Example usage for org.apache.commons.compress.archivers.zip UnrecognizedExtraField setLocalFileDataData

List of usage examples for org.apache.commons.compress.archivers.zip UnrecognizedExtraField setLocalFileDataData

Introduction

In this page you can find the example usage for org.apache.commons.compress.archivers.zip UnrecognizedExtraField setLocalFileDataData.

Prototype

public void setLocalFileDataData(byte[] data) 

Source Link

Document

Set the extra field data in the local file data - without Header-ID or length specifier.

Usage

From source file:cz.muni.fi.xklinec.zipstream.Mallory.java

/**
 * Adds given number of bytes as a null padding to extra field.
 * Minimal padding is 8B. Maximal padding is PAD_BLOCK_MAX.
 * /*www  .j av  a2s . c  o m*/
 * @param ze
 * @param padlen 
 */
public void addExtraPadding(ZipArchiveEntry ze, int padlen) {
    if (padlen < EXTRA_FIELD_SIZE) {
        throw new IllegalArgumentException(
                "Cannot add padding less than 8 B (due to compulsory extra field structure). Given size "
                        + padlen);
    }

    if (padlen > PAD_BLOCK_MAX) {
        throw new IllegalArgumentException(
                "Specified padding is too big, maximal size is " + PAD_BLOCK_MAX + " given size is " + padlen);
    }

    byte[] paddBuff = new byte[padlen - EXTRA_FIELD_SIZE];
    UnrecognizedExtraField zextra = new UnrecognizedExtraField();
    zextra.setHeaderId(new ZipShort(PAD_SIGNATURE));
    zextra.setLocalFileDataData(new byte[0]);
    zextra.setCentralDirectoryData(paddBuff);

    ze.addExtraField(zextra);
}