home *** CD-ROM | disk | FTP | other *** search
- package javax.sound.sampled;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.PushbackInputStream;
-
- public class AudioInputStream extends InputStream {
- private PushbackInputStream stream;
- private boolean markSupported;
- protected AudioFormat format;
- protected long frameLength;
- protected int frameSize;
- protected long framePos;
- private long markpos;
-
- public AudioInputStream(InputStream var1, AudioFormat var2, long var3) {
- this.format = var2;
- this.frameLength = var3;
- this.frameSize = var2.getFrameSize();
- if (this.frameSize == -1) {
- this.frameSize = 1;
- }
-
- if (this.frameSize > 1) {
- this.stream = new PushbackInputStream(var1, this.frameSize - 1);
- } else {
- this.stream = new PushbackInputStream(var1, 1);
- }
-
- this.framePos = 0L;
- this.markpos = 0L;
- this.markSupported = var1.markSupported();
- }
-
- public AudioInputStream(TargetDataLine var1) {
- TargetDataLineInputStream var2 = new TargetDataLineInputStream(this, var1);
- this.format = var1.getFormat();
- this.frameLength = -1L;
- this.frameSize = this.format.getFrameSize();
- if (this.frameSize == -1) {
- this.frameSize = 1;
- }
-
- if (this.frameSize > 1) {
- this.stream = new PushbackInputStream(var2, this.frameSize - 1);
- } else {
- this.stream = new PushbackInputStream(var2, 1);
- }
-
- this.framePos = 0L;
- this.markpos = 0L;
- this.markSupported = this.stream.markSupported();
- }
-
- public AudioFormat getFormat() {
- return this.format;
- }
-
- public long getFrameLength() {
- return this.frameLength;
- }
-
- public int read() throws IOException {
- if (this.frameSize != 1) {
- throw new IOException("cannot read a single byte if frame size != 1");
- } else if (this.frameLength != -1L && this.framePos >= this.frameLength) {
- return -1;
- } else {
- int var1 = this.stream.read();
- if (var1 >= 0) {
- ++this.framePos;
- }
-
- return var1;
- }
- }
-
- public int read(byte[] var1) throws IOException {
- return this.read(var1, 0, var1.length);
- }
-
- public int read(byte[] var1, int var2, int var3) throws IOException {
- if (var3 % this.frameSize != 0) {
- var3 -= var3 % this.frameSize;
- }
-
- if (this.frameLength != -1L) {
- if (this.framePos >= this.frameLength) {
- return -1;
- }
-
- if ((long)(var3 / this.frameSize) > this.frameLength - this.framePos) {
- var3 = (int)(this.frameLength - this.framePos) * this.frameSize;
- }
- }
-
- int var4 = this.stream.read(var1, var2, var3);
- if (var4 > 0) {
- int var5 = var4 % this.frameSize;
- if (var5 > 0) {
- this.stream.unread(var1, var2 + var4 - var5, var5);
- var4 -= var5;
- }
- }
-
- this.framePos += (long)(var4 / this.frameSize);
- return var4;
- }
-
- public long skip(long var1) throws IOException {
- if (var1 % (long)this.frameSize != 0L) {
- var1 -= var1 % (long)this.frameSize;
- }
-
- if (this.frameLength != -1L && var1 / (long)this.frameSize > this.frameLength - this.framePos) {
- var1 = (this.frameLength - this.framePos) * (long)this.frameSize;
- }
-
- long var3 = this.stream.skip(var1);
- if (var3 % (long)this.frameSize != 0L) {
- throw new IOException("Could not skip an integer number of frames.");
- } else {
- if (var3 >= 0L) {
- this.framePos += var3 / (long)this.frameSize;
- }
-
- return var3;
- }
- }
-
- public int available() throws IOException {
- int var1 = this.stream.available();
- return this.frameLength != -1L && (long)(var1 / this.frameSize) > this.frameLength - this.framePos ? (int)(this.frameLength - this.framePos) * this.frameSize : var1;
- }
-
- public void close() throws IOException {
- this.stream.close();
- }
-
- public void mark(int var1) {
- this.stream.mark(var1);
- if (this.markSupported()) {
- this.markpos = this.framePos;
- }
-
- }
-
- public void reset() throws IOException {
- this.stream.reset();
- this.framePos = this.markpos;
- }
-
- public boolean markSupported() {
- return this.markSupported;
- }
- }
-