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

  1. package netscape.netcast;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.RandomAccessFile;
  6. import marimba.castanet.client.CastanetFile;
  7. import marimba.castanet.util.Checksum;
  8. import marimba.io.RAFInputStream;
  9.  
  10. class FileCacheFile extends File implements CastanetFile {
  11.    FileCache cache;
  12.    long total;
  13.    // $FF: renamed from: cs marimba.castanet.util.Checksum
  14.    Checksum field_0;
  15.    FileCacheFile next;
  16.  
  17.    FileCacheFile(FileCache cache, File dir, String path, long total) {
  18.       super(dir, path);
  19.       this.cache = cache;
  20.       this.total = total;
  21.    }
  22.  
  23.    public RAFInputStream getInputStream() {
  24.       try {
  25.          if (this.total == -2L) {
  26.             return new RAFInputStream(new RandomAccessFile(this, "r"));
  27.          } else {
  28.             try {
  29.                return new FileCacheInputStream(this);
  30.             } catch (IOException var2) {
  31.                File parent = new File(((File)this).getParent());
  32.                return !parent.exists() && parent.mkdirs() ? new FileCacheInputStream(this) : null;
  33.             }
  34.          }
  35.       } catch (IOException var3) {
  36.          return null;
  37.       }
  38.    }
  39.  
  40.    public Checksum getChecksum() {
  41.       return this.field_0 != null ? this.field_0 : (this.field_0 = new Checksum(((File)this).getName()));
  42.    }
  43.  
  44.    public boolean waitFor() {
  45.       if (this.complete()) {
  46.          return true;
  47.       } else {
  48.          boolean var1;
  49.          try {
  50.             this.cache.addWaiter(this);
  51.             synchronized(this){}
  52.  
  53.             try {
  54.                while(!this.complete()) {
  55.                   this.wait();
  56.                }
  57.             } catch (Throwable var11) {
  58.                throw var11;
  59.             }
  60.  
  61.             var1 = this.total >= 0L;
  62.             return var1;
  63.          } catch (InterruptedException var12) {
  64.             var1 = false;
  65.          } finally {
  66.             this.cache.removeWaiter(this);
  67.          }
  68.  
  69.          return var1;
  70.       }
  71.    }
  72.  
  73.    int waitForData(FileCacheInputStream in) throws IOException {
  74.       try {
  75.          this.cache.addReader(this);
  76.          synchronized(this){}
  77.  
  78.          try {
  79.             while(this.total >= 0L) {
  80.                long fp = ((RAFInputStream)in).getFilePointer();
  81.                if (fp < 0L) {
  82.                   byte var22 = -1;
  83.                   return var22;
  84.                }
  85.  
  86.                long length = ((RAFInputStream)in).length();
  87.                if (length < 0L) {
  88.                   byte var21 = -1;
  89.                   return var21;
  90.                }
  91.  
  92.                if (fp < length) {
  93.                   int var20 = (int)(length - fp);
  94.                   return var20;
  95.                }
  96.  
  97.                if (length >= this.total) {
  98.                   byte var4 = -1;
  99.                   return var4;
  100.                }
  101.  
  102.                this.wait();
  103.             }
  104.  
  105.             return -1;
  106.          } catch (Throwable var17) {
  107.             throw var17;
  108.          }
  109.       } catch (InterruptedException var18) {
  110.          return -1;
  111.       } finally {
  112.          this.cache.removeReader(this);
  113.       }
  114.    }
  115.  
  116.    boolean complete() {
  117.       return this.total >= 0L && this.total == super.length() || this.total == -2L;
  118.    }
  119.  
  120.    synchronized void notifyComplete() {
  121.       this.notify();
  122.    }
  123.  
  124.    synchronized void notifyData() {
  125.       this.notify();
  126.    }
  127.  
  128.    synchronized void notifyError() {
  129.       this.total = -1L;
  130.       this.notify();
  131.    }
  132.  
  133.    public long length() {
  134.       return this.total == -2L ? super.length() : this.total;
  135.    }
  136. }
  137.