equal
deleted
inserted
replaced
28 import java.io.DataInput; |
28 import java.io.DataInput; |
29 import java.io.EOFException; |
29 import java.io.EOFException; |
30 import java.io.File; |
30 import java.io.File; |
31 import java.io.IOException; |
31 import java.io.IOException; |
32 import java.io.RandomAccessFile; |
32 import java.io.RandomAccessFile; |
|
33 import java.nio.file.Path; |
33 |
34 |
34 public final class RecordingInput implements DataInput, AutoCloseable { |
35 public final class RecordingInput implements DataInput, AutoCloseable { |
35 |
36 |
36 |
37 |
37 private final static int DEFAULT_BLOCK_SIZE = 16 * 1024 * 1024; |
38 private final static int DEFAULT_BLOCK_SIZE = 16 * 1024 * 1024; |
55 } |
56 } |
56 |
57 |
57 public byte get(long position) { |
58 public byte get(long position) { |
58 return bytes[(int) (position - blockPosition)]; |
59 return bytes[(int) (position - blockPosition)]; |
59 } |
60 } |
|
61 |
|
62 public void reset() { |
|
63 blockPosition = 0; |
|
64 size = 0; |
|
65 } |
60 } |
66 } |
61 |
67 |
62 private final RandomAccessFile file; |
68 private final RandomAccessFile file; |
63 private final String filename; |
69 private final String filename; |
64 private Block currentBlock = new Block(); |
70 private Block currentBlock = new Block(); |
77 } |
83 } |
78 |
84 |
79 public RecordingInput(File f) throws IOException { |
85 public RecordingInput(File f) throws IOException { |
80 this(f, DEFAULT_BLOCK_SIZE); |
86 this(f, DEFAULT_BLOCK_SIZE); |
81 } |
87 } |
|
88 |
82 public void positionPhysical(long position) throws IOException { |
89 public void positionPhysical(long position) throws IOException { |
83 file.seek(position); |
90 file.seek(position); |
84 } |
91 } |
85 public final byte readPhysicalByte() throws IOException { |
92 public final byte readPhysicalByte() throws IOException { |
86 return file.readByte(); |
93 return file.readByte(); |
324 |
331 |
325 public String getFilename() { |
332 public String getFilename() { |
326 return filename; |
333 return filename; |
327 } |
334 } |
328 |
335 |
|
336 // Purpose of this method is to reuse block cache from a |
|
337 // previous RecordingInput |
|
338 public RecordingInput newFile(Path path) throws IOException { |
|
339 try { |
|
340 close(); |
|
341 } catch (IOException e) { |
|
342 // perhaps deleted |
|
343 } |
|
344 RecordingInput input = new RecordingInput(path.toFile(), this.blockSize); |
|
345 input.currentBlock = this.currentBlock; |
|
346 input.currentBlock.reset(); |
|
347 input.previousBlock = this.previousBlock; |
|
348 input.previousBlock.reset(); |
|
349 |
|
350 return input; |
|
351 } |
|
352 |
329 } |
353 } |