62 public void reset() { |
62 public void reset() { |
63 blockPosition = 0; |
63 blockPosition = 0; |
64 blockPositionEnd = 0; |
64 blockPositionEnd = 0; |
65 } |
65 } |
66 } |
66 } |
67 |
67 private final int blockSize; |
|
68 private final FileAccess fileAccess; |
68 private RandomAccessFile file; |
69 private RandomAccessFile file; |
69 private String filename; |
70 private String filename; |
70 private Block currentBlock = new Block(); |
71 private Block currentBlock = new Block(); |
71 private Block previousBlock = new Block(); |
72 private Block previousBlock = new Block(); |
72 private long position; |
73 private long position; |
73 private final int blockSize; |
|
74 private long size = -1; // Fail fast if setSize(...) has not been called |
74 private long size = -1; // Fail fast if setSize(...) has not been called |
75 // before parsing |
75 // before parsing |
76 |
76 |
77 public RecordingInput(File f, int blockSize) throws IOException { |
77 public RecordingInput(File f, FileAccess fileAccess, int blockSize) throws IOException { |
78 this.blockSize = blockSize; |
78 this.blockSize = blockSize; |
|
79 this.fileAccess = fileAccess; |
79 initialize(f); |
80 initialize(f); |
80 } |
81 } |
81 |
82 |
82 private void initialize(File f) throws IOException { |
83 private void initialize(File f) throws IOException { |
83 this.filename = f.getAbsolutePath().toString(); |
84 this.filename = f.getAbsolutePath().toString(); |
84 this.file = new RandomAccessFile(f, "r"); |
85 this.file = fileAccess.openRAF(f, "r"); |
85 this.position = 0; |
86 this.position = 0; |
86 this.size = -1; |
87 this.size = -1; |
87 this.currentBlock.reset(); |
88 this.currentBlock.reset(); |
88 this.previousBlock.reset(); |
89 this.previousBlock.reset(); |
89 if (f.length() < 8) { |
90 if (f.length() < 8) { |
90 throw new IOException("Not a valid Flight Recorder file. File length is only " + f.length() + " bytes."); |
91 throw new IOException("Not a valid Flight Recorder file. File length is only " + f.length() + " bytes."); |
91 } |
92 } |
92 } |
93 } |
93 |
94 |
94 public RecordingInput(File f) throws IOException { |
95 public RecordingInput(File f, FileAccess fileAccess) throws IOException { |
95 this(f, DEFAULT_BLOCK_SIZE); |
96 this(f, fileAccess, DEFAULT_BLOCK_SIZE); |
96 } |
97 } |
97 |
98 |
98 public void positionPhysical(long position) throws IOException { |
99 public void positionPhysical(long position) throws IOException { |
99 file.seek(position); |
100 file.seek(position); |
100 } |
101 } |