• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

AudioInputStream IOException Mark/Reset Not Supported

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that uses 'javax.sound.sampled.AudioSystem'. My code works fine on a PC but when I move the jar file to a Debian based Linux (Rasbian specifically) I get the attached IOException No console available thus the image. What does this mean and how do I fix it?

FWIW, here is the specific code:


Capture.PNG
IOException
IOException
 
Sam Ritter
Ranch Hand
Posts: 205
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After much research I found an obscure article that suggested a subtle change that fixed it. In case someone else runs into this problem the solution is to use a URL and not an input stream. I don't understand why one works over the other but I won't argue with success. It said audio files don't support mark/reset but why it works with a URL rather than an input stream was not explained. Also why the exception did not occur on Windows and did on Linux was also not explained.

 
Saloon Keeper
Posts: 1609
52
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Interesting and subtle...I hadn't worked with AudioInputStream yet.

I know you aren't ever supposed to be calling mark()/reset() unless markSupported() returns true:
https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/io/InputStream.html#reset()

Better tutorials point that out with some emphasis.

The docs warn that a call to reset() on a stream that returns false for markSupported() may throw an IOException.

For general IOStream reference, it is my feeling that anything Buffered will support mark()/reset(), anything NOT buffered won't, tho I am not sure that is an actual rule:
jshell> import java.io.FileInputStream;
jshell> import java.io.BufferedInputStream;

jshell> var fis = new FileInputStream("F:/java/default.txt")
fis ==> java.io.FileInputStream@6d21714c

jshell> fis.markSupported()
$19 ==> false

jshell> var bis = new BufferedInputStream(fis)
bis ==> java.io.BufferedInputStream@4bf558aa

jshell> bis.markSupported()
$22 ==> true

None of your code explicitly calls mark() or reset(), but it looks like some of Sun's audio code doesn't follow their own rules!

When you use a URL instead of a file, either:
  • It calls some helper constructor that wraps something that DOES return true for markSupported(), perhaps just because there is a BufferedInputStream in the mix, and a reset works just fine,


  • Or different code in the stack is smart enough to call markSupported() and then know it had better not call mark() or reset() when it sees false,


  • Or there is code that is even more different than for the file case that doesn't feel the need to call reset() in the first place.


  • Whichever the answer is, there is no code on the Windows side that blindly calls reset() without checking that it will work first, for one of the same set of reasons (I don't know which one).

    I was mildly curious what it would look like if you ignored the warnings and called mark()/reset() anyway when markSupported() returned false.
    Now I know, thanks!
     
    Jesse Silverman
    Saloon Keeper
    Posts: 1609
    52
    Eclipse IDE Postgres Database C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    One more possibility, a call to reset() on a Stream that returns false for markSupported() doesn't HAVE to return IOException, but what happens in that case seems so dicey I think I'd prefer the exception:

    If the method markSupported returns false, then:
    The call to reset may throw an IOException.
    If an IOException is not thrown, then the stream is reset to a fixed state that depends on the particular type of the input stream and how it was created. The bytes that will be supplied to subsequent callers of the read method depend on the particular type of the input stream.
    The method reset for class InputStream does nothing except throw an IOException.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    reply
      Bookmark Topic Watch Topic
    • New Topic