Example usage for org.apache.commons.compress.archivers ArchiveStreamFactory AR

List of usage examples for org.apache.commons.compress.archivers ArchiveStreamFactory AR

Introduction

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

Prototype

String AR

To view the source code for org.apache.commons.compress.archivers ArchiveStreamFactory AR.

Click Source Link

Document

Constant used to identify the AR archive format.

Usage

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  w w  . ja v a  2s .co  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;//from w w w .ja v 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.dataconservancy.packaging.tool.impl.generator.BagItPackageAssembler.java

private void validateArchivingFormat() {
    if (!archivingFormat.equals(ArchiveStreamFactory.CPIO) && !archivingFormat.equals(ArchiveStreamFactory.TAR)
            && !archivingFormat.equals(ArchiveStreamFactory.JAR)
            && !archivingFormat.equals(ArchiveStreamFactory.AR)
            && !archivingFormat.equals(ArchiveStreamFactory.ZIP) && !archivingFormat.equals("exploded")) {
        throw new PackageToolException(PackagingToolReturnInfo.PKG_ASSEMBLER_INVALID_PARAMS,
                String.format(//from  www.  j  av a2s  .co m
                        "Specified archiving format <%s> is not supported. The supported archiving "
                                + "formats are: %s, %s, %s, %s, %s, %s.",
                        archivingFormat, ArchiveStreamFactory.AR, ArchiveStreamFactory.CPIO,
                        ArchiveStreamFactory.JAR, ArchiveStreamFactory.TAR, ArchiveStreamFactory.ZIP,
                        "exploded"));
    }
}

From source file:org.structr.websocket.command.UnarchiveCommand.java

@Override
public void processMessage(WebSocketMessage webSocketData) {

    final Set<String> supportedByArchiveStreamFactory = new HashSet<>(
            Arrays.asList(new String[] { ArchiveStreamFactory.AR, ArchiveStreamFactory.ARJ,
                    ArchiveStreamFactory.CPIO, ArchiveStreamFactory.DUMP, ArchiveStreamFactory.JAR,
                    ArchiveStreamFactory.TAR, ArchiveStreamFactory.ZIP }));

    final SecurityContext securityContext = getWebSocket().getSecurityContext();
    final App app = StructrApp.getInstance(securityContext);

    try {//  ww  w.j  a  v a 2 s  .c om

        final String id = (String) webSocketData.getId();
        final File file;

        try (final Tx tx = app.tx()) {

            file = app.get(File.class, id);

            if (file == null) {
                getWebSocket().send(
                        MessageBuilder.status().code(400).message("File not found: ".concat(id)).build(), true);
                return;
            }

            final String fileExtension = StringUtils.substringAfterLast(file.getName(), ".");
            if (!supportedByArchiveStreamFactory.contains(fileExtension)) {

                getWebSocket().send(MessageBuilder.status().code(400)
                        .message("Unsupported archive format: ".concat(fileExtension)).build(), true);
                return;
            }

            tx.success();
        }

        // no transaction here since this is a bulk command
        unarchive(securityContext, file);

    } catch (Throwable t) {

        t.printStackTrace();

        String msg = t.toString();

        try (final Tx tx = app.tx()) {

            // return error message
            getWebSocket().send(
                    MessageBuilder.status().code(400)
                            .message("Could not unarchive file: ".concat((msg != null) ? msg : "")).build(),
                    true);

            tx.success();

        } catch (FrameworkException ignore) {
        }

    }
}