It works with a File
object being passed to AudioSystem#getAudioFileFormat
, but why does it fail with an InputStream
object below? Any suggestion?
import java.io.*;
import javax.sound.sampled.*;
public class Test {
public static void main(String[] args) throws Exception {
AudioSystem.getAudioFileFormat(new File(
"myaudio.wav"));
AudioSystem.getAudioFileFormat(new FileInputStream(
"myaudio.wav"));
}
}
Output:
Exception in thread "main" java.io.IOException: mark/reset not supported
at java.io.InputStream.reset(InputStream.java:330)
at com.sun.media.sound.WaveFileReader.getAudioFileFormat(WaveFileReader.java:88)
at javax.sound.sampled.AudioSystem.getAudioFileFormat(AudioSystem.java:985)
at Test.main(Test.java:10)
@EDIT
According to the answers from @René Jeschke
, @Phil Freihofner
and @Andrew Thompson
, wherever mark/reset
is required as the mandatory protocal for Java Sound API
to interact with the IO stream
, IMHO, the type of buffered
stream instead of the raw
one should have been specially defined as the signature of the parameter to be passed. Doing so would narrow to the more desirable result than arbitrarily accepting an IO stream
then resorting to IOException
as the adverse indicator.