Example usage for org.apache.commons.compress.archivers.ar ArArchiveEntry ArArchiveEntry

List of usage examples for org.apache.commons.compress.archivers.ar ArArchiveEntry ArArchiveEntry

Introduction

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

Prototype

public ArArchiveEntry(File inputFile, String entryName) 

Source Link

Document

Create a new instance using the attributes of the given file

Usage

From source file:debrepo.teamcity.archive.ArStreamerTest.java

@Test
public void getThing() {
    ArArchiveEntry e = new ArArchiveEntry(new File("src/test/resources/build-essential_11.6ubuntu6_amd64.deb"),
            "control.tar.gz");
    System.out.println(e.getLength());
}

From source file:com.espringtran.compressor4j.processor.ArProcessor.java

/**
 * Compress data//w  ww. j a va  2 s .c om
 * 
 * @param fileCompressor
 *            FileCompressor object
 * @return
 * @throws Exception
 */
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ArArchiveOutputStream aos = new ArArchiveOutputStream(baos);
    try {
        for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) {
            ArArchiveEntry entry = new ArArchiveEntry(binaryFile.getDesPath(), binaryFile.getActualSize());
            aos.putArchiveEntry(entry);
            aos.write(binaryFile.getData());
            aos.closeArchiveEntry();
        }
        aos.flush();
        aos.finish();
    } catch (Exception e) {
        FileCompressor.LOGGER.error("Error on compress data", e);
    } finally {
        aos.close();
        baos.close();
    }
    return baos.toByteArray();
}

From source file:com.kloudtek.buildmagic.tools.createinstaller.deb.CreateDebTask.java

@Override
public void execute() throws BuildException {
    try {//w w w . jav  a  2  s .  c  om
        prepare();
        final ArArchiveOutputStream debFile = new ArArchiveOutputStream(new FileOutputStream(destfile));
        // create debian-binary
        debFile.putArchiveEntry(new ArArchiveEntry("debian-binary", DEBVERSION.length));
        debFile.write(DEBVERSION);
        debFile.closeArchiveEntry();
        // create control.tar.gz
        DataBuffer controlFile = createControlArchive();
        ArchiveHelper.write(debFile, controlFile, "control.tar.gz");
        controlFile.clear();
        // create data.tar.gz
        DataBuffer dataArchive = createDataArchive();
        ArchiveHelper.write(debFile, dataArchive, "data.tar.gz");
        dataArchive.clear();
        debFile.close();
        log("Created " + destfile.getPath());
    } catch (RuntimeException e) {
        throw new BuildException(e);
    } catch (IOException e) {
        throw new BuildException(e);
    } finally {
        dataBufferManager.clear();
    }
}

From source file:com.github.wolfposd.jdpkg.deb.DpkgDeb.java

public static void writeDebFile(File destination, File[] inputsfiles) throws ArchiveException, IOException {
    ArchiveOutputStream archive = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.AR,
            new FileOutputStream(destination));

    for (File file : inputsfiles) {
        ArArchiveEntry entry = new ArArchiveEntry(file, file.getName());
        archive.putArchiveEntry(entry);//from   w  ww .j a  va 2  s. c  o  m

        BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(input, archive);
        input.close();

        archive.closeArchiveEntry();
    }
    archive.finish();
    archive.close();

}

From source file:org.dataconservancy.packaging.tool.impl.generator.BagItPackageAssembler.java

