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


Java ByteStreams.readFully方法代码示例

本文整理汇总了Java中com.google.common.io.ByteStreams.readFully方法的典型用法代码示例。如果您正苦于以下问题:Java ByteStreams.readFully方法的具体用法?Java ByteStreams.readFully怎么用?Java ByteStreams.readFully使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.ByteStreams的用法示例。


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

示例1: fromInputStream

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public static DexBackedDexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is)
        throws IOException {
    if (!is.markSupported()) {
        throw new IllegalArgumentException("InputStream must support mark");
    }
    is.mark(44);
    byte[] partialHeader = new byte[44];
    try {
        ByteStreams.readFully(is, partialHeader);
    } catch (EOFException ex) {
        throw new NotADexFile("File is too short");
    } finally {
        is.reset();
    }

    verifyMagicAndByteOrder(partialHeader, 0);

    byte[] buf = ByteStreams.toByteArray(is);
    return new DexBackedDexFile(opcodes, buf, 0, false);
}
 
开发者ID:CvvT,项目名称:andbg,代码行数:21,代码来源:DexBackedDexFile.java

示例2: loadNext

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public void loadNext() throws IOException {
  recordLength = din.readInt();
  keyPrefix = din.readLong();
  if (recordLength > arr.length) {
    arr = new byte[recordLength];
    baseObject = arr;
  }
  ByteStreams.readFully(in, arr, 0, recordLength);
  numRecordsRemaining--;
  if (numRecordsRemaining == 0) {
    close();
  }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:15,代码来源:UnsafeSorterSpillReader.java

示例3: fromInputStream

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
public static DexBackedOdexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is)
        throws IOException {
    if (!is.markSupported()) {
        throw new IllegalArgumentException("InputStream must support mark");
    }
    is.mark(8);
    byte[] partialHeader = new byte[8];
    try {
        ByteStreams.readFully(is, partialHeader);
    } catch (EOFException ex) {
        throw new NotADexFile("File is too short");
    } finally {
        is.reset();
    }

    verifyMagic(partialHeader);

    is.reset();
    byte[] odexBuf = new byte[OdexHeaderItem.ITEM_SIZE];
    ByteStreams.readFully(is, odexBuf);
    int dexOffset = OdexHeaderItem.getDexOffset(odexBuf);
    if (dexOffset > OdexHeaderItem.ITEM_SIZE) {
        ByteStreams.skipFully(is, dexOffset - OdexHeaderItem.ITEM_SIZE);
    }

    byte[] dexBuf = ByteStreams.toByteArray(is);

    return new DexBackedOdexFile(opcodes, odexBuf, dexBuf);
}
 
开发者ID:CvvT,项目名称:andbg,代码行数:30,代码来源:DexBackedOdexFile.java

示例4: next

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
/**
 * Returns the next {@link Chunk} or throws a {@link NoSuchElementException} if no data is left.
 *
 * <p>Always call {@link #hasNext()} before calling this method.
 *
 * <p>Zero byte inputs are treated special. Instead of throwing a {@link NoSuchElementException}
 * on the first call to {@link #next()}, a {@link Chunk} with an empty {@link ByteString} is
 * returned.
 */
public Chunk next() throws IOException {
  if (!hasNext()) {
    throw new NoSuchElementException();
  }

  maybeInitialize();

  if (digest.getSizeBytes() == 0) {
    data = null;
    return EMPTY_CHUNK;
  }

  // The cast to int is safe, because the return value is capped at chunkSize.
  int bytesToRead = (int) Math.min(bytesLeft(), chunkSize);
  if (bytesToRead == 0) {
    chunkCache = null;
    data = null;
    throw new NoSuchElementException();
  }

  if (chunkCache == null) {
    // Lazily allocate it in order to save memory on small data.
    // 1) bytesToRead < chunkSize: There will only ever be one next() call.
    // 2) bytesToRead == chunkSize: chunkCache will be set to its biggest possible value.
    // 3) bytestoRead > chunkSize: Not possible, due to Math.min above.
    chunkCache = new byte[bytesToRead];
  }

  long offsetBefore = offset;
  try {
    ByteStreams.readFully(data, chunkCache, 0, bytesToRead);
  } catch (EOFException e) {
    throw new IllegalStateException("Reached EOF, but expected "
        + bytesToRead + " bytes.", e);
  }
  offset += bytesToRead;

  ByteString blob = ByteString.copyFrom(chunkCache, 0, bytesToRead);

  if (bytesLeft() == 0) {
    data.close();
    data = null;
    chunkCache = null;
  }

  return new Chunk(digest, blob, offsetBefore);
}
 
开发者ID:bazelbuild,项目名称:bazel-buildfarm,代码行数:57,代码来源:Chunker.java


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