37 |
|
|
38 |
/** Get the File object for the block |
/** Get the File object for the block |
39 |
* corresponding to a given id. |
* corresponding to a given id. |
40 |
|
* This is needed in many places and wrapping it in a convenience |
41 |
|
* function makes code easier to read & maintain. |
42 |
*/ |
*/ |
43 |
protected File getFile(BlockId id) { |
protected final File getFile(BlockId id) { |
44 |
String hex = gzz.util.HexUtil.byteArrToHex(id.getBytes()); |
String hex = gzz.util.HexUtil.byteArrToHex(id.getBytes()); |
45 |
return new File(dir, "b_" + hex); |
return new File(dir, "b_" + hex); |
46 |
} |
} |
47 |
|
|
48 |
/** Read the header of the block |
/** Read the header of the block |
49 |
* corresponding to the given id. |
* corresponding to the given id. |
50 |
|
* Like getFile(), this is needed in a number |
51 |
|
* of different places. |
52 |
*/ |
*/ |
53 |
protected Header822 getFileHeader(BlockId id) throws IOException { |
protected final Header822 getFileHeader(BlockId id) throws IOException { |
54 |
InputStream is = new BufferedInputStream( |
InputStream is = new BufferedInputStream( |
55 |
id.getCheckedInputStream(new FileInputStream(getFile(id)))); |
id.getCheckedInputStream(new FileInputStream(getFile(id)))); |
56 |
Header822 header = Headers822.readHeader(is); |
Header822 header = Headers822.readHeader(is); |
60 |
|
|
61 |
|
|
62 |
protected class FileBlockOutputStream extends AbstractBlockOutputStream { |
protected class FileBlockOutputStream extends AbstractBlockOutputStream { |
|
protected ByteArrayOutputStream baos; |
|
63 |
protected File tempFile; |
protected File tempFile; |
64 |
|
|
65 |
protected FileBlockOutputStream(Header822 header, File tempFile) |
protected FileBlockOutputStream(Header822 header, File tempFile) |