This discussion is archived
10 Replies Latest reply: Jan 17, 2012 3:15 AM by ptoye RSS

Problem with getAudioInputStream in Java 7

ptoye Newbie
Currently Being Moderated
I have a program which works fine under Java 6. But under Java 7 it fails when calling getAudioInputStream. The failure is an I/O exception saying that Mark/Reset is not available for the stream (which is true under both Javas 6 & 7).

Has getAudioInputStream changed between Java versions?

And how to mend the program? I can post snippets if it helps.
  • 1. Re: Problem with getAudioInputStream in Java 7
    793415 Pro
    Currently Being Moderated
    ptoye wrote:
    I have a program which works fine under Java 6. But under Java 7 it fails when calling getAudioInputStream. The failure is an I/O exception saying that Mark/Reset is not available for the stream (which is true under both Javas 6 & 7).

    Has getAudioInputStream changed between Java versions?
    I expect the problem is the Java 7 JRE. Why not raise a bug report and see what Oracle has to say on the matter?
    And how to mend the program? ..
    One potential fix is to read the input stream and write the bytes into a <tt>ByteArrayOutputStream</tt>, when they are loaded, call <tt>getBytes()</tt> and use that to construct a <tt>ByteArrayInputStream</tt>. Use the BAIS for <tt>getAudioInputStream(InputStream)</tt>. The BAIS is definitely positionable.
  • 2. Re: Problem with getAudioInputStream in Java 7
    ptoye Newbie
    Currently Being Moderated
    Thanks Andrew. This isn't the first problem I've had with Java 7 being incompatible with 6.

    I don't actually need to rewind the stream (it wouldn't have worked under 6 if I did). At the moment I think I'll stick with 6.

    One further question - how does one actually submit a bug report to Oracle? I can't see anything on the Oracle.com web site which even hints that such a thing might be possible.

    Edited by: ptoye on 25-Sep-2011 11:15
  • 3. Re: Problem with getAudioInputStream in Java 7
    ptoye Newbie
    Currently Being Moderated
    I created a bug report and they've agreed that it's a bug. But haven't said when/if it'll get fixed.
  • 4. Re: Problem with getAudioInputStream in Java 7
    793415 Pro
    Currently Being Moderated
    ptoye wrote:
    I created a bug report and they've agreed that it's a bug.
    Good work. Please let us know when it becomes visible, and I'll give it a vote.
  • 5. Re: Problem with getAudioInputStream in Java 7
    ptoye Newbie
    Currently Being Moderated
    It's in the database as number 7095006. The login's so slow that I can't vote for it myself!
  • 6. Re: Problem with getAudioInputStream in Java 7
    793415 Pro
    Currently Being Moderated
    ptoye wrote:
    It's in the database as number 7095006. ..
    Thanks.
    ..The login's so slow that I can't vote for it myself!
    I'm right there with you. :(
  • 7. Re: Problem with getAudioInputStream in Java 7
    ptoye Newbie
    Currently Being Moderated
    Well, it took about 30 minutes, but I managed it!
  • 8. Re: Problem with getAudioInputStream in Java 7
    810200 Newbie
    Currently Being Moderated
    I just got the same error. Unfortunately I don't have Java 7 and can't test if the following fix works!

    I was using this form to get a new AudioInputStream:
        AudioInputStream ais = AudioSystem.getAudioInputStream(AudioMixer.class.getResourceAsStream(fileName));
    This syntax uses InputStream as an argument, and InputStream requires that a stream be "markable". Maybe this was a "grey area" and previously worked but with Java 7 is now more rigorously enforced?

    So, I am trying this form, which doesn't mention checking for "mark/reset" in the api.
    [http://download.oracle.com/javase/7/docs/api/javax/sound/sampled/AudioSystem.html#getAudioInputStream(java.net.URL)]
        URL url = AudioMixer.class.getResource(fileName);
        AudioInputStream ais = AudioSystem.getAudioInputStream(url);
    I haven't been able to verify if this works yet!

    It would be great to have someone who runs Java 7 give my Applet a try. It is a demo of an audio mixing program in development, to funnel all audio into a single SourceDataLine.
    [http://www.hexara.com/VSL/AudioMixerDemoWarOfWorlds.htm]

    I'd appreciate a note if the top row buttons are working or not. They rely upon the one-time loading of an AudioInputStream.

    Edited by: 807197 on Nov 10, 2011 2:38 PM
  • 9. Re: Problem with getAudioInputStream in Java 7
    810200 Newbie
    Currently Being Moderated
    The Java 7 user who reported this problem to me just let me know that the above solution works.

    I would like to suggest the previous post as a possible "work around" for those of you who are involved in the bug report. I'll try to make a note on the bug report itself, if there is a place for comments, but it is rather difficult to navigate in that area.

    It seems to me, in fact, that it might be more correct to use a parameter other than InputStream, given that InputStream's specification indicates it checks for markability. Unfortunately, due to this being a "gray area" and working in the past (see explanation in the Bug Report response!), backwards compatibility issues do arise. Fortunately, the required recoding is straightforward.
  • 10. Re: Problem with getAudioInputStream in Java 7
    ptoye Newbie
    Currently Being Moderated
    Thanks Phil. That's really helped. Sorry about the delay - been working on other things.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points