当前位置: 首页>>代码示例>>Java>>正文


Java CountingInputStream类代码示例

本文整理汇总了Java中com.google.common.io.CountingInputStream的典型用法代码示例。如果您正苦于以下问题:Java CountingInputStream类的具体用法?Java CountingInputStream怎么用?Java CountingInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CountingInputStream类属于com.google.common.io包,在下文中一共展示了CountingInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchData

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

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

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

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

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

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

示例7: testOne

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);
  Codec codec = new CellCodec();
  Codec.Encoder encoder = codec.getEncoder(dos);
  final KeyValue kv =
    new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
  kv.setSequenceId(Long.MAX_VALUE);
  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 = codec.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(offset, cis.getCount());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:TestCellCodec.java

示例8: encodeDecodeTest

import com.google.common.io.CountingInputStream; //导入依赖的package包/类
@Test
public void encodeDecodeTest() throws IOException {
    ArthmeticCoder.SimpleFrequency freq = new ArthmeticCoder.SimpleFrequency(counts);

    ByteArrayOutputStream encodedPool = new ByteArrayOutputStream();
    CountingOutputStream outputCounting = new CountingOutputStream(encodedPool);
    ArthmeticCoder.Encoder encoder = new ArthmeticCoder.Encoder(freq, new BitWrappedOutputStream(outputCounting));
    for (int s : symbols) {
        encoder.write(s);
    }
    encoder.seal();

    ByteArrayInputStream decodedPool = new ByteArrayInputStream(encodedPool.toByteArray());
    CountingInputStream inputCounting = new CountingInputStream(decodedPool);
    ArthmeticCoder.Decoder decoder = new ArthmeticCoder.Decoder(freq, new BitWrappedInputStream(inputCounting));
    int[] symbols2 = new int[symbols.length];
    for (int i = 0; i < symbols.length; i++) {
        symbols2[i] = decoder.read();
    }

    Assert.assertEquals(outputCounting.getCount(), inputCounting.getCount());
    Assert.assertArrayEquals(symbols, symbols2);
}
 
开发者ID:shunfei,项目名称:indexr,代码行数:24,代码来源:ArithmeticCoderTest.java

示例9: decode

import com.google.common.io.CountingInputStream; //导入依赖的package包/类
@VisibleForTesting
static <T> T decode(
    Coder<T> coder, Coder.Context context, byte[] bytes) throws CoderException, IOException {
  @SuppressWarnings("unchecked")
  Coder<T> deserializedCoder = SerializableUtils.clone(coder);

  byte[] buffer;
  if (context == Coder.Context.NESTED) {
    buffer = new byte[bytes.length + 1];
    System.arraycopy(bytes, 0, buffer, 0, bytes.length);
    buffer[bytes.length] = 1;
  } else {
    buffer = bytes;
  }

  CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(buffer));
  T value = deserializedCoder.decode(new UnownedInputStream(cis), context);
  assertThat("consumed bytes equal to encoded bytes", cis.getCount(),
      equalTo((long) bytes.length));
  return value;
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:CoderProperties.java

示例10: AddBlobVertexOperation

import com.google.common.io.CountingInputStream; //导入依赖的package包/类
public AddBlobVertexOperation(DuctileDBTransactionImpl transaction, long vertexId, InputStream blobContent,
    Set<String> types, Map<String, Object> properties) {
super(transaction);
try {
    this.types = Collections.unmodifiableSet(types);
    this.types.add(GraphStore.BLOB_TYPE_NAME);
    this.properties = Collections.unmodifiableMap(properties);
    this.vertex = new DuctileDBCacheVertex(transaction, vertexId, types, properties, new ArrayList<>());
    blobFile = File.createTempFile("add-vertex-" + vertex.getId(), ".blob");
    blobFile.deleteOnExit();
    try (CountingInputStream countingInputStream = new CountingInputStream(blobContent); //
	    HashIdCreatorInputStream hashIdStream = new HashIdCreatorInputStream(countingInputStream); //
	    FileOutputStream outputStream = new FileOutputStream(this.blobFile)) {
	ByteStreams.copy(hashIdStream, outputStream);
	hashId = hashIdStream.getHashId();
	long size = countingInputStream.getCount();
	properties.put(GraphStore.BLOB_HASHID_PROPERTY_NAME, hashId.toString());
	properties.put(GraphStore.BLOB_SIZE_PROPERTY_NAME, size);
    }
} catch (IOException e) {
    throw new DuctileDBTransactionException("Could not create temporary file.", e);
}
   }
 
开发者ID:PureSolTechnologies,项目名称:DuctileDB,代码行数:24,代码来源:AddBlobVertexOperation.java

示例11: interceptClose

import com.google.common.io.CountingInputStream; //导入依赖的package包/类
private static void interceptClose(final Stream<?> stream, final CountingInputStream in,
        final long startTime, final Object... args) {
    final Map<String, String> mdc = Logging.getMDC();
    stream.onClose(new Runnable() {

        @Override
        public void run() {
            final Map<String, String> oldMdc = Logging.getMDC();
            try {
                Logging.setMDC(mdc);
                logRead(in, startTime, args);
                // closing the stream should not be done, but GZIPFilter seems not to detect
                // EOF and does not release the underlying stream, causing the connection not
                // to be released
                Util.closeQuietly(in);
            } finally {
                Logging.setMDC(oldMdc);
            }
        }

    });
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:23,代码来源:Serializer.java

示例12: logRead

import com.google.common.io.CountingInputStream; //导入依赖的package包/类
private static void logRead(final CountingInputStream in, final long startTime,
        final Object... args) {
    if (LOGGER.isDebugEnabled()) {
        boolean eof = false;
        try {
            eof = in.read() == -1;
        } catch (final Throwable ex) {
            // ignore
        }
        final long elapsed = System.currentTimeMillis() - startTime;
        final StringBuilder builder = new StringBuilder();
        builder.append("Http: read complete, ");
        for (int i = 0; i < args.length; i += 2) {
            builder.append(args[i]).append(" ").append(args[i + 1]).append(", ");
        }
        builder.append(in.getCount()).append(" byte(s), ");
        if (eof) {
            builder.append("EOF, ");
        }
        builder.append(elapsed).append(" ms");
        LOGGER.debug(builder.toString());
    }
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:24,代码来源:Serializer.java

示例13: ExampleRecordCursor

import com.google.common.io.CountingInputStream; //导入依赖的package包/类
public ExampleRecordCursor(List<ExampleColumnHandle> columnHandles, ByteSource byteSource)
{
    this.columnHandles = columnHandles;

    fieldToColumnIndex = new int[columnHandles.size()];
    for (int i = 0; i < columnHandles.size(); i++) {
        ExampleColumnHandle columnHandle = columnHandles.get(i);
        fieldToColumnIndex[i] = columnHandle.getOrdinalPosition();
    }

    try (CountingInputStream input = new CountingInputStream(byteSource.openStream())) {
        lines = byteSource.asCharSource(UTF_8).readLines().iterator();
        totalBytes = input.getCount();
    }
    catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:19,代码来源:ExampleRecordCursor.java

示例14: testOne

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);
  Codec codec = new CellCodec();
  Codec.Encoder encoder = codec.getEncoder(dos);
  final KeyValue kv =
    new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"), Bytes.toBytes("v"));
  kv.setMvccVersion(Long.MAX_VALUE);
  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 = codec.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(offset, cis.getCount());
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:25,代码来源:TestCellCodec.java

示例15: main

import com.google.common.io.CountingInputStream; //导入依赖的package包/类
public static void main(String[] args) {
    try {
        String fileName = args != null && args.length > 0 ? args[0] : "in.hprof";
        CountingInputStream in = new CountingInputStream(new FileInputStream(fileName));
        ValidatingProcessor processor = new ValidatingProcessor(in);
        HprofReader reader = new HprofReader(in, processor);
        while (reader.hasNext()) {
            reader.next();
        }
        // All data loaded, start to check that it is consistent
        processor.verifyClasses();
        processor.verifyInstances();
    }
    catch (IOException e) {
       System.err.print("Failed to process file");
        e.printStackTrace(System.err);
        throw new RuntimeException(e);
    }
}
 
开发者ID:badoo,项目名称:hprof-tools,代码行数:20,代码来源:HprofValidator.java


注:本文中的com.google.common.io.CountingInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。