Example usage for org.apache.commons.compress.archivers.zip ZipShort ZipShort

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

Introduction

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

Prototype

public ZipShort(byte[] bytes) 

Source Link

Document

Create instance from bytes.

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.
 * //ww w  . ja  v a 2s  .  c om
 * @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);
}

From source file:org.apache.ant.compress.taskdefs.ArchiveBase.java

/**
 * Extracts flags from a resource./*w w w .  j a v a  2  s  .  c om*/
 *
 * <p>ZipExceptions are only here for the code that translates
 * Ant's ZipExtraFields to CC ZipExtraFields and should never
 * actually be thrown.</p>
 */
protected ResourceFlags getFlags(Resource r) throws ZipException {
    if (r instanceof ArchiveResource) {
        if (r instanceof CommonsCompressArchiveResource) {
            if (r instanceof TarResource) {
                TarResource tr = (TarResource) r;
                return new ResourceFlags(tr.getMode(), tr.getUid(), tr.getGid(), tr.getUserName(),
                        tr.getGroup());
            } else if (r instanceof ZipResource) {
                ZipResource zr = (ZipResource) r;
                return new ResourceFlags(zr.getMode(), zr.getExtraFields(), zr.getMethod());
            } else {
                CommonsCompressArchiveResource cr = (CommonsCompressArchiveResource) r;
                return new ResourceFlags(cr.getMode(), cr.getUid(), cr.getGid());
            }
        } else if (r instanceof org.apache.tools.ant.types.resources.TarResource) {
            org.apache.tools.ant.types.resources.TarResource tr = (org.apache.tools.ant.types.resources.TarResource) r;
            return new ResourceFlags(tr.getMode(), tr.getUid(), tr.getGid(), tr.getUserName(), tr.getGroup());
        } else if (r instanceof org.apache.tools.ant.types.resources.ZipResource) {
            org.apache.tools.ant.types.resources.ZipResource zr = (org.apache.tools.ant.types.resources.ZipResource) r;

            org.apache.tools.zip.ZipExtraField[] extra = zr.getExtraFields();
            ZipExtraField[] ex = new ZipExtraField[extra == null ? 0 : extra.length];
            if (extra != null && extra.length > 0) {
                for (int i = 0; i < extra.length; i++) {
                    try {
                        ex[i] = ExtraFieldUtils
                                .createExtraField(new ZipShort(extra[i].getHeaderId().getValue()));
                    } catch (InstantiationException e) {
                        throw new BuildException(e);
                    } catch (IllegalAccessException e) {
                        throw new BuildException(e);
                    }
                    byte[] b = extra[i].getCentralDirectoryData();
                    ex[i].parseFromCentralDirectoryData(b, 0, b.length);
                    b = extra[i].getLocalFileDataData();
                    ex[i].parseFromLocalFileData(b, 0, b.length);
                }
            }

            return new ResourceFlags(zr.getMode(), ex, zr.getMethod());
        } else {
            ArchiveResource ar = (ArchiveResource) r;
            return new ResourceFlags(ar.getMode());
        }
    }
    return new ResourceFlags();
}

From source file:org.apache.james.mailbox.backup.LongExtraField.java

@Override
public ZipShort getLocalFileDataLength() {
    return new ZipShort(Long.BYTES);
}

From source file:org.callimachusproject.io.ContentTypeExtraField.java

public ZipShort getLocalFileDataLength() {
    return new ZipShort(data.length);
}