- java.lang.Object
- 
- java.io.InputStream
- 
- javax.sound.sampled.AudioInputStream
 
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 
 public class AudioInputStream extends InputStream An audio input stream is an input stream with a specified audio format and length. The length is expressed in sample frames, not bytes. Several methods are provided for reading a certain number of bytes from the stream, or an unspecified number of bytes. The audio input stream keeps track of the last byte that was read. You can skip over an arbitrary number of bytes to get to a later position for reading. An audio input stream may support marks. When you set a mark, the current position is remembered so that you can return to it later.The AudioSystemclass includes many methods that manipulateAudioInputStreamobjects. For example, the methods let you:- obtain an audio input stream from an external audio file, stream, or
   URL
- write an external file from an audio input stream
- convert an audio input stream to a different audio format
 - Since:
- 1.3
- See Also:
- AudioSystem,- Clip.open(AudioInputStream)
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected AudioFormatformatThe format of the audio data contained in the stream.protected longframeLengthThis stream's length, in sample frames.protected longframePosThe current position in this stream, in sample frames (zero-based).protected intframeSizeThe size of each frame, in bytes.
 - 
Constructor SummaryConstructors Constructor Description AudioInputStream(InputStream stream, AudioFormat format, long length)Constructs an audio input stream that has the requested format and length in sample frames, using audio data from the specified input stream.AudioInputStream(TargetDataLine line)Constructs an audio input stream that reads its data from the target data line indicated.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the maximum number of bytes that can be read (or skipped over) from this audio input stream without blocking.voidclose()Closes this audio input stream and releases any system resources associated with the stream.AudioFormatgetFormat()Obtains the audio format of the sound data in this audio input stream.longgetFrameLength()Obtains the length of the stream, expressed in sample frames rather than bytes.voidmark(int readlimit)Marks the current position in this audio input stream.booleanmarkSupported()Tests whether this audio input stream supports themarkandresetmethods.intread()Reads the next byte of data from the audio input stream.intread(byte[] b)Reads some number of bytes from the audio input stream and stores them into the buffer arrayb.intread(byte[] b, int off, int len)Reads up to a specified maximum number of bytes of data from the audio stream, putting them into the given byte array.voidreset()Repositions this audio input stream to the position it had at the time itsmarkmethod was last invoked.longskip(long n)Skips over and discards a specified number of bytes from this audio input stream.- 
Methods declared in class java.io.InputStreamnullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
 
- 
 
- 
- 
- 
Field Detail- 
formatprotected AudioFormat format The format of the audio data contained in the stream.
 - 
frameLengthprotected long frameLength This stream's length, in sample frames.
 - 
frameSizeprotected int frameSize The size of each frame, in bytes.
 - 
framePosprotected long framePos The current position in this stream, in sample frames (zero-based).
 
- 
 - 
Constructor Detail- 
AudioInputStreampublic AudioInputStream(InputStream stream, AudioFormat format, long length) Constructs an audio input stream that has the requested format and length in sample frames, using audio data from the specified input stream.- Parameters:
- stream- the stream on which this- AudioInputStreamobject is based
- format- the format of this stream's audio data
- length- the length in sample frames of the data in this stream
 
 - 
AudioInputStreampublic AudioInputStream(TargetDataLine line) Constructs an audio input stream that reads its data from the target data line indicated. The format of the stream is the same as that of the target data line, and the length isAudioSystem#NOT_SPECIFIED.- Parameters:
- line- the target data line from which this stream obtains its data
- See Also:
- AudioSystem.NOT_SPECIFIED
 
 
- 
 - 
Method Detail- 
getFormatpublic AudioFormat getFormat() Obtains the audio format of the sound data in this audio input stream.- Returns:
- an audio format object describing this stream's format
 
 - 
getFrameLengthpublic long getFrameLength() Obtains the length of the stream, expressed in sample frames rather than bytes.- Returns:
- the length in sample frames
 
 - 
readpublic int read() throws IOExceptionReads the next byte of data from the audio input stream. The audio input stream's frame size must be one byte, or anIOExceptionwill be thrown.- Specified by:
- readin class- InputStream
- Returns:
- the next byte of data, or -1 if the end of the stream is reached
- Throws:
- IOException- if an input or output error occurs
- See Also:
- read(byte[], int, int),- read(byte[]),- available()
 
 - 
readpublic int read(byte[] b) throws IOExceptionReads some number of bytes from the audio input stream and stores them into the buffer arrayb. The number of bytes actually read is returned as an integer. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.This method will always read an integral number of frames. If the length of the array is not an integral number of frames, a maximum of b.length - (b.length % frameSize)bytes will be read.- Overrides:
- readin class- InputStream
- Parameters:
- b- the buffer into which the data is read
- Returns:
- the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached
- Throws:
- IOException- if an input or output error occurs
- See Also:
- read(byte[], int, int),- read(),- available()
 
 - 
readpublic int read(byte[] b, int off, int len) throws IOExceptionReads up to a specified maximum number of bytes of data from the audio stream, putting them into the given byte array.This method will always read an integral number of frames. If lendoes not specify an integral number of frames, a maximum oflen - (len % frameSize)bytes will be read.- Overrides:
- readin class- InputStream
- Parameters:
- b- the buffer into which the data is read
- off- the offset, from the beginning of array- b, at which the data will be written
- len- the maximum number of bytes to read
- Returns:
- the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached
- Throws:
- IOException- if an input or output error occurs
- See Also:
- read(byte[]),- read(),- skip(long),- available()
 
 - 
skippublic long skip(long n) throws IOExceptionSkips over and discards a specified number of bytes from this audio input stream.This method will always skip an integral number of frames. If ndoes not specify an integral number of frames, a maximum ofn - (n % frameSize)bytes will be skipped.- Overrides:
- skipin class- InputStream
- Parameters:
- n- the requested number of bytes to be skipped
- Returns:
- the actual number of bytes skipped
- Throws:
- IOException- if an input or output error occurs
- See Also:
- read(),- available()
 
 - 
availablepublic int available() throws IOExceptionReturns the maximum number of bytes that can be read (or skipped over) from this audio input stream without blocking. This limit applies only to the next invocation of areadorskipmethod for this audio input stream; the limit can vary each time these methods are invoked. Depending on the underlying stream, anIOExceptionmay be thrown if this stream is closed.- Overrides:
- availablein class- InputStream
- Returns:
- the number of bytes that can be read from this audio input stream without blocking
- Throws:
- IOException- if an input or output error occurs
- See Also:
- read(byte[], int, int),- read(byte[]),- read(),- skip(long)
 
 - 
closepublic void close() throws IOExceptionCloses this audio input stream and releases any system resources associated with the stream.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- InputStream
- Throws:
- IOException- if an input or output error occurs
 
 - 
markpublic void mark(int readlimit) Marks the current position in this audio input stream.- Overrides:
- markin class- InputStream
- Parameters:
- readlimit- the maximum number of bytes that can be read before the mark position becomes invalid
- See Also:
- reset(),- markSupported()
 
 - 
resetpublic void reset() throws IOExceptionRepositions this audio input stream to the position it had at the time itsmarkmethod was last invoked.- Overrides:
- resetin class- InputStream
- Throws:
- IOException- if an input or output error occurs
- See Also:
- mark(int),- markSupported()
 
 - 
markSupportedpublic boolean markSupported() Tests whether this audio input stream supports themarkandresetmethods.- Overrides:
- markSupportedin class- InputStream
- Returns:
- trueif this stream supports the- markand- resetmethods;- falseotherwise
- See Also:
- mark(int),- reset()
 
 
- 
 
-