Initial import
[jpf-core.git] / src / classes / java / io / RandomAccessFile.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
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
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
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.
17  */
18 package java.io;
19
20 import java.nio.channels.FileChannel;
21
22 import java.io.FileDescriptor;
23 /**
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
29  *
30  * @author Owen O'Malley
31  */
32 @SuppressWarnings("unused")
33 public class RandomAccessFile {
34   public RandomAccessFile(File name, String permissions
35                          ) throws FileNotFoundException {
36     filename = name;
37     isOpen = true;
38     isReadOnly = "r".equals(permissions);
39     setDataMap();
40   }
41
42   public RandomAccessFile(String name, String permissions
43                          ) throws FileNotFoundException {
44     this(new File(name), permissions);
45   }
46
47   public void seek(long posn) throws IOException {
48     currentPosition = posn;
49   }
50
51   public long length() throws IOException {
52     return currentLength;
53   }
54
55   public native void setDataMap();
56   
57   public native void writeByte(int data) throws IOException;
58
59   public native void write(byte[] data, int start, int len
60                           ) throws IOException;
61
62
63   public native void setLength(long len) throws IOException;
64
65   public native int read(byte[] data, int start, int len
66                          ) throws IOException;
67
68   public native byte readByte() throws IOException;
69
70   public void close() throws IOException {
71     isOpen = false;
72   }
73
74   public FileChannel getChannel(){
75     return null;//TODO
76   }
77
78   public FileDescriptor getFD(){
79     return null;//TODO
80   }
81
82   private static class DataRepresentation {
83     DataRepresentation next;
84     long chunk_index;
85     int[] data;
86   }
87
88   private final static void printList(DataRepresentation node) {
89     DataRepresentation cur = node;
90     System.out.print("Chunks:");
91     while (cur != null) {
92       System.out.print(" " + cur.chunk_index);
93       cur = cur.next;
94     }
95     System.out.println();
96   }
97
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;
105 }
106