home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / sound / sampled / AudioInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.5 KB  |  157 lines

  1. package javax.sound.sampled;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.PushbackInputStream;
  6.  
  7. public class AudioInputStream extends InputStream {
  8.    private PushbackInputStream stream;
  9.    private boolean markSupported;
  10.    protected AudioFormat format;
  11.    protected long frameLength;
  12.    protected int frameSize;
  13.    protected long framePos;
  14.    private long markpos;
  15.  
  16.    public AudioInputStream(InputStream var1, AudioFormat var2, long var3) {
  17.       this.format = var2;
  18.       this.frameLength = var3;
  19.       this.frameSize = var2.getFrameSize();
  20.       if (this.frameSize == -1) {
  21.          this.frameSize = 1;
  22.       }
  23.  
  24.       if (this.frameSize > 1) {
  25.          this.stream = new PushbackInputStream(var1, this.frameSize - 1);
  26.       } else {
  27.          this.stream = new PushbackInputStream(var1, 1);
  28.       }
  29.  
  30.       this.framePos = 0L;
  31.       this.markpos = 0L;
  32.       this.markSupported = var1.markSupported();
  33.    }
  34.  
  35.    public AudioInputStream(TargetDataLine var1) {
  36.       TargetDataLineInputStream var2 = new TargetDataLineInputStream(this, var1);
  37.       this.format = var1.getFormat();
  38.       this.frameLength = -1L;
  39.       this.frameSize = this.format.getFrameSize();
  40.       if (this.frameSize == -1) {
  41.          this.frameSize = 1;
  42.       }
  43.  
  44.       if (this.frameSize > 1) {
  45.          this.stream = new PushbackInputStream(var2, this.frameSize - 1);
  46.       } else {
  47.          this.stream = new PushbackInputStream(var2, 1);
  48.       }
  49.  
  50.       this.framePos = 0L;
  51.       this.markpos = 0L;
  52.       this.markSupported = this.stream.markSupported();
  53.    }
  54.  
  55.    public AudioFormat getFormat() {
  56.       return this.format;
  57.    }
  58.  
  59.    public long getFrameLength() {
  60.       return this.frameLength;
  61.    }
  62.  
  63.    public int read() throws IOException {
  64.       if (this.frameSize != 1) {
  65.          throw new IOException("cannot read a single byte if frame size != 1");
  66.       } else if (this.frameLength != -1L && this.framePos >= this.frameLength) {
  67.          return -1;
  68.       } else {
  69.          int var1 = this.stream.read();
  70.          if (var1 >= 0) {
  71.             ++this.framePos;
  72.          }
  73.  
  74.          return var1;
  75.       }
  76.    }
  77.  
  78.    public int read(byte[] var1) throws IOException {
  79.       return this.read(var1, 0, var1.length);
  80.    }
  81.  
  82.    public int read(byte[] var1, int var2, int var3) throws IOException {
  83.       if (var3 % this.frameSize != 0) {
  84.          var3 -= var3 % this.frameSize;
  85.       }
  86.  
  87.       if (this.frameLength != -1L) {
  88.          if (this.framePos >= this.frameLength) {
  89.             return -1;
  90.          }
  91.  
  92.          if ((long)(var3 / this.frameSize) > this.frameLength - this.framePos) {
  93.             var3 = (int)(this.frameLength - this.framePos) * this.frameSize;
  94.          }
  95.       }
  96.  
  97.       int var4 = this.stream.read(var1, var2, var3);
  98.       if (var4 > 0) {
  99.          int var5 = var4 % this.frameSize;
  100.          if (var5 > 0) {
  101.             this.stream.unread(var1, var2 + var4 - var5, var5);
  102.             var4 -= var5;
  103.          }
  104.       }
  105.  
  106.       this.framePos += (long)(var4 / this.frameSize);
  107.       return var4;
  108.    }
  109.  
  110.    public long skip(long var1) throws IOException {
  111.       if (var1 % (long)this.frameSize != 0L) {
  112.          var1 -= var1 % (long)this.frameSize;
  113.       }
  114.  
  115.       if (this.frameLength != -1L && var1 / (long)this.frameSize > this.frameLength - this.framePos) {
  116.          var1 = (this.frameLength - this.framePos) * (long)this.frameSize;
  117.       }
  118.  
  119.       long var3 = this.stream.skip(var1);
  120.       if (var3 % (long)this.frameSize != 0L) {
  121.          throw new IOException("Could not skip an integer number of frames.");
  122.       } else {
  123.          if (var3 >= 0L) {
  124.             this.framePos += var3 / (long)this.frameSize;
  125.          }
  126.  
  127.          return var3;
  128.       }
  129.    }
  130.  
  131.    public int available() throws IOException {
  132.       int var1 = this.stream.available();
  133.       return this.frameLength != -1L && (long)(var1 / this.frameSize) > this.frameLength - this.framePos ? (int)(this.frameLength - this.framePos) * this.frameSize : var1;
  134.    }
  135.  
  136.    public void close() throws IOException {
  137.       this.stream.close();
  138.    }
  139.  
  140.    public void mark(int var1) {
  141.       this.stream.mark(var1);
  142.       if (this.markSupported()) {
  143.          this.markpos = this.framePos;
  144.       }
  145.  
  146.    }
  147.  
  148.    public void reset() throws IOException {
  149.       this.stream.reset();
  150.       this.framePos = this.markpos;
  151.    }
  152.  
  153.    public boolean markSupported() {
  154.       return this.markSupported;
  155.    }
  156. }
  157.