本文整理汇总了Java中com.google.common.io.CountingInputStream类的典型用法代码示例。如果您正苦于以下问题:Java CountingInputStream类的具体用法?Java CountingInputStream怎么用?Java CountingInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CountingInputStream类属于com.google.common.io包,在下文中一共展示了CountingInputStream类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: fetchData
点赞 3
import com.google.common.io.CountingInputStream; //导入依赖的package包/类
public byte[] fetchData(String blobKey, long startIndex, long l) {
CountingInputStream inputStream = new CountingInputStream(getInputStream(blobKey));
byte[] bytes = new byte[(int) l];
try {
int readSize = inputStream.read(bytes, (int) startIndex, (int) l);
if (readSize < l) {
bytes = ArrayUtils.subarray(bytes, 0, readSize - 1);
}
} catch (IOException e) {
LOGGER.warn("Failed to read bytes", e);
} finally {
try {
inputStream.close();
} catch (IOException ignored) {
LOGGER.warn("Exception while closing inputStream", ignored);
}
}
return bytes;
}
开发者ID:logistimo,
项目名称:logistimo-web-service,
代码行数:20,
代码来源:HDFSBlobStoreService.java
示例2: testEmptyWorks
点赞 3
import com.google.common.io.CountingInputStream; //导入依赖的package包/类
@Test
public void testEmptyWorks() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
MessageCodec cmc = new MessageCodec();
Codec.Encoder encoder = cmc.getEncoder(dos);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(0, offset);
CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = cmc.getDecoder(dis);
assertFalse(decoder.advance());
dis.close();
assertEquals(0, cis.getCount());
}
开发者ID:fengchen8086,
项目名称:ditb,
代码行数:19,
代码来源:TestCellMessageCodec.java
示例3: testOne
点赞 3
import com.google.common.io.CountingInputStream; //导入依赖的package包/类
@Test
public void testOne() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
MessageCodec cmc = new MessageCodec();
Codec.Encoder encoder = cmc.getEncoder(dos);
final KeyValue kv =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
encoder.write(kv);
encoder.flush();
dos.close();
long offset = cos.getCount();
CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = cmc.getDecoder(dis);
assertTrue(decoder.advance()); // First read should pull in the KV
assertFalse(decoder.advance()); // Second read should trip over the end-of-stream marker and return false
dis.close();
assertEquals(offset, cis.getCount());
}
开发者ID:fengchen8086,
项目名称:ditb,
代码行数:22,
代码来源:TestCellMessageCodec.java
示例4: testEmptyWorks
点赞 3
import com.google.common.io.CountingInputStream; //导入依赖的package包/类
@Test
public void testEmptyWorks() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
KeyValueCodec kvc = new KeyValueCodec();
Codec.Encoder encoder = kvc.getEncoder(dos);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(0, offset);
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = kvc.getDecoder(dis);
assertFalse(decoder.advance());
dis.close();
assertEquals(0, cis.getCount());
}
开发者ID:fengchen8086,
项目名称:ditb,
代码行数:20,
代码来源:TestKeyValueCodec.java
示例5: testOne
点赞 3
import com.google.common.io.CountingInputStream; //导入依赖的package包/类
@Test
public void testOne() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
KeyValueCodec kvc = new KeyValueCodec();
Codec.Encoder encoder = kvc.getEncoder(dos);
final KeyValue kv =
new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
final long length = kv.getLength() + Bytes.SIZEOF_INT;
encoder.write(kv);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(length, offset);
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = kvc.getDecoder(dis);
assertTrue(decoder.advance()); // First read should pull in the KV
// Second read should trip over the end-of-stream marker and return false
assertFalse(decoder.advance());
dis.close();
assertEquals(length, cis.getCount());
}
开发者ID:fengchen8086,
项目名称:ditb,
代码行数:26,
代码来源:TestKeyValueCodec.java
示例6: testEmptyWorks
点赞 3
import com.google.common.io.CountingInputStream; //导入依赖的package包/类
@Test
public void testEmptyWorks() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream cos = new CountingOutputStream(baos);
DataOutputStream dos = new DataOutputStream(cos);
Codec codec = new CellCodec();
Codec.Encoder encoder = codec.getEncoder(dos);
encoder.flush();
dos.close();
long offset = cos.getCount();
assertEquals(0, offset);
CountingInputStream cis =
new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
DataInputStream dis = new DataInputStream(cis);
Codec.Decoder decoder = codec.getDecoder(dis);
assertFalse(decoder.advance());
dis.close();
assertEquals(0, cis.getCount());
}
开发者ID:fengchen8086,
项目名称:ditb,
代码行数:20,
代码来源:TestCellCodec.java