@Override public void feed(long offset, long size, DataSink sink) throws IOException { checkChunkValid(offset, size); // checkChunkValid combined with the way instances of this class are constructed ensures // that mSliceOffset + offset does not overflow and that it's fine to cast size to int. sink.consume(mArray, (int) (mSliceOffset + offset), (int) size); }
@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)); }
@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); }
@Override public void consume(byte[] buf, int offset, int length) throws IOException { checkNotClosed(); mInflater.setInput(buf, offset, length); if (mOutputBuffer == null) { mOutputBuffer = new byte[65536]; } while (!mInflater.finished()) { int outputChunkSize; try { outputChunkSize = mInflater.inflate(mOutputBuffer); } catch (DataFormatException e) { throw new IOException("Failed to inflate data", e); } if (outputChunkSize == 0) { return; } mDelegate.consume(mOutputBuffer, 0, outputChunkSize); mOutputByteCount += outputChunkSize; } }
@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; } }
/** * 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; }
signerEngine.outputJarEntry(entryName); if (inspectEntryRequest != null) { inspectEntryRequest.getDataSink().consume( uncompressedData, 0, uncompressedData.length); inspectEntryRequest.done(); if (outputApkSigingBlockRequest != null) { byte[] outputApkSigningBlock = outputApkSigingBlockRequest.getApkSigningBlock(); outputApkOut.consume(outputApkSigningBlock, 0, outputApkSigningBlock.length); ZipUtils.setZipEocdCentralDirectoryOffset( outputEocd, outputCentralDirStartOffset + outputApkSigningBlock.length); outputApkOut.consume(outputEocd); signerEngine.outputDone();