home *** CD-ROM | disk | FTP | other *** search
/ Australian PC Authority 1999 May / may1999.iso / INTERNET / COMMUNIC / NETCAST.Z / marimb10.jar / netscape / netcast / FileCacheInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-25  |  1.2 KB  |  34 lines

  1. package netscape.netcast;
  2.  
  3. import java.io.IOException;
  4. import java.io.RandomAccessFile;
  5. import marimba.io.RAFInputStream;
  6.  
  7. final class FileCacheInputStream extends RAFInputStream {
  8.    FileCacheFile file;
  9.  
  10.    FileCacheInputStream(FileCacheFile file) throws IOException {
  11.       super(new RandomAccessFile(file, "rw"));
  12.       this.file = file;
  13.    }
  14.  
  15.    public int read() throws IOException {
  16.       int avail = this.file.waitForData(this);
  17.       return avail > 0 ? super.read() : -1;
  18.    }
  19.  
  20.    public int read(byte[] b) throws IOException {
  21.       return this.read(b, 0, b.length);
  22.    }
  23.  
  24.    public int read(byte[] b, int off, int len) throws IOException {
  25.       int avail = this.file.waitForData(this);
  26.       if (avail > 0) {
  27.          int n = super.read(b, off, Math.min(avail, len));
  28.          return n <= 0 && len > 0 ? -1 : n;
  29.       } else {
  30.          return -1;
  31.       }
  32.    }
  33. }
  34.