home *** CD-ROM | disk | FTP | other *** search
- package sun.audio;
-
- import java.io.FilterInputStream;
- import java.io.IOException;
- import java.io.InputStream;
-
- public class AudioStream extends FilterInputStream {
- NativeAudioStream audioIn;
-
- public AudioStream(InputStream in) throws IOException {
- super(in);
-
- try {
- this.audioIn = new NativeAudioStream(in);
- } catch (InvalidAudioFormatException var2) {
- this.audioIn = new AudioTranslatorStream(in);
- }
-
- super.in = this.audioIn;
- }
-
- public int read(byte[] buf, int pos, int len) throws IOException {
- int count = 0;
-
- while(count < len) {
- int n = super.read(buf, pos + count, len - count);
- if (n < 0) {
- return count;
- }
-
- count += n;
- Thread.currentThread();
- Thread.yield();
- }
-
- return count;
- }
-
- public AudioData getData() throws IOException {
- byte[] buffer = new byte[this.audioIn.getLength()];
- int gotbytes = this.read(buffer, 0, this.audioIn.getLength());
- ((FilterInputStream)this).close();
- if (gotbytes != this.audioIn.getLength()) {
- throw new IOException("audio data read error");
- } else {
- return new AudioData(buffer);
- }
- }
-
- public int getLength() {
- return this.audioIn.getLength();
- }
- }
-