javax.sound.sampled

Class AudioInputStream

public class AudioInputStream extends InputStream

This is an InputStream which is specialized for reading audio files. In particular it only allows operations to act on a multiple of the audio stream's frame size.

Since: 1.3

Field Summary
protected AudioFormatformat
The format of the audio stream.
protected longframeLength
The length of the audio stream in frames.
protected longframePos
The current frame position, starting from frame zero.
protected intframeSize
The size of a frame in bytes.
Constructor Summary
AudioInputStream(InputStream is, AudioFormat fmt, long length)
Create a new AudioInputStream given an underlying InputStream, the audio format, and the length of the data in frames.
AudioInputStream(TargetDataLine line)
Create a new AudioInputStream given a TargetDataLine.
Method Summary
intavailable()
Return the number of bytes available to be read from the underlying stream.
voidclose()
Close the stream.
AudioFormatgetFormat()
Get the format associated with this stream.
longgetFrameLength()
Get the length of this stream in frames.
voidmark(int limit)
booleanmarkSupported()
Return true if the underlying stream supports mark and reset, false otherwise.
intread()
Read a single byte from the underlying stream.
intread(byte[] buf)
intread(byte[] buf, int offset, int length)
voidreset()
longskip(long n)

Field Detail

format

protected AudioFormat format
The format of the audio stream.

frameLength

protected long frameLength
The length of the audio stream in frames.

framePos

protected long framePos
The current frame position, starting from frame zero.

frameSize

protected int frameSize
The size of a frame in bytes.

Constructor Detail

AudioInputStream

public AudioInputStream(InputStream is, AudioFormat fmt, long length)
Create a new AudioInputStream given an underlying InputStream, the audio format, and the length of the data in frames. The frame size is taken from the format.

Parameters: is the underlying input stream fmt the format of the data length the length of the data in frames

AudioInputStream

public AudioInputStream(TargetDataLine line)
Create a new AudioInputStream given a TargetDataLine. The audio format and the frame size are taken from the line.

Parameters: line the TargetDataLine

Method Detail

available

public int available()
Return the number of bytes available to be read from the underlying stream. This wrapper method ensures that the result is always a multiple of the frame size.

close

public void close()
Close the stream.

getFormat

public AudioFormat getFormat()
Get the format associated with this stream.

Returns: the AudioFormat

getFrameLength

public long getFrameLength()
Get the length of this stream in frames. Note that this may be AudioSystem#NOT_SPECIFIED.

Returns: the length of the stream in frames

mark

public void mark(int limit)

markSupported

public boolean markSupported()
Return true if the underlying stream supports mark and reset, false otherwise.

read

public int read()
Read a single byte from the underlying stream. If the frame size is set, and is not one byte, an IOException will be thrown.

read

public int read(byte[] buf)

read

public int read(byte[] buf, int offset, int length)

reset

public void reset()

skip

public long skip(long n)