本文整理汇总了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);
}
示例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();
}
}
示例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);
}
示例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);
}