75 |
return (Block)blocks.get(id); |
return (Block)blocks.get(id); |
76 |
} |
} |
77 |
public void add(Block b) throws IOException { |
public void add(Block b) throws IOException { |
78 |
byte[] body = gzz.util.CopyUtil.readBytes(b.getInputStream()); |
byte[] bytes = gzz.util.CopyUtil.readBytes(b.getRawInputStream()); |
|
byte[] raw = gzz.util.CopyUtil.readBytes(b.getRawInputStream()); |
|
79 |
|
|
80 |
InputStream is = new ByteArrayInputStream(raw); |
BlockId id = b.getId(); |
81 |
|
id.check(bytes); |
82 |
|
|
83 |
|
InputStream is = new ByteArrayInputStream(bytes); |
84 |
Header822 header = Headers822.readHeader(is); |
Header822 header = Headers822.readHeader(is); |
85 |
is.close(); |
is.close(); |
86 |
|
|
87 |
Block block = new TransientBlock(BlockId.getIdForData(raw), |
Block block = new TransientBlock(id, bytes, header); |
88 |
raw, header); |
blocks.put(id, block); |
|
BlockId id = block.getId(); |
|
|
|
|
|
if(!id.equals(b.getId())) |
|
|
throw new IOException("Block with bad id supplied"); |
|
|
|
|
|
blocks.put(block.getId(), block); |
|
89 |
} |
} |
90 |
public void delete(Block b) { |
public void delete(Block b) { |
91 |
blocks.keySet().remove(b.getId()); |
blocks.keySet().remove(b.getId()); |