private static void readFully(InputStream in, byte[] b, int off, int len) throws IOException { int count = IOUtils.readFully(in, b, off, len); if (count < len) { String msg = String.format("Expected %d bytes, actually received: %d", len, count); throw new EOFException(msg); } }
public static byte[] readFully(BlobStore store, String id) throws IOException { int len = (int) store.getBlobLength(id); byte[] buff = new byte[len]; BlobStoreInputStream in = new BlobStoreInputStream(store, id, 0); IOUtils.readFully(in, buff, 0, len); return buff; }
public static byte[] readFully(BlobStore store, String id) throws IOException { int len = (int) store.getBlobLength(id); byte[] buff = new byte[len]; BlobStoreInputStream in = new BlobStoreInputStream(store, id, 0); IOUtils.readFully(in, buff, 0, len); return buff; }
public static byte[] readFully(BlobStore store, String id) throws IOException { int len = (int) store.getBlobLength(id); byte[] buff = new byte[len]; BlobStoreInputStream in = new BlobStoreInputStream(store, id, 0); IOUtils.readFully(in, buff, 0, len); return buff; }
@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; }
public void testReadWithEmptyBuffer() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(0); assertEquals(0, IOUtils.readFully(file.getChannel(), 0, buffer)); } }
public void testReadWithEmptyBufferFromOffset() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(0); assertEquals(0, IOUtils.readFully(file.getChannel(), 1, buffer)); } }
public void testReadOffsetOutOfBound() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(10); assertEquals(0, IOUtils.readFully(file.getChannel(), 10, buffer)); } }
public void testReadWithSmallBufferFromOffset() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(6); assertEquals(6, IOUtils.readFully(file.getChannel(), 1, buffer)); assertEquals(4, buffer.array()[3]); } }
public void testReadAll() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(8); assertEquals(8, IOUtils.readFully(file.getChannel(), 0, buffer)); assertEquals(3, buffer.array()[3]); } }
public void testReadWithLargeBuffer() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(10); assertEquals(8, IOUtils.readFully(file.getChannel(), 0, buffer)); assertEquals(3, buffer.array()[3]); } }
public void testReadAllFromOffset() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(7); assertEquals(7, IOUtils.readFully(file.getChannel(), 1, buffer)); assertEquals(4, buffer.array()[3]); } }
public void testReadWithLargeBufferFromOffset() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(10); assertEquals(7, IOUtils.readFully(file.getChannel(), 1, buffer)); assertEquals(4, buffer.array()[3]); } }
public void testReadWithSmallBuffer() throws IOException { try (RandomAccessFile file = new RandomAccessFile(testFile, "r")) { ByteBuffer buffer = ByteBuffer.allocate(6); assertEquals(6, IOUtils.readFully(file.getChannel(), 0, buffer)); assertEquals(3, buffer.array()[3]); } }
public void testReadFully() throws IOException { final Random r = new Random(1); byte[] data = new byte[1000]; final AtomicInteger readCount = new AtomicInteger(); r.nextBytes(data); FilterInputStream in = new FilterInputStream(new ByteArrayInputStream(data)) { @Override public int read(byte[] buffer, int off, int max) throws IOException { readCount.incrementAndGet(); if (r.nextInt(10) == 0) { return 0; } return in.read(buffer, off, Math.min(10, max)); } }; in.mark(10000); byte[] test = new byte[1000]; // readFully is not supposed to call read when reading 0 bytes assertEquals(0, IOUtils.readFully(in, test, 0, 0)); assertEquals(0, readCount.get()); assertEquals(1000, IOUtils.readFully(in, test, 0, 1000)); IOUtilsTest.assertEquals(data, test); test = new byte[1001]; in.reset(); in.mark(10000); assertEquals(1000, IOUtils.readFully(in, test, 0, 1001)); assertEquals(0, IOUtils.readFully(in, test, 0, 0)); }
IOUtils.readFully(idStream, digest, 0, digest.length); BlockId id = new BlockId(digest, 0); mark(id);
IOUtils.readFully(idStream, digest, 0, digest.length); BlockId id = new BlockId(digest, 0); mark(id);
IOUtils.readFully(idStream, digest, 0, digest.length); BlockId id = new BlockId(digest, 0); mark(id);