Platform Interface: java.io.FileInputStream

wrapper java.io.FileInputStream requiredif RFile, RFileSystem {
  requires java.io.RFileMap;

  // can't do this: 
  //  state RFile rfile;
  //
  // Although Java binary compatibility rules should allow us to add a field to this
  // class, they rules are not necessarily valid across native methods.  Since there
  // are native methods involving FileInputStream, we run into problems when a
  // new instance variable is added to the class.  The solution is to use
  // RHState to store the object data.  This is, unfortunately, awkward and slow.
  // It is claimed that JDK 1.2 and better will support binary compatibility 
  // in the presence of new fields, but there is no formal documentation.
  //

  requires RHState;

  helper harmless RFile getRfile () {
    return (RFileRHState.getValue (this, 0);
  }

  wrapper FileInputStream (java.io.File file) {
      RFileSystem.openRead (RFileMap.lookupAdd (file));
      # ;
      RHState.add (this, 0, RFileMap.lookup (file));
  }
  
  nestwrapper FileInputStream (java.io.File file) {
      #;
      RHState.add (this, 0, null);
  }
  
  wrapper FileInputStream (java.io.FileDescriptor fd) {
    RFile trfile;
    
    if (NCheck.isInitialized ()) {
      trfile = RFileMap.lookupAddReal (fd);       
      if (trfile != null) {
        RFileSystem.openRead (trfile);
      }
    } else {
      trfile = null;
    }
    
    #
    RHState.add (this, 0, trfile);
  }

  nestwrapper FileInputStream (java.io.FileDescriptor fd) {
    #
    RHState.add (this, 0, null);
  }

  wrapper FileInputStream (String file) {
    RFileSystem.openRead (RFileMap.lookupAdd (file));
    # 
    RHState.add (this, 0, RFileMap.lookup (file));
  }

  nestwrapper FileInputStream (String file) {
    #
    RHState.add (this, 0, null);
  }

  helper void preRead (int n) {
    if (getRfile () != null) {
      RFileSystem.preRead (getRfile (), n);
    }
  }

  helper void postRead (int n) {
    if (n > 0) {
      if (getRfile () != null) {
        RFileSystem.postRead (getRfile (), n);
      }
    }
  }

  wrapper int read () {
    preRead (1);
    #
    if (result == -1) {
      ;
    } else {
      postRead (1);
    }
  }
    
  wrapper int read (byte data[]) {
    preRead (data.length);
    #
    postRead (result);  
  }
  
  wrapper int read (byte data[], int off, int num) {
    preRead (num);
    #
    postRead (result);
  }

  wrapper void close () {
    if (getRfile () != null) {
      RFileSystem.close (getRfile ());
    }
    #
  }

  wrapper java.io.FileDescriptor getFD () {
    #
    RFileMap.addReference (result, getRfile ());
  }
}

About this file

Naccio Home Page
David Evans
University of Virginia, Computer Science