private void addFilesToArchive(ArchiveOutputStream taos, File file) throws IOException {
    // Create an entry for the file
    //taos.putArchiveEntry(new TarArchiveEntry(file, file.getParentFile().toURI().relativize(file.toURI()).toString()));
    switch (archivingFormat) {
    case ArchiveStreamFactory.TAR:
        taos.putArchiveEntry(new TarArchiveEntry(file, FilenameUtils.separatorsToUnix(
                Paths.get(packageLocationDir.getPath()).relativize(Paths.get(file.getPath())).toString())));
        break;// w w  w .j av  a  2 s . c o  m
    case ArchiveStreamFactory.ZIP:
        taos.putArchiveEntry(new ZipArchiveEntry(file, FilenameUtils.separatorsToUnix(
                Paths.get(packageLocationDir.getPath()).relativize(Paths.get(file.getPath())).toString())));
        break;
    case ArchiveStreamFactory.JAR:
        taos.putArchiveEntry(new JarArchiveEntry(new ZipArchiveEntry(file, FilenameUtils.separatorsToUnix(
                Paths.get(packageLocationDir.getPath()).relativize(Paths.get(file.getPath())).toString()))));
        break;
    case ArchiveStreamFactory.AR:
        taos.putArchiveEntry(new ArArchiveEntry(file, FilenameUtils.separatorsToUnix(
                Paths.get(packageLocationDir.getPath()).relativize(Paths.get(file.getPath())).toString())));
        break;
    case ArchiveStreamFactory.CPIO:
        taos.putArchiveEntry(new CpioArchiveEntry(file, FilenameUtils.separatorsToUnix(
                Paths.get(packageLocationDir.getPath()).relativize(Paths.get(file.getPath())).toString())));
        break;
    }
    if (file.isFile()) {
        // Add the file to the archive
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        IOUtils.copy(bis, taos);
        taos.closeArchiveEntry();
        bis.close();
    } else if (file.isDirectory()) {
        // close the archive entry
        taos.closeArchiveEntry();
        // go through all the files in the directory and using recursion, add them to the archive
        for (File childFile : file.listFiles()) {
            addFilesToArchive(taos, childFile);
        }
    }
}

From source file:org.eclipse.packagedrone.utils.deb.build.DebianPackageWriter.java

public DebianPackageWriter(final OutputStream stream, final BinaryPackageControlFile packageControlFile)
        throws IOException {
    this.packageControlFile = packageControlFile;
    BinaryPackageControlFile.validate(packageControlFile);

    this.ar = new ArArchiveOutputStream(stream);

    this.ar.putArchiveEntry(new ArArchiveEntry("debian-binary", this.binaryHeader.length));
    this.ar.write(this.binaryHeader);
    this.ar.closeArchiveEntry();

    this.dataTemp = File.createTempFile("data", null);

    this.dataStream = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(this.dataTemp)));
    this.dataStream.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
}

From source file:org.eclipse.packagedrone.utils.deb.build.DebianPackageWriter.java

private void addArFile(final File file, final String entryName) throws IOException {
    final ArArchiveEntry entry = new ArArchiveEntry(entryName, file.length());
    this.ar.putArchiveEntry(entry);

    IOUtils.copy(new FileInputStream(file), this.ar);

    this.ar.closeArchiveEntry();
}

From source file:org.vafer.jdeb.ar.ArOutputStreamTestCase.java

public void testWrite() throws Exception {
    final File out1 = File.createTempFile("jdeb", ".ar");

    final ArArchiveOutputStream os = new ArArchiveOutputStream(new FileOutputStream(out1));
    os.putArchiveEntry(new ArArchiveEntry("data", 4));
    os.write("data".getBytes());
    os.closeArchiveEntry();/*from w ww  . ja  va2 s  .  c o  m*/
    os.close();

    assertTrue(out1.delete());
}

From source file:org.vafer.jdeb.DebMaker.java

private void addTo(ArArchiveOutputStream pOutput, String pName, String pContent) throws IOException {
    final byte[] content = pContent.getBytes();
    pOutput.putArchiveEntry(new ArArchiveEntry(pName, content.length));
    pOutput.write(content);//w ww.  j  a  v  a2 s.c  om
    pOutput.closeArchiveEntry();
}

From source file:org.vafer.jdeb.DebMaker.java

private void addTo(ArArchiveOutputStream pOutput, String pName, File pContent) throws IOException {
    pOutput.putArchiveEntry(new ArArchiveEntry(pName, pContent.length()));

    final InputStream input = new FileInputStream(pContent);
    try {/*from  www . ja  v  a2 s . c  o m*/
        Utils.copy(input, pOutput);
    } finally {
        input.close();
    }

    pOutput.closeArchiveEntry();
}