Giter Site home page Giter Site logo

jarchivelib's Introduction

jarchivelib

Build Status

A simple archiving and compression library for Java that provides a thin and easy-to-use API layer on top of the powerful and feature-rich org.apache.commons.compress.

Usage

Using the ArchiverFactory

Create a new Archiver to handle zip archives

Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.ZIP);

Create a new Archiver to handle tar archives with gzip compression

Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);

Alternatively you can use string representations of the archive and compression types.

Archiver archiver = ArchiverFactory.createArchiver("zip");

The ArchiveFactory can also detect archive types based on file extensions and hand you the correct Archiver. This example returns an Archiver instance that handles tar.gz files. (It would also recognize the .tgz extension)

Archiver archiver = ArchiveFactory.createArchiver(new File("archive.tar.gz"));

Using Archivers

Extract

To extract the zip archive /home/jack/archive.zip to /home/jack/archive:

File archive = new File("/home/jack/archive.zip");
File destination = new File("/home/jack/archive");

Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.ZIP);
archiver.extract(archive, destination);

Create

To create a new tar archive with gzip compression archive.tar.gz in /home/jack/ containing the entire directory /home/jack/archive

String archiveName = "archive";
File destination = new File("/home/jack");
File source = new File("/home/jack/archive");

Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);
File archive = archiver.create(archiveName, destination, source);

notice that you can omit the filename extension in the archive name, as it will be appended by the archiver automatically if it is missing.

Stream

To access the contents of an archive as a Stream, rather than extracting them directly onto the filesystem

ArchiveStream stream = archiver.stream(archive);
ArchiveEntry entry;

while((entry = stream.getNextEntry()) != null) {
    // access each archive entry individually using the stream
    // or extract it using entry.extract(destination)
    // or fetch meta-data using entry.getName(), entry.isDirectory(), ...
}
stream.close();

Dependencies

  • commons-compress(tm) 1.8

Compatibility

  • Java 6 and 7
  • Currently only tested for *nix file systems.

OSGi

jarchivelib compiles to a bundle and is OSGi compatible

Known limitations

  • Permissions are not stored when creating archives
  • There is no support for Windows permissions
  • JAR files are treated like streamed zip files and can not restore permissions

jarchivelib's People

Contributors

benson-basis avatar thrau avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.