/[classpath]/classpath/java/io/FileDescriptor.java
ViewVC logotype

Diff of /classpath/java/io/FileDescriptor.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by arenn, Sun Mar 9 20:15:08 2003 UTC revision 1.11 by arenn, Sat Mar 15 21:37:45 2003 UTC
# Line 125  public final class FileDescriptor Line 125  public final class FileDescriptor
125    {    {
126    }    }
127    
128    private FileDescriptor(int nativeFd)    private FileDescriptor(long nativeFd)
129    {    {
130      this.nativeFd = nativeFd;      this.nativeFd = nativeFd;
131    }    }
# Line 193  public final class FileDescriptor Line 193  public final class FileDescriptor
193      nativeFd = nativeOpen(path, mode);      nativeFd = nativeOpen(path, mode);
194    }    }
195    
196    void close() throws IOException    synchronized void close() throws IOException
197    {    {
198      if (nativeFd == -1L)      if (nativeFd == -1L)
199        return;        return;
200    
201      nativeClose(nativeFd);      try
202      nativeFd = -1L;        {
203            nativeClose(nativeFd);
204          }
205        catch(IOException e)
206          {
207            nativeFd = -1L;
208            throw new IOException(e.getMessage());
209          }
210    }    }
211    
212    void write(int b) throws IOException    void write(int b) throws IOException
# Line 207  public final class FileDescriptor Line 214  public final class FileDescriptor
214      if (nativeFd == -1L)      if (nativeFd == -1L)
215        throw new IOException("Invalid FileDescriptor");        throw new IOException("Invalid FileDescriptor");
216    
217      nativeWriteByte(nativeFd, (long)(b & 0xFF));      nativeWriteByte(nativeFd, (b & 0xFF));
218    }    }
219    
220    void write(byte[] buf, long offset, long len) throws IOException    void write(byte[] buf, int offset, int len) throws IOException
221    {    {
222      if (nativeFd == -1L)      if (nativeFd == -1L)
223        throw new IOException("Invalid FileDescriptor");        throw new IOException("Invalid FileDescriptor");
# Line 234  public final class FileDescriptor Line 241  public final class FileDescriptor
241      if (nativeFd == -1L)      if (nativeFd == -1L)
242        throw new IOException("Invalid FileDescriptor");        throw new IOException("Invalid FileDescriptor");
243    
244      long byteRead = nativeReadByte(nativeFd);      return(nativeReadByte(nativeFd));
     if (byteRead == -1L)  
       return(-1);  
   
     return((int)(byteRead & 0xFF));  
245    }    }
246    
247    int read(byte[] buf, int offset, int len) throws IOException    int read(byte[] buf, int offset, int len) throws IOException
# Line 257  public final class FileDescriptor Line 260  public final class FileDescriptor
260    
261      // Note that above ops implicitly bomb if buf == null      // Note that above ops implicitly bomb if buf == null
262    
263      long bytesRead = nativeReadBuf(nativeFd, buf, offset, len);      return(nativeReadBuf(nativeFd, buf, offset, len));
     if (bytesRead == -1L)  
       return(-1);  
   
     return((int)(bytesRead & 0xFFFF));  
264    }    }
265    
266    int available() throws IOException    int available() throws IOException
# Line 269  public final class FileDescriptor Line 268  public final class FileDescriptor
268      if (nativeFd == -1L)      if (nativeFd == -1L)
269        throw new IOException("Invalid FileDescriptor");        throw new IOException("Invalid FileDescriptor");
270            
271      long bytesAvail = nativeAvailable(nativeFd);      return(nativeAvailable(nativeFd));
   
     // FIXME:  Is this right?  
     if (bytesAvail > 0xFFFFL)  
       return(0xFFFF);  
     else  
       return((int)(bytesAvail & 0xFFFF));  
272    }    }
273    
274    long seek(long offset, int whence, boolean stopAtEof) throws IOException    long seek(long offset, int whence, boolean stopAtEof) throws IOException
# Line 391  public final class FileDescriptor Line 384  public final class FileDescriptor
384      *      *
385      * @exception IOException If an error occurs      * @exception IOException If an error occurs
386      */      */
387    private native long nativeWriteByte(long fd, long b) throws IOException;    private native long nativeWriteByte(long fd, int b) throws IOException;
388    // I hate name mangling.    // I hate name mangling.
389    
390    /**    /**
# Line 406  public final class FileDescriptor Line 399  public final class FileDescriptor
399      *      *
400      * @exception IOException If an error occurs      * @exception IOException If an error occurs
401      */      */
402    private native long nativeWriteBuf(long fd, byte[] buf, long offset, long len)    private native long nativeWriteBuf(long fd, byte[] buf, int offset, int len)
403      throws IOException;      throws IOException;
404    // I hate name mangling.    // I hate name mangling.
405    
# Line 420  public final class FileDescriptor Line 413  public final class FileDescriptor
413      *      *
414      * @exception IOException If an error occurs      * @exception IOException If an error occurs
415      */      */
416    private native long nativeReadByte(long fd) throws IOException;    private native int nativeReadByte(long fd) throws IOException;
417    // I hate name mangling.    // I hate name mangling.
418    
419    /**    /**
# Line 435  public final class FileDescriptor Line 428  public final class FileDescriptor
428      *      *
429      * @exception IOException If an error occurs      * @exception IOException If an error occurs
430      */      */
431    private native long nativeReadBuf(long fd, byte[] buf, long offset, long len)    private native int nativeReadBuf(long fd, byte[] buf, int offset, int len)
432      throws IOException;      throws IOException;
433    // I hate name mangling.    // I hate name mangling.
434    
# Line 448  public final class FileDescriptor Line 441  public final class FileDescriptor
441      *      *
442      * @exception IOException If an error occurs      * @exception IOException If an error occurs
443      */      */
444    private native long nativeAvailable(long fd) throws IOException;    private native int nativeAvailable(long fd) throws IOException;
445    
446    /**    /**
447      * Method to do a "seek" operation on the file      * Method to do a "seek" operation on the file

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26