Beispiel #1
0
 @Override
 public int read(ByteBuffer buf) throws IOException {
   ShortBuffer sbuf = buf.asShortBuffer();
   int total = 0;
   while (sbuf.hasRemaining() && _header != null) {
     if (_buffer == null) {
       try {
         _buffer = (SampleBuffer) _decoder.decodeFrame(_header, _istream);
         _istream.closeFrame();
         _header = _istream.readFrame();
       } catch (JavaLayerException e) {
         throw new IOException(e.toString());
       }
     }
     int blen = _buffer.getBufferLength(), length = Math.min(sbuf.remaining(), blen - _offset);
     sbuf.put(_buffer.getBuffer(), _offset, length);
     if ((_offset += length) >= blen) {
       _offset = 0;
       _buffer = null;
     }
     total += (length * 2);
   }
   buf.position(buf.position() + total);
   return total;
 }
Beispiel #2
0
 @Override
 public void init(InputStream in) throws IOException {
   _istream = new Bitstream(in);
   try {
     _header = _istream.readFrame();
   } catch (JavaLayerException e) {
     throw new IOException(e.toString());
   }
   _decoder = new Decoder();
 }