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.
20 import java.nio.channels.FileChannel;
22 import java.io.FileDescriptor;
24 * MJI model class for java.io.RandomAccessFile
25 * This class cannot yet handle File I/O correctly
26 * Some work about the use of RandomAccessFile can be
27 * found here : https://bitbucket.org/pfjeau/jpf_for_nanohttpd/src/8f880ee27410026c69cf37f1904b159965d1576e/?at=raf-progress
28 * Another way to implement all the missing features is to fix the jpf-bfs project in order to handle file I/O
30 * @author Owen O'Malley
32 @SuppressWarnings("unused")
33 public class RandomAccessFile {
34 public RandomAccessFile(File name, String permissions
35 ) throws FileNotFoundException {
38 isReadOnly = "r".equals(permissions);
42 public RandomAccessFile(String name, String permissions
43 ) throws FileNotFoundException {
44 this(new File(name), permissions);
47 public void seek(long posn) throws IOException {
48 currentPosition = posn;
51 public long length() throws IOException {
55 public native void setDataMap();
57 public native void writeByte(int data) throws IOException;
59 public native void write(byte[] data, int start, int len
63 public native void setLength(long len) throws IOException;
65 public native int read(byte[] data, int start, int len
68 public native byte readByte() throws IOException;
70 public void close() throws IOException {
74 public FileChannel getChannel(){
78 public FileDescriptor getFD(){
82 private static class DataRepresentation {
83 DataRepresentation next;
88 private final static void printList(DataRepresentation node) {
89 DataRepresentation cur = node;
90 System.out.print("Chunks:");
92 System.out.print(" " + cur.chunk_index);
98 private static final int CHUNK_SIZE = 256;
99 private File filename;
100 private boolean isOpen;
101 private boolean isReadOnly;
102 private long currentLength;
103 private long currentPosition;
104 private DataRepresentation data_root = null;