Method from javax.sound.sampled.AudioInputStream Detail: |
public int available() throws IOException {
int temp = stream.available();
// don't return greater than our set length in frames
if( (frameLength != AudioSystem.NOT_SPECIFIED) && ( (temp/frameSize) > (frameLength-framePos)) ) {
return (int) (frameLength-framePos) * frameSize;
} else {
return temp;
}
}
Returns 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
a read or skip method for this audio input stream; the limit
can vary each time these methods are invoked.
Depending on the underlying stream,an IOException may be thrown if this
stream is closed. |
public void close() throws IOException {
stream.close();
}
Closes this audio input stream and releases any system resources associated
with the stream. |
public AudioFormat getFormat() {
return format;
}
Obtains the audio format of the sound data in this audio input stream. |
public long getFrameLength() {
return frameLength;
}
Obtains the length of the stream, expressed in sample frames rather than bytes. |
public void mark(int readlimit) {
stream.mark(readlimit);
if (markSupported()) {
markpos = framePos;
// remember the pushback buffer
markPushBackLen = pushBackLen;
if (markPushBackLen > 0) {
if (markPushBackBuffer == null) {
markPushBackBuffer = new byte[frameSize];
}
System.arraycopy(pushBackBuffer, 0, markPushBackBuffer, 0, markPushBackLen);
}
}
}
Marks the current position in this audio input stream. |
public boolean markSupported() {
return stream.markSupported();
}
Tests whether this audio input stream supports the mark and
reset methods. |
public int read() throws IOException {
if( frameSize != 1 ) {
throw new IOException("cannot read a single byte if frame size > 1");
}
byte[] data = new byte[1];
int temp = read(data);
if (temp < = 0) {
// we have a weird situation if read(byte[]) returns 0!
return -1;
}
return data[0] & 0xFF;
}
Reads the next byte of data from the audio input stream. The audio input
stream's frame size must be one byte, or an IOException
will be thrown. |
public int read(byte[] b) throws IOException {
return read(b,0,b.length);
}
Reads some number of bytes from the audio input stream and stores them into
the buffer array b . 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. |
public int read(byte[] b,
int off,
int len) throws IOException {
// make sure we don't read fractions of a frame.
if( (len%frameSize) != 0 ) {
len -= (len%frameSize);
if (len == 0) {
return 0;
}
}
if( frameLength != AudioSystem.NOT_SPECIFIED ) {
if( framePos >= frameLength ) {
return -1;
} else {
// don't try to read beyond our own set length in frames
if( (len/frameSize) > (frameLength-framePos) ) {
len = (int) (frameLength-framePos) * frameSize;
}
}
}
int bytesRead = 0;
int thisOff = off;
// if we've bytes left from last call to read(),
// use them first
if (pushBackLen > 0 && len >= pushBackLen) {
System.arraycopy(pushBackBuffer, 0,
b, off, pushBackLen);
thisOff += pushBackLen;
len -= pushBackLen;
bytesRead += pushBackLen;
pushBackLen = 0;
}
int thisBytesRead = stream.read(b, thisOff, len);
if (thisBytesRead == -1) {
return -1;
}
if (thisBytesRead > 0) {
bytesRead += thisBytesRead;
}
if (bytesRead > 0) {
pushBackLen = bytesRead % frameSize;
if (pushBackLen > 0) {
// copy everything we got from the beginning of the frame
// to our pushback buffer
if (pushBackBuffer == null) {
pushBackBuffer = new byte[frameSize];
}
System.arraycopy(b, off + bytesRead - pushBackLen,
pushBackBuffer, 0, pushBackLen);
bytesRead -= pushBackLen;
}
// make sure to update our framePos
framePos += bytesRead/frameSize;
}
return bytesRead;
}
Reads 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 len does not specify an integral number
of frames, a maximum of len - (len % frameSize)
bytes will be read. |
public void reset() throws IOException {
stream.reset();
framePos = markpos;
// re-create the pushback buffer
pushBackLen = markPushBackLen;
if (pushBackLen > 0) {
if (pushBackBuffer == null) {
pushBackBuffer = new byte[frameSize - 1];
}
System.arraycopy(markPushBackBuffer, 0, pushBackBuffer, 0, pushBackLen);
}
}
Repositions this audio input stream to the position it had at the time its
mark method was last invoked. |
public long skip(long n) throws IOException {
// make sure not to skip fractional frames
if( (n%frameSize) != 0 ) {
n -= (n%frameSize);
}
if( frameLength != AudioSystem.NOT_SPECIFIED ) {
// don't skip more than our set length in frames.
if( (n/frameSize) > (frameLength-framePos) ) {
n = (frameLength-framePos) * frameSize;
}
}
long temp = stream.skip(n);
// if no error, update our position.
if( temp%frameSize != 0 ) {
// Throw an IOException if we've skipped a fractional number of frames
throw new IOException("Could not skip an integer number of frames.");
}
if( temp >= 0 ) {
framePos += temp/frameSize;
}
return temp;
}
Skips over and discards a specified number of bytes from this
audio input stream. |