home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / audio / AudioStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.6 KB  |  54 lines

  1. package sun.audio;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.FilterInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import javax.sound.midi.InvalidMidiDataException;
  8. import javax.sound.midi.MidiFileFormat;
  9. import javax.sound.midi.MidiSystem;
  10. import javax.sound.sampled.AudioFormat;
  11. import javax.sound.sampled.AudioInputStream;
  12. import javax.sound.sampled.AudioSystem;
  13. import javax.sound.sampled.UnsupportedAudioFileException;
  14.  
  15. public class AudioStream extends FilterInputStream {
  16.    protected AudioInputStream ais = null;
  17.    protected AudioFormat format = null;
  18.    protected MidiFileFormat midiformat = null;
  19.    protected InputStream stream = null;
  20.  
  21.    public AudioStream(InputStream var1) throws IOException {
  22.       super(var1);
  23.       this.stream = var1;
  24.       if (!var1.markSupported()) {
  25.          this.stream = new BufferedInputStream(var1, 1024);
  26.       }
  27.  
  28.       try {
  29.          this.ais = AudioSystem.getAudioInputStream(this.stream);
  30.          this.format = this.ais.getFormat();
  31.          super.in = this.ais;
  32.       } catch (UnsupportedAudioFileException var5) {
  33.          try {
  34.             this.midiformat = MidiSystem.getMidiFileFormat(this.stream);
  35.          } catch (InvalidMidiDataException var4) {
  36.             throw new IOException("could not create audio stream from input stream");
  37.          }
  38.       }
  39.  
  40.    }
  41.  
  42.    public AudioData getData() throws IOException {
  43.       throw new IOException("could not create AudioData object");
  44.    }
  45.  
  46.    public int getLength() {
  47.       if (this.ais != null && this.format != null) {
  48.          return (int)(this.ais.getFrameLength() * (long)this.ais.getFormat().getFrameSize());
  49.       } else {
  50.          return this.midiformat != null ? this.midiformat.getByteLength() : -1;
  51.       }
  52.    }
  53. }
  54.