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


Java DataSink类代码示例

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


DataSink类属于com.android.apksig.util包,在下文中一共展示了DataSink类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:27,代码来源:LocalFileRecord.java

示例2: outputUncompressedData

import com.android.apksig.util.DataSink; //导入依赖的package包/类
/**
 * Sends uncompressed data pointed to by the provided ZIP Central Directory (CD) record into the
 * provided data sink.
 */
public static void outputUncompressedData(
        DataSource source,
        CentralDirectoryRecord cdRecord,
        long cdStartOffsetInArchive,
        DataSink sink) throws ZipFormatException, IOException {
    // IMPLEMENTATION NOTE: This method attempts to mimic the behavior of Android platform
    // exhibited when reading an APK for the purposes of verifying its signatures.
    // When verifying an APK, Android doesn't care reading the extra field or the Data
    // Descriptor.
    LocalFileRecord lfhRecord =
            getRecord(
                    source,
                    cdRecord,
                    cdStartOffsetInArchive,
                    false, // don't care about the extra field
                    false // don't read the Data Descriptor
                    );
    lfhRecord.outputUncompressedData(source, sink);
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:24,代码来源:LocalFileRecord.java

示例3: 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;
    }
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:23,代码来源:RandomAccessFileDataSource.java

示例4: ApkSigner

import com.android.apksig.util.DataSink; //导入依赖的package包/类
private ApkSigner(
        List<SignerConfig> signerConfigs,
        Integer minSdkVersion,
        boolean v1SigningEnabled,
        boolean v2SigningEnabled,
        boolean otherSignersSignaturesPreserved,
        String createdBy,
        ApkSignerEngine signerEngine,
        File inputApkFile,
        DataSource inputApkDataSource,
        File outputApkFile,
        DataSink outputApkDataSink,
        DataSource outputApkDataSource) {

    mSignerConfigs = signerConfigs;
    mMinSdkVersion = minSdkVersion;
    mV1SigningEnabled = v1SigningEnabled;
    mV2SigningEnabled = v2SigningEnabled;
    mOtherSignersSignaturesPreserved = otherSignersSignaturesPreserved;
    mCreatedBy = createdBy;

    mSignerEngine = signerEngine;

    mInputApkFile = inputApkFile;
    mInputApkDataSource = inputApkDataSource;

    mOutputApkFile = outputApkFile;
    mOutputApkDataSink = outputApkDataSink;
    mOutputApkDataSource = outputApkDataSource;
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:31,代码来源:ApkSigner.java

示例5: outputInputJarEntryLfhRecordPreservingDataAlignment

import com.android.apksig.util.DataSink; //导入依赖的package包/类
private static long outputInputJarEntryLfhRecordPreservingDataAlignment(
        DataSource inputLfhSection,
        LocalFileRecord inputRecord,
        DataSink outputLfhSection,
        long outputOffset) throws IOException {
    long inputOffset = inputRecord.getStartOffsetInArchive();
    if (inputOffset == outputOffset) {
        // This record's data will be aligned same as in the input APK.
        return inputRecord.outputRecord(inputLfhSection, outputLfhSection);
    }
    int dataAlignmentMultiple = getInputJarEntryDataAlignmentMultiple(inputRecord);
    if ((dataAlignmentMultiple <= 1)
            || ((inputOffset % dataAlignmentMultiple)
                    == (outputOffset % dataAlignmentMultiple))) {
        // This record's data will be aligned same as in the input APK.
        return inputRecord.outputRecord(inputLfhSection, outputLfhSection);
    }

    long inputDataStartOffset = inputOffset + inputRecord.getDataStartOffsetInRecord();
    if ((inputDataStartOffset % dataAlignmentMultiple) != 0) {
        // This record's data is not aligned in the input APK. No need to align it in the
        // output.
        return inputRecord.outputRecord(inputLfhSection, outputLfhSection);
    }

    // This record's data needs to be re-aligned in the output. This is achieved using the
    // record's extra field.
    ByteBuffer aligningExtra =
            createExtraFieldToAlignData(
                    inputRecord.getExtra(),
                    outputOffset + inputRecord.getExtraFieldStartOffsetInsideRecord(),
                    dataAlignmentMultiple);
    return inputRecord.outputRecordWithModifiedExtra(
            inputLfhSection, aligningExtra, outputLfhSection);
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:36,代码来源:ApkSigner.java

示例6: setOutputApk

import com.android.apksig.util.DataSink; //导入依赖的package包/类
/**
 * Sets the sink which will receive the output (signed) APK. Data received by the
 * {@code outputApkOut} sink must be visible through the {@code outputApkIn} data source.
 *
 * <p>This is an advanced variant of {@link #setOutputApk(ReadableDataSink)}, enabling the
 * sink and the source to be different objects.
 *
 * @see #setOutputApk(ReadableDataSink)
 * @see #setOutputApk(File)
 */
public Builder setOutputApk(DataSink outputApkOut, DataSource outputApkIn) {
    if (outputApkOut == null) {
        throw new NullPointerException("outputApkOut == null");
    }
    if (outputApkIn == null) {
        throw new NullPointerException("outputApkIn == null");
    }
    mOutputApkFile = null;
    mOutputApkDataSink = outputApkOut;
    mOutputApkDataSource = outputApkIn;
    return this;
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:23,代码来源:ApkSigner.java

示例7: 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;
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:40,代码来源:LocalFileRecord.java

示例8: 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));
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:8,代码来源:ByteBufferDataSource.java

示例9: 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);
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:8,代码来源:ByteArrayDataSink.java

示例10: 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));
}
 
开发者ID:nukc,项目名称:ApkMultiChannelPlugin,代码行数:8,代码来源:ByteBufferDataSource.java

示例11: getDataSink

import com.android.apksig.util.DataSink; //导入依赖的package包/类
@Override
public DataSink getDataSink() {
    synchronized (mLock) {
        checkNotDone();
        if (mDataSinkBuf == null) {
            mDataSinkBuf = new ByteArrayOutputStream();
        }
        if (mDataSink == null) {
            mDataSink = DataSinks.asDataSink(mDataSinkBuf);
        }
        return mDataSink;
    }
}
 
开发者ID:bihe0832,项目名称:Android-GetAPKInfo,代码行数:14,代码来源:DefaultApkSignerEngine.java


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