01: //
02: // Copyright (C) 2005 United States Government as represented by the
03: // Administrator of the National Aeronautics and Space Administration
04: // (NASA). All Rights Reserved.
05: //
06: // This software is distributed under the NASA Open Source Agreement
07: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
08: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
09: // directory tree for the complete NOSA document.
10: //
11: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18: //
19:
20: package java.io;
21:
22: /**
23: * MJI model class for java.io.RandomAccessFile
24: *
25: * @author Owen O'Malley
26: */
27: public class RandomAccessFile {
28: public RandomAccessFile(File name, String permissions)
29: throws FileNotFoundException {
30: filename = name;
31: isOpen = true;
32: isReadOnly = "r".equals(permissions);
33: setDataMap();
34: }
35:
36: public void seek(long posn) throws IOException {
37: currentPosition = posn;
38: }
39:
40: public long length() throws IOException {
41: return currentLength;
42: }
43:
44: public native void setDataMap();
45:
46: public native void writeByte(int data) throws IOException;
47:
48: public native void write(byte[] data, int start, int len)
49: throws IOException;
50:
51: public native void setLength(long len) throws IOException;
52:
53: public native int read(byte[] data, int start, int len)
54: throws IOException;
55:
56: public native byte readByte() throws IOException;
57:
58: public void close() throws IOException {
59: isOpen = false;
60: }
61:
62: private static class DataRepresentation {
63: DataRepresentation next;
64: long chunk_index;
65: int[] data;
66: }
67:
68: private final static void printList(DataRepresentation node) {
69: DataRepresentation cur = node;
70: System.out.print("Chunks:");
71: while (cur != null) {
72: System.out.print(" " + cur.chunk_index);
73: cur = cur.next;
74: }
75: System.out.println();
76: }
77:
78: private static final int CHUNK_SIZE = 256;
79: private File filename;
80: private boolean isOpen;
81: private boolean isReadOnly;
82: private long currentLength;
83: private long currentPosition;
84: private DataRepresentation data_root = null;
85: }
|