109 |
return new FileBlock(id); |
return new FileBlock(id); |
110 |
} |
} |
111 |
public void add(Block b) throws IOException { |
public void add(Block b) throws IOException { |
112 |
byte[] bytes = gzz.util.CopyUtil.readBytes(b.getRawInputStream()); |
File temp = gzz.util.TempFileUtil.tmpFile(dir); |
113 |
BlockId id = BlockId.getIdForData(bytes); |
|
114 |
|
BlockId id = b.getId(); |
115 |
if(!id.equals(b.getId())) |
InputStream is = id.getCheckedInputStream(b.getRawInputStream()); |
|
throw new IOException("Block with bad id supplied"); |
|
|
|
|
116 |
OutputStream os = |
OutputStream os = |
117 |
new BufferedOutputStream(new FileOutputStream(getFile(id))); |
new BufferedOutputStream(new FileOutputStream(temp)); |
118 |
os.write(bytes); |
|
119 |
os.close(); |
gzz.util.CopyUtil.copy(is, os); |
120 |
|
|
121 |
|
if(!temp.renameTo(getFile(id))) |
122 |
|
throw new IOException("Could not rename temporary file"); |
123 |
} |
} |
124 |
public void delete(Block b) throws IOException { |
public void delete(Block b) throws IOException { |
125 |
getFile(b.getId()).delete(); |
getFile(b.getId()).delete(); |