本文整理了Java中org.apache.jackrabbit.oak.commons.IOUtils.readVarInt()
方法的一些代码示例,展示了IOUtils.readVarInt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.readVarInt()
方法的具体详情如下:
包路径:org.apache.jackrabbit.oak.commons.IOUtils
类名称:IOUtils
方法名:readVarInt
[英]Read a variable size integer.
[中]读取可变大小的整数。
代码示例来源:origin: org.apache.jackrabbit/oak-mk
@Override
public int readIntValue(String key) throws Exception {
if (in == null) {
throw new IllegalStateException("no InputStream provided");
}
return IOUtils.readVarInt(in);
}
代码示例来源:origin: apache/jackrabbit-oak
/**
* Read a byte array. This will first read the length as 4 bytes, and then
* the actual bytes.
*
* @param in the data input stream
* @return the bytes
* @throws IOException if an IO exception occurred while reading from the stream.
*/
public static byte[] readBytes(InputStream in) throws IOException {
int len = readVarInt(in);
byte[] data = new byte[len];
for (int pos = 0; pos < len;) {
int l = in.read(data, pos, data.length - pos);
if (l < 0) {
throw new EOFException();
}
pos += l;
}
return data;
}
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
/**
* Read a byte array. This will first read the length as 4 bytes, and then
* the actual bytes.
*
* @param in the data input stream
* @return the bytes
* @throws IOException if an IO exception occurred while reading from the stream.
*/
public static byte[] readBytes(InputStream in) throws IOException {
int len = readVarInt(in);
byte[] data = new byte[len];
for (int pos = 0; pos < len;) {
int l = in.read(data, pos, data.length - pos);
if (l < 0) {
throw new EOFException();
}
pos += l;
}
return data;
}
代码示例来源:origin: org.apache.jackrabbit/oak-mk
@Override
public StringEntryIterator readStringMap(String key) throws Exception {
if (in == null) {
throw new IllegalStateException("no InputStream provided");
}
final int size = IOUtils.readVarInt(in);
return new StringEntryIterator() {
int count = size;
public boolean hasNext() {
return count > 0;
}
public StringEntry next() {
if (count-- > 0) {
try {
String key = IOUtils.readString(in);
String value = IOUtils.readString(in);
return new StringEntry(key, value);
} catch (IOException e) {
throw new RuntimeException("deserialization failed", e);
}
}
throw new NoSuchElementException();
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
代码示例来源:origin: org.apache.jackrabbit/oak-commons
/**
* Read a byte array. This will first read the length as 4 bytes, and then
* the actual bytes.
*
* @param in the data input stream
* @return the bytes
* @throws IOException if an IO exception occurred while reading from the stream.
*/
public static byte[] readBytes(InputStream in) throws IOException {
int len = readVarInt(in);
byte[] data = new byte[len];
for (int pos = 0; pos < len;) {
int l = in.read(data, pos, data.length - pos);
if (l < 0) {
throw new EOFException();
}
pos += l;
}
return data;
}
代码示例来源:origin: org.apache.jackrabbit/oak-mk
throw new IllegalStateException("no InputStream provided");
final int size = IOUtils.readVarInt(in);
return new BytesEntryIterator() {
int count = size;
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
totalLength += len;
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
int digestLength = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, digestLength);
} else {
代码示例来源:origin: apache/jackrabbit-oak
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
totalLength += len;
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
int digestLength = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, digestLength);
} else {
代码示例来源:origin: apache/jackrabbit-oak
streamsStack.pop();
} else if (type == TYPE_DATA) {
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
byte[] digest = new byte[IOUtils.readVarInt(idStream)];
IOUtils.readFully(idStream, digest, 0, digest.length);
if (level > 0) {
代码示例来源:origin: apache/jackrabbit-oak
return;
} else if (type == TYPE_DATA) {
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
byte[] digest = new byte[IOUtils.readVarInt(idStream)];
IOUtils.readFully(idStream, digest, 0, digest.length);
BlockId id = new BlockId(digest, 0);
代码示例来源:origin: org.apache.jackrabbit/oak-blob
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
totalLength += len;
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
int digestLength = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, digestLength);
} else {
代码示例来源:origin: org.apache.jackrabbit/oak-blob
return;
} else if (type == TYPE_DATA) {
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
byte[] digest = new byte[IOUtils.readVarInt(idStream)];
IOUtils.readFully(idStream, digest, 0, digest.length);
BlockId id = new BlockId(digest, 0);
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
streamsStack.pop();
} else if (type == TYPE_DATA) {
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
byte[] digest = new byte[IOUtils.readVarInt(idStream)];
IOUtils.readFully(idStream, digest, 0, digest.length);
if (level > 0) {
代码示例来源:origin: org.apache.jackrabbit/oak-blob
streamsStack.pop();
} else if (type == TYPE_DATA) {
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
byte[] digest = new byte[IOUtils.readVarInt(idStream)];
IOUtils.readFully(idStream, digest, 0, digest.length);
if (level > 0) {
代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak
return;
} else if (type == TYPE_DATA) {
int len = IOUtils.readVarInt(idStream);
IOUtils.skipFully(idStream, len);
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
byte[] digest = new byte[IOUtils.readVarInt(idStream)];
IOUtils.readFully(idStream, digest, 0, digest.length);
BlockId id = new BlockId(digest, 0);
代码示例来源:origin: apache/jackrabbit-oak
public void testVarEOF() throws IOException {
try {
IOUtils.readVarInt(new ByteArrayInputStream(new byte[0]));
fail();
} catch (EOFException e) {
// expected
}
try {
IOUtils.readVarLong(new ByteArrayInputStream(new byte[0]));
fail();
} catch (EOFException e) {
// expected
}
}
代码示例来源:origin: org.apache.jackrabbit/oak-blob
return -1;
} else if (type == TYPE_DATA) {
int len = IOUtils.readVarInt(idStream);
if (pos < len) {
IOUtils.skipFully(idStream, (int) pos);
pos -= len;
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
byte[] digest = new byte[IOUtils.readVarInt(idStream)];
IOUtils.readFully(idStream, digest, 0, digest.length);
if (pos >= totalLength) {
代码示例来源:origin: apache/jackrabbit-oak
private static void testVarInt(int x, int expectedLen) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.writeVarInt(out, x);
byte[] data = out.toByteArray();
assertTrue(data.length <= 5);
if (expectedLen > 0) {
assertEquals(expectedLen, data.length);
}
ByteArrayInputStream in = new ByteArrayInputStream(data);
int x2 = IOUtils.readVarInt(in);
assertEquals(x, x2);
assertEquals(-1, in.read());
}
代码示例来源:origin: apache/jackrabbit-oak
return -1;
} else if (type == TYPE_DATA) {
int len = IOUtils.readVarInt(idStream);
if (pos < len) {
IOUtils.skipFully(idStream, (int) pos);
pos -= len;
} else if (type == TYPE_HASH) {
int level = IOUtils.readVarInt(idStream);
byte[] digest = new byte[IOUtils.readVarInt(idStream)];
IOUtils.readFully(idStream, digest, 0, digest.length);
if (pos >= totalLength) {
代码示例来源:origin: apache/jackrabbit-oak
public void testVarInt() throws IOException {
testVarInt(0, 1);
testVarInt(0x7f, 1);
testVarInt(0x80, 2);
testVarInt(0x3fff, 2);
testVarInt(0x4000, 3);
testVarInt(0x1fffff, 3);
testVarInt(0x200000, 4);
testVarInt(0xfffffff, 4);
testVarInt(0x10000000, 5);
testVarInt(-1, 5);
for (int x = 0; x < 0x20000; x++) {
testVarInt(x, 0);
testVarInt(Integer.MIN_VALUE + x, 0);
testVarInt(Integer.MAX_VALUE - x, 5);
testVarInt(0x200000 + x - 100, 0);
testVarInt(0x10000000 + x - 100, 0);
}
Random r = new Random(1);
for (int i = 0; i < 100000; i++) {
testVarInt(r.nextInt(), 0);
testVarInt(r.nextInt(10000000), 0);
}
// trailing 0s are never written, but are an alternative way to encode a value
InputStream in = new ByteArrayInputStream(new byte[]{(byte) 0x80, 0});
assertEquals(0, IOUtils.readVarInt(in));
assertEquals(-1, in.read());
}
内容来源于网络,如有侵权,请联系作者删除!