home *** CD-ROM | disk | FTP | other *** search
- package netscape.netcast;
-
- import java.io.File;
- import java.io.IOException;
- import java.io.RandomAccessFile;
- import marimba.castanet.client.CastanetFile;
- import marimba.castanet.util.Checksum;
- import marimba.io.RAFInputStream;
-
- class FileCacheFile extends File implements CastanetFile {
- FileCache cache;
- long total;
- // $FF: renamed from: cs marimba.castanet.util.Checksum
- Checksum field_0;
- FileCacheFile next;
-
- FileCacheFile(FileCache cache, File dir, String path, long total) {
- super(dir, path);
- this.cache = cache;
- this.total = total;
- }
-
- public RAFInputStream getInputStream() {
- try {
- if (this.total == -2L) {
- return new RAFInputStream(new RandomAccessFile(this, "r"));
- } else {
- try {
- return new FileCacheInputStream(this);
- } catch (IOException var2) {
- File parent = new File(((File)this).getParent());
- return !parent.exists() && parent.mkdirs() ? new FileCacheInputStream(this) : null;
- }
- }
- } catch (IOException var3) {
- return null;
- }
- }
-
- public Checksum getChecksum() {
- return this.field_0 != null ? this.field_0 : (this.field_0 = new Checksum(((File)this).getName()));
- }
-
- public boolean waitFor() {
- if (this.complete()) {
- return true;
- } else {
- boolean var1;
- try {
- this.cache.addWaiter(this);
- synchronized(this){}
-
- try {
- while(!this.complete()) {
- this.wait();
- }
- } catch (Throwable var11) {
- throw var11;
- }
-
- var1 = this.total >= 0L;
- return var1;
- } catch (InterruptedException var12) {
- var1 = false;
- } finally {
- this.cache.removeWaiter(this);
- }
-
- return var1;
- }
- }
-
- int waitForData(FileCacheInputStream in) throws IOException {
- try {
- this.cache.addReader(this);
- synchronized(this){}
-
- try {
- while(this.total >= 0L) {
- long fp = ((RAFInputStream)in).getFilePointer();
- if (fp < 0L) {
- byte var22 = -1;
- return var22;
- }
-
- long length = ((RAFInputStream)in).length();
- if (length < 0L) {
- byte var21 = -1;
- return var21;
- }
-
- if (fp < length) {
- int var20 = (int)(length - fp);
- return var20;
- }
-
- if (length >= this.total) {
- byte var4 = -1;
- return var4;
- }
-
- this.wait();
- }
-
- return -1;
- } catch (Throwable var17) {
- throw var17;
- }
- } catch (InterruptedException var18) {
- return -1;
- } finally {
- this.cache.removeReader(this);
- }
- }
-
- boolean complete() {
- return this.total >= 0L && this.total == super.length() || this.total == -2L;
- }
-
- synchronized void notifyComplete() {
- this.notify();
- }
-
- synchronized void notifyData() {
- this.notify();
- }
-
- synchronized void notifyError() {
- this.total = -1L;
- this.notify();
- }
-
- public long length() {
- return this.total == -2L ? super.length() : this.total;
- }
- }
-