87 |
} |
} |
88 |
} |
} |
89 |
|
|
90 |
public Block get(BlockId id) { |
public Block get(BlockId id) throws FileNotFoundException { |
91 |
|
if(!blocks.keySet().contains(id)) |
92 |
|
throw new FileNotFoundException("No such block: "+id); |
93 |
|
|
94 |
return (Block)blocks.get(id); |
return (Block)blocks.get(id); |
95 |
} |
} |
96 |
public void add(Block b) {} |
public void add(Block b) throws IOException { |
97 |
|
byte[] body = gzz.util.CopyUtil.readBytes(b.getInputStream()); |
98 |
|
byte[] raw = gzz.util.CopyUtil.readBytes(b.getRawInputStream()); |
99 |
|
|
100 |
|
InputStream is = b.getRawInputStream(); |
101 |
|
Header822 header = Headers822.readHeader(is); |
102 |
|
is.close(); |
103 |
|
|
104 |
|
int headerLength = raw.length - body.length; |
105 |
|
|
106 |
|
Block block = new TransientBlock(raw, header, headerLength); |
107 |
|
BlockId id = block.getId(); |
108 |
|
|
109 |
|
if(!id.equals(b.getId())) |
110 |
|
throw new IOException("Block with bad id supplied"); |
111 |
|
|
112 |
|
blocks.put(block.getId(), block); |
113 |
|
} |
114 |
public void delete(Block b) {} |
public void delete(Block b) {} |
115 |
public Set getIds() { return blocks.keySet(); } |
public Set getIds() { return blocks.keySet(); } |
116 |
public BlockOutputStream getBlockOutputStream(String contentType) |
public BlockOutputStream getBlockOutputStream(String contentType) |