本文整理汇总了Java中com.android.apksig.util.DataSink.consume方法的典型用法代码示例。如果您正苦于以下问题:Java DataSink.consume方法的具体用法?Java DataSink.consume怎么用?Java DataSink.consume使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.apksig.util.DataSink
的用法示例。
在下文中一共展示了DataSink.consume方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: outputRecordWithModifiedExtra
import com.android.apksig.util.DataSink; //导入方法依赖的package包/类
/**
* Outputs this record, replacing its extra field with the provided one, and returns returns the
* number of bytes output.
*/
public long outputRecordWithModifiedExtra(
DataSource sourceApk,
ByteBuffer extra,
DataSink output) throws IOException {
long recordStartOffsetInSource = getStartOffsetInArchive();
int extraStartOffsetInRecord = getExtraFieldStartOffsetInsideRecord();
int extraSizeBytes = extra.remaining();
int headerSize = extraStartOffsetInRecord + extraSizeBytes;
ByteBuffer header = ByteBuffer.allocate(headerSize);
header.order(ByteOrder.LITTLE_ENDIAN);
sourceApk.copyTo(recordStartOffsetInSource, extraStartOffsetInRecord, header);
header.put(extra.slice());
header.flip();
ZipUtils.setUnsignedInt16(header, EXTRA_LENGTH_OFFSET, extraSizeBytes);
long outputByteCount = header.remaining();
output.consume(header);
long remainingRecordSize = getSize() - mDataStartOffset;
sourceApk.feed(recordStartOffsetInSource + mDataStartOffset, remainingRecordSize, output);
outputByteCount += remainingRecordSize;
return outputByteCount;
}
示例2: feed
import com.android.apksig.util.DataSink; //导入方法依赖的package包/类
@Override
public void feed(long offset, long size, DataSink sink) throws IOException {
long sourceSize = size();
checkChunkValid(offset, size, sourceSize);
if (size == 0) {
return;
}
long chunkOffsetInFile = mOffset + offset;
long remaining = size;
byte[] buf = new byte[(int) Math.min(remaining, MAX_READ_CHUNK_SIZE)];
while (remaining > 0) {
int chunkSize = (int) Math.min(remaining, buf.length);
synchronized (mFile) {
mFile.seek(chunkOffsetInFile);
mFile.readFully(buf, 0, chunkSize);
}
sink.consume(buf, 0, chunkSize);
chunkOffsetInFile += chunkSize;
remaining -= chunkSize;
}
}
示例3: outputRecordWithDeflateCompressedData
import com.android.apksig.util.DataSink; //导入方法依赖的package包/类
/**
* Outputs the specified Local File Header record with its data and returns the number of bytes
* output.
*/
public static long outputRecordWithDeflateCompressedData(
String name,
int lastModifiedTime,
int lastModifiedDate,
byte[] compressedData,
long crc32,
long uncompressedSize,
DataSink output) throws IOException {
byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8);
int recordSize = HEADER_SIZE_BYTES + nameBytes.length;
ByteBuffer result = ByteBuffer.allocate(recordSize);
result.order(ByteOrder.LITTLE_ENDIAN);
result.putInt(RECORD_SIGNATURE);
ZipUtils.putUnsignedInt16(result, 0x14); // Minimum version needed to extract
result.putShort(ZipUtils.GP_FLAG_EFS); // General purpose flag: UTF-8 encoded name
result.putShort(ZipUtils.COMPRESSION_METHOD_DEFLATED);
ZipUtils.putUnsignedInt16(result, lastModifiedTime);
ZipUtils.putUnsignedInt16(result, lastModifiedDate);
ZipUtils.putUnsignedInt32(result, crc32);
ZipUtils.putUnsignedInt32(result, compressedData.length);
ZipUtils.putUnsignedInt32(result, uncompressedSize);
ZipUtils.putUnsignedInt16(result, nameBytes.length);
ZipUtils.putUnsignedInt16(result, 0); // Extra field length
result.put(nameBytes);
if (result.hasRemaining()) {
throw new RuntimeException("pos: " + result.position() + ", limit: " + result.limit());
}
result.flip();
long outputByteCount = result.remaining();
output.consume(result);
outputByteCount += compressedData.length;
output.consume(compressedData, 0, compressedData.length);
return outputByteCount;
}
示例4: feed
import com.android.apksig.util.DataSink; //导入方法依赖的package包/类
@Override
public void feed(long offset, long size, DataSink sink) throws IOException {
if ((size < 0) || (size > mSize)) {
throw new IndexOutOfBoundsException("size: " + size + ", source size: " + mSize);
}
sink.consume(getByteBuffer(offset, (int) size));
}
示例5: feed
import com.android.apksig.util.DataSink; //导入方法依赖的package包/类
@Override
public void feed(long offset, long size, DataSink sink) throws IOException {
checkChunkValid(offset, size);
// checkChunkValid ensures that it's OK to cast offset and size to int.
sink.consume(mArray, (int) offset, (int) size);
}
示例6: feed
import com.android.apksig.util.DataSink; //导入方法依赖的package包/类
@Override
public void feed(long offset, long size, DataSink sink) throws IOException {
if ((size < 0) || (size > mSize)) {
throw new IllegalArgumentException("size: " + size + ", source size: " + mSize);
}
sink.consume(getByteBuffer(offset, (int) size));
}