Closeable
, AutoCloseable
public class AudioInputStream extends InputStream
The AudioSystem
class includes many methods that manipulate AudioInputStream
objects. For example, the methods let you:
URL
Modifier and Type | Field | Description |
---|---|---|
protected AudioFormat |
format |
The format of the audio data contained in the stream. |
protected long |
frameLength |
This stream's length, in sample frames. |
protected long |
framePos |
The current position in this stream, in sample frames (zero-based). |
protected int |
frameSize |
The size of each frame, in bytes. |
Constructor | Description |
---|---|
AudioInputStream |
Constructs an audio input stream that has the requested format and length in sample frames, using audio data from the specified input stream. |
AudioInputStream |
Constructs an audio input stream that reads its data from the target data line indicated. |
Modifier and Type | Method | Description |
---|---|---|
int |
available() |
Returns the maximum number of bytes that can be read (or skipped over) from this audio input stream without blocking. |
void |
close() |
Closes this audio input stream and releases any system resources associated with the stream. |
AudioFormat |
getFormat() |
Obtains the audio format of the sound data in this audio input stream. |
long |
getFrameLength() |
Obtains the length of the stream, expressed in sample frames rather than bytes. |
void |
mark |
Marks the current position in this audio input stream. |
boolean |
markSupported() |
Tests whether this audio input stream supports the mark and reset methods. |
int |
read() |
Reads the next byte of data from the audio input stream. |
int |
read |
Reads some number of bytes from the audio input stream and stores them into the buffer array b . |
int |
read |
Reads up to a specified maximum number of bytes of data from the audio stream, putting them into the given byte array. |
void |
reset() |
Repositions this audio input stream to the position it had at the time its mark method was last invoked. |
long |
skip |
Skips over and discards a specified number of bytes from this audio input stream. |
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
protected AudioFormat format
protected long frameLength
protected int frameSize
protected long framePos
public AudioInputStream(InputStream stream, AudioFormat format, long length)
stream
- the stream on which this AudioInputStream
object is basedformat
- the format of this stream's audio datalength
- the length in sample frames of the data in this streampublic AudioInputStream(TargetDataLine line)
AudioSystem#NOT_SPECIFIED
.line
- the target data line from which this stream obtains its datapublic AudioFormat getFormat()
public long getFrameLength()
public int read() throws IOException
IOException
will be thrown.read
in class InputStream
-1
if the end of the stream is reached.IOException
- if an input or output error occurspublic int read(byte[] b) throws IOException
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.
read
in class InputStream
b
- the buffer into which the data is read.-1
if there is no more data because the end of the stream has been reached.IOException
- if an input or output error occurspublic int read(byte[] b, int off, int len) throws IOException
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.
read
in class InputStream
b
- the buffer into which the data is read.off
- the start offset in array b
at which the data is written.len
- the maximum number of bytes to read.-1
if there is no more data because the end of the stream has been reached.IOException
- if an input or output error occurspublic long skip(long n) throws IOException
This method will always skip an integral number of frames. If n
does not specify an integral number of frames, a maximum of n - (n % frameSize)
bytes will be skipped.
skip
in class InputStream
n
- the requested number of bytes to be skippedIOException
- if an input or output error occurspublic int available() throws IOException
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.available
in class InputStream
IOException
- if an input or output error occurspublic void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
close
in class InputStream
IOException
- if an input or output error occurspublic void mark(int readlimit)
mark
in class InputStream
readlimit
- the maximum number of bytes that can be read before the mark position becomes invalidpublic void reset() throws IOException
mark
method was last invoked.reset
in class InputStream
IOException
- if an input or output error occurspublic boolean markSupported()
mark
and reset
methods.markSupported
in class InputStream
true
if this stream supports the mark
and reset
methods; false
otherwise
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/javax/sound/sampled/AudioInputStream.html