2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
6 * The Java Pathfinder core (jpf-core) platform is licensed under the
7 * Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0.
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 import gov.nasa.jpf.annotation.FilterField;
24 * a simple abstraction for a file descriptor, which for us is little more
25 * than just an id for a native data buffer (we don't want to keep the
26 * data itself in the JPF space)
28 * <2do> still needs the standard descriptors
30 public class FileDescriptor {
31 @FilterField int fd; // to be set from the native side
33 static final int FD_READ = 0;
34 static final int FD_WRITE = 1;
36 static final int FD_NEW = 0;
37 static final int FD_OPENED = 1;
38 static final int FD_CLOSED = 2;
41 int mode; // no use to turn it into an Enum - it's accessed from the native peer
43 // we can't use the 'fd' field for it, because we need to keep that in
44 // case we have to automatically reopen after a backtrack
47 long off; // we need to keep this on the model side to make it backtrackable
49 public FileDescriptor () {
53 FileDescriptor (String fname, int mode) throws IOException, FileNotFoundException {
57 fd = open(fname, mode);
62 throw new FileNotFoundException(fname);
66 public boolean valid () {
70 public void close () throws IOException {
75 //--- those are the real work horses
76 native int open (String fname, int mode) throws IOException;
77 public native void sync();
78 native int read () throws IOException;
79 public native int read (byte[] buf, int off, int len);
80 native long skip(long n) throws IOException;
81 native int available () throws IOException;
82 native void close0 () throws IOException;
84 native void write (int b) throws IOException;
85 public native void write (byte[] buf, int off, int len);