MCPcopy Create free account
hub / github.com/badvision/jace / readBlock

Method readBlock

src/main/java/jace/hardware/massStorage/FileNode.java:172–206  ·  view source on GitHub ↗
(int block, byte[] buffer)

Source from the content-addressed store, hash-verified

170 }
171
172 @Override
173 public void readBlock(int block, byte[] buffer) throws IOException {
174 allocate();
175 int dataBlocks = (int) ((getPhysicalFile().length() + ProdosVirtualDisk.BLOCK_SIZE - 1) / ProdosVirtualDisk.BLOCK_SIZE);
176 int treeBlocks = (((dataBlocks * 2) + (ProdosVirtualDisk.BLOCK_SIZE - 2)) / ProdosVirtualDisk.BLOCK_SIZE);
177 if (treeBlocks > 1) {
178 treeBlocks++;
179 }
180 switch (this.getType()) {
181 case SEEDLING:
182 readFile(buffer, 0);
183 break;
184 case SAPLING:
185 if (block > 0) {
186 readFile(buffer, (block - 1));
187 } else {
188 // Generate seedling index block
189 generateIndex(buffer, 1, dataBlocks + 1);
190 }
191 break;
192 case TREE:
193 if (block == 0) {
194 generateIndex(buffer, 1, treeBlocks);
195 } else if (block <= treeBlocks) {
196 int start = treeBlocks + ((block - 1) * 256);
197 int end = treeBlocks + dataBlocks;
198 generateIndex(buffer, start, end);
199 } else {
200 readFile(buffer, (block - treeBlocks - 1));
201 }
202 break;
203 default:
204 // ignore
205 }
206 }
207
208 private void readFile(byte[] buffer, int start) throws IOException {
209 try (FileInputStream f = new FileInputStream(physicalFile)) {

Callers

nothing calls this directly

Calls 5

getTypeMethod · 0.95
readFileMethod · 0.95
generateIndexMethod · 0.95
allocateMethod · 0.80
getPhysicalFileMethod · 0.80

Tested by

no test coverage detected