source: trunk/src/gcc/libjava/java/io/FileDescriptor.java@ 154

Last change on this file since 154 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.1 KB
Line 
1// FileDescriptor.java - Open file or device
2
3/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
4
5 This file is part of libgcj.
6
7This software is copyrighted work licensed under the terms of the
8Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9details. */
10
11package java.io;
12
13/**
14 * @author Tom Tromey <[email protected]>
15 * @date September 24, 1998
16 */
17
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
21 */
22
23// For now we assume a POSIXy file system. This can be changed later
24// if need be.
25public final class FileDescriptor
26{
27
28 public static final FileDescriptor in = null;
29 public static final FileDescriptor out = null;
30 public static final FileDescriptor err = null;
31
32 private static native void init();
33 static
34 {
35 init();
36 }
37
38 public native void sync () throws SyncFailedException;
39 public native boolean valid ();
40
41 // These are mode values for open().
42 static final int READ = 1;
43 static final int WRITE = 2;
44 static final int APPEND = 4;
45 // EXCL is used only when making a temp file.
46 static final int EXCL = 8;
47
48 // These are WHENCE values for seek.
49 static final int SET = 0;
50 static final int CUR = 1;
51
52 // This constructor is specified to create an invalid descriptor.
53 public FileDescriptor ()
54 {
55 }
56
57 // Open a file. MODE is a combination of the above mode flags.
58 FileDescriptor (String path, int mode) throws FileNotFoundException
59 {
60 fd = open (path, mode);
61 }
62
63 native int open (String path, int mode) throws FileNotFoundException;
64 native void write (int b) throws IOException;
65 native void write (byte[] b, int offset, int len)
66 throws IOException, NullPointerException, IndexOutOfBoundsException;
67 native void close () throws IOException;
68 // EOF_TRUNC is true if a request to seek past the end of file
69 // should actually stop at the end of file. If false, then a seek
70 // past the end is ok (and if a subsequent write occurs the file
71 // will grow).
72 native int seek (long pos, int whence, boolean eof_trunc) throws IOException;
73 native long length () throws IOException;
74 native long getFilePointer () throws IOException;
75 native int read () throws IOException;
76 native int read (byte[] bytes, int offset, int len) throws IOException;
77 native int available () throws IOException;
78
79
80 // When collected, close.
81 protected void finalize () throws IOException
82 {
83 if (valid ())
84 close ();
85 }
86
87 // Attach to an already-opened file. This is not private because we
88 // need access to it from other packages, for instance java.net.
89 // Ordinarily that wouldn't work, either, but in our case we know
90 // the access comes from C++, where "package private" is translated
91 // into "public". Eww.
92 FileDescriptor (int desc)
93 {
94 fd = desc;
95 }
96
97 // System's notion of file descriptor. It might seem redundant to
98 // initialize this given that it is reassigned in the constructors.
99 // However, this is necessary because if open() throws an exception
100 // we want to make sure this has the value -1. This is the most
101 // efficient way to accomplish that.
102 private int fd = -1;
103}
Note: See TracBrowser for help on using the repository browser.