Discussions
Categories
- 196.8K All Categories
- 2.2K Data
- 238 Big Data Appliance
- 1.9K Data Science
- 450.2K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 544 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.8K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.5K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 154 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 437 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
IOException reading WAV from client via applet

Phil Freihofner
Member Posts: 28
I just managed to enable an Applet to allow reading of files from a client computer, using the JNLP API. The following code returned a diagnostic that indicates the file selected is readable.
Any thoughts on what I might be overlooking? I'm so new to JNLP that I don't know if there is some aspect of the Applet context that is causing a problem. Should I post this question in the JNLP & WebStart forum?
I am posting the Applet at a remote site via FTP, going to the site with a Mozilla Firefox browser, and trying to read a file from my computer's "My Documents" area.
Thank you for your time and help!
Edited by: 807197 on Jun 30, 2011 12:18 AM
InputStream in = null; ... vsg.updateDiagnostic("about to try fos instantiation"); FileOpenService fos = (FileOpenService) ServiceManager.lookup("javax.jnlp.FileOpenService"); FileContents contents = fos.openFileDialog(".", new String[] {"wav"}); if (contents != null) { in = contents.getInputStream(); if (contents.canRead()) { vsg.updateDiagnostic("can read"); } }However, I am throwing an IOException when I try to instantiate an AudioFileFormat object from this InputStream as follows:
AudioFileFormat aff = AudioSystem.getAudioFileFormat(in);The very same WAV file loads fine when I run this program with the following code in an "application" context, where fs is a JFileChooser.
File soundFile = fs.getSelectedFile().getAbsoluteFile(); AudioiFileFormat aff = AudioSystem.getAudioFileFormat(soundFile);An InputStream is considered a valid argument for the getAudioFileFormat() method, yes? And I verified that the newly created InputStream was readable.
Any thoughts on what I might be overlooking? I'm so new to JNLP that I don't know if there is some aspect of the Applet context that is causing a problem. Should I post this question in the JNLP & WebStart forum?
I am posting the Applet at a remote site via FTP, going to the site with a Mozilla Firefox browser, and trying to read a file from my computer's "My Documents" area.
Thank you for your time and help!
Edited by: 807197 on Jun 30, 2011 12:18 AM
Tagged:
Best Answer
-
You might try loading the entire input stream provided by the <tt>FileContents</tt> into a <tt>ByteArrayOutputStream</tt>. Provide the <tt>byte[]</tt> from that to the constructor of a <tt>ByteArrayInputStream</tt> & use the BAIS for further operations.
Answers
-
-
"IOException: mark/reset not supported"
Sorry for not including this initially. I don't know how to retrieve error messages from Applets, and had to build a text field on the GUI itself to intercept the full message.
I recall running into this situation before, but not a solution. Is there a way to wrap the stream in something that CAN do a mark & reset? I will try this while awaiting further replies.
Thanks! -
I just tried wrapping the InputStream from the FileOpenService in a BufferedInputStream and wrapping that in a PushbackInputStream. But I get a .markSupported() = false on the BushbackInputStream, so trying to get an AudioFileFormat still does not work.
I kind of need the AudioFileFormat in order to get the frame length of the audio file (used to build an internal array), as well as use it for prescreening supported audio file formats.
Is there be a way to make this file "markable"? Or should one take another approach?
Thanks again! -
You might try loading the entire input stream provided by the <tt>FileContents</tt> into a <tt>ByteArrayOutputStream</tt>. Provide the <tt>byte[]</tt> from that to the constructor of a <tt>ByteArrayInputStream</tt> & use the BAIS for further operations.
-
Beautiful!
That was exactly what I was trying just now, and it worked. Since you already described the answer, I don't have to.
Many, many thanks!
This discussion has been closed.