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

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

Introduction

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

Prototype

public void setHeaderId(ZipShort headerId) 

Source Link

Document

Set the header id.

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.
 * //from ww  w  . j  a  v  a 2  s.com
 * @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);
}