1 // FileDescriptor.java - Open file or device
3 /* Copyright (C) 1998, 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
14 * @author Tom Tromey <tromey@cygnus.com>
15 * @date September 24, 1998
18 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
19 * "The Java Language Specification", ISBN 0-201-63451-1
20 * Status: Complete to 1.1
23 // For now we assume a POSIXy file system. This can be changed later
25 public final class FileDescriptor
27 public static final FileDescriptor in = new FileDescriptor (0);
28 public static final FileDescriptor out = new FileDescriptor (1);
29 public static final FileDescriptor err = new FileDescriptor (2);
31 public native void sync () throws SyncFailedException;
32 public native boolean valid ();
35 // These are mode values for open().
36 static final int READ = 1;
37 static final int WRITE = 2;
38 static final int APPEND = 4;
40 // These are WHENCE values for seek.
41 static final int SET = 0;
42 static final int CUR = 1;
44 // Open a file. MODE is a combination of the above mode flags.
45 FileDescriptor (String path, int mode) throws FileNotFoundException
47 fd = open (path, mode);
50 public FileDescriptor ()
55 native int open (String path, int mode) throws FileNotFoundException;
56 native void write (int b) throws IOException;
57 native void write (byte[] b, int offset, int len)
58 throws IOException, NullPointerException, IndexOutOfBoundsException;
59 native void close () throws IOException;
60 native int seek (long pos, int whence) throws IOException;
61 native long length () throws IOException;
62 native long getFilePointer () throws IOException;
63 native int read () throws IOException;
64 native int read (byte[] bytes, int offset, int len) throws IOException;
65 native int available () throws IOException;
68 // When collected, close.
69 protected void finalize () throws IOException
75 // Attach to an already-opened file. This is not private because we
76 // need access to it from other packages, for instance java.net.
77 // Ordinarily that wouldn't work, either, but in our case we know
78 // the access comes from C++, where "package private" is translated
79 // into "public". Eww.
80 FileDescriptor (int desc)
85 // System's notion of file descriptor.