home *** CD-ROM | disk | FTP | other *** search
- package netscape.netcast;
-
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import marimba.io.RAFInputStream;
-
- final class FileCacheInputStream extends RAFInputStream {
- FileCacheFile file;
-
- FileCacheInputStream(FileCacheFile file) throws IOException {
- super(new RandomAccessFile(file, "rw"));
- this.file = file;
- }
-
- public int read() throws IOException {
- int avail = this.file.waitForData(this);
- return avail > 0 ? super.read() : -1;
- }
-
- public int read(byte[] b) throws IOException {
- return this.read(b, 0, b.length);
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- int avail = this.file.waitForData(this);
- if (avail > 0) {
- int n = super.read(b, off, Math.min(avail, len));
- return n <= 0 && len > 0 ? -1 : n;
- } else {
- return -1;
- }
- }
- }
-