本文整理了Java中org.apache.jackrabbit.oak.commons.IOUtils.readFully()
方法的一些代码示例,展示了IOUtils.readFully()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.readFully()
方法的具体详情如下:
包路径:org.apache.jackrabbit.oak.commons.IOUtils
类名称:IOUtils
方法名:readFully
[英]Try to read the given number of bytes to the buffer. This method reads until the maximum number of bytes have been read or until the end of file.
[中]尝试将给定数量的字节读入缓冲区。此方法一直读取,直到读取了最大字节数或文件结束。
代码示例来源:origin: org.apache.jackrabbit/oak-mk-remote
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);
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
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;
}
代码示例来源:origin: apache/jackrabbit-oak
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;
}
代码示例来源:origin: org.apache.jackrabbit/oak-blob
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;
}
代码示例来源:origin: apache/jackrabbit-oak
@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;
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
@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;
}
代码示例来源:origin: org.apache.jackrabbit/oak-blob
@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;
}
代码示例来源:origin: apache/jackrabbit-oak
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));
}
}
代码示例来源:origin: apache/jackrabbit-oak
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));
}
}
代码示例来源:origin: apache/jackrabbit-oak
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));
}
}
代码示例来源:origin: apache/jackrabbit-oak
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]);
}
}
代码示例来源:origin: apache/jackrabbit-oak
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]);
}
}
代码示例来源:origin: apache/jackrabbit-oak
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]);
}
}
代码示例来源:origin: apache/jackrabbit-oak
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]);
}
}
代码示例来源:origin: apache/jackrabbit-oak
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]);
}
}
代码示例来源:origin: apache/jackrabbit-oak
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]);
}
}
代码示例来源:origin: apache/jackrabbit-oak
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));
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
IOUtils.readFully(idStream, digest, 0, digest.length);
BlockId id = new BlockId(digest, 0);
mark(id);
代码示例来源:origin: apache/jackrabbit-oak
IOUtils.readFully(idStream, digest, 0, digest.length);
BlockId id = new BlockId(digest, 0);
mark(id);
代码示例来源:origin: org.apache.jackrabbit/oak-blob
IOUtils.readFully(idStream, digest, 0, digest.length);
BlockId id = new BlockId(digest, 0);
mark(id);
内容来源于网络,如有侵权,请联系作者删除!