@Override protected byte[] readBlockFromBackend(BlockId id) throws IOException { File f = getFile(id.digest, false); if (!f.exists()) { File old = getFile(id.digest, true); f.getParentFile().mkdir(); old.renameTo(f); f = getFile(id.digest, false); } int length = (int) Math.min(f.length(), getBlockSize()); byte[] data = new byte[length]; InputStream in = new FileInputStream(f); try { IOUtils.skipFully(in, id.pos); IOUtils.readFully(in, data, 0, length); } finally { in.close(); } return data; }
@Override protected byte[] readBlockFromBackend(BlockId id) throws IOException { File f = getFile(id.digest, false); if (!f.exists()) { File old = getFile(id.digest, true); f.getParentFile().mkdir(); old.renameTo(f); f = getFile(id.digest, false); } int length = (int) Math.min(f.length(), getBlockSize()); byte[] data = new byte[length]; InputStream in = new FileInputStream(f); try { IOUtils.skipFully(in, id.pos); IOUtils.readFully(in, data, 0, length); } finally { in.close(); } return data; }
@Override protected byte[] readBlockFromBackend(BlockId id) throws IOException { File f = getFile(id.digest, false); if (!f.exists()) { File old = getFile(id.digest, true); f.getParentFile().mkdir(); old.renameTo(f); f = getFile(id.digest, false); } int length = (int) Math.min(f.length(), getBlockSize()); byte[] data = new byte[length]; InputStream in = new FileInputStream(f); try { IOUtils.skipFully(in, id.pos); IOUtils.readFully(in, data, 0, length); } finally { in.close(); } return data; }
} else if (type == TYPE_DATA) { int len = IOUtils.readVarInt(idStream); IOUtils.skipFully(idStream, len); } else if (type == TYPE_HASH) { int level = IOUtils.readVarInt(idStream);
} else if (type == TYPE_DATA) { int len = IOUtils.readVarInt(idStream); IOUtils.skipFully(idStream, len); } else if (type == TYPE_HASH) { int level = IOUtils.readVarInt(idStream);
} else if (type == TYPE_DATA) { int len = IOUtils.readVarInt(idStream); IOUtils.skipFully(idStream, len); } else if (type == TYPE_HASH) { int level = IOUtils.readVarInt(idStream);
public void testSkipFully() throws IOException { final Random r = new Random(1); byte[] data = new byte[1000]; r.nextBytes(data); FilterInputStream in = new FilterInputStream(new ByteArrayInputStream(data)) { @Override public int read(byte[] buffer, int off, int max) throws IOException { return in.read(buffer, off, Math.min(10, max)); } }; in.mark(10000); IOUtils.skipFully(in, 1000); assertEquals(-1, in.read()); in.reset(); try { IOUtils.skipFully(in, 1001); fail(); } catch (EOFException e) { // expected } }
int len = IOUtils.readVarInt(idStream); if (pos < len) { IOUtils.skipFully(idStream, (int) pos); len -= pos; if (length < len) { return len; IOUtils.skipFully(idStream, len); pos -= len; } else if (type == TYPE_HASH) { byte[] block = readBlock(digest, readPos); ByteArrayInputStream in = new ByteArrayInputStream(block); IOUtils.skipFully(in, pos - readPos); return IOUtils.readFully(in, buff, off, length);
int len = IOUtils.readVarInt(idStream); if (pos < len) { IOUtils.skipFully(idStream, (int) pos); len -= pos; if (length < len) { return len; IOUtils.skipFully(idStream, len); pos -= len; } else if (type == TYPE_HASH) { byte[] block = readBlock(digest, readPos); ByteArrayInputStream in = new ByteArrayInputStream(block); IOUtils.skipFully(in, pos - readPos); return IOUtils.readFully(in, buff, off, length);
int len = IOUtils.readVarInt(idStream); if (pos < len) { IOUtils.skipFully(idStream, (int) pos); len -= pos; if (length < len) { return len; IOUtils.skipFully(idStream, len); pos -= len; } else if (type == TYPE_HASH) { byte[] block = readBlock(digest, readPos); ByteArrayInputStream in = new ByteArrayInputStream(block); IOUtils.skipFully(in, pos - readPos); return IOUtils.readFully(in, buff, off, length);
} else if (type == TYPE_DATA) { int len = IOUtils.readVarInt(idStream); IOUtils.skipFully(idStream, len); } else if (type == TYPE_HASH) { int level = IOUtils.readVarInt(idStream);
} else if (type == TYPE_DATA) { int len = IOUtils.readVarInt(idStream); IOUtils.skipFully(idStream, len); } else if (type == TYPE_HASH) { int level = IOUtils.readVarInt(idStream);
} else if (type == TYPE_DATA) { int len = IOUtils.readVarInt(idStream); IOUtils.skipFully(idStream, len); } else if (type == TYPE_HASH) { int level = IOUtils.readVarInt(idStream);