Package org.apache.commons.compress.archivers

Examples of org.apache.commons.compress.archivers.ArchiveStreamFactory


        final OutputStream out =
            new Pack200CompressorOutputStream(new FileOutputStream(output),
                                              mode);
        try {
            final ArchiveOutputStream os = new ArchiveStreamFactory()
                .createArchiveOutputStream("jar", out);

            os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
            IOUtils.copy(new FileInputStream(file1), os);
            os.closeArchiveEntry();

            os.putArchiveEntry(new ZipArchiveEntry("testdata/test2.xml"));
            IOUtils.copy(new FileInputStream(file2), os);
            os.closeArchiveEntry();

            os.close();
        } finally {
            out.close();
        }

        final InputStream is = new Pack200CompressorInputStream(output);
        try {
            final ArchiveInputStream in = new ArchiveStreamFactory()
                .createArchiveInputStream("jar", is);
            List<String> files = new ArrayList<String>();
            files.add("testdata/test1.xml");
            files.add("testdata/test2.xml");
            checkArchiveContent(in, files);
View Full Code Here


   *
   * @param inStream InputStream
   * @return boolean
   */
  private static boolean isArchive(InputStream inStream) {
    ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
    try {
      streamFactory.createArchiveInputStream(inStream);
      return true;
    } catch (ArchiveException e) {
      logger.info("File is not an archive");
    }
    return false;
View Full Code Here

    public ArchiveFileExtractor(String[] entryTypes) {
        this.entryTypes = entryTypes;
    }

    public List<Image> extractArchive(InputStream inStream) {
        ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
        List<Image> pictures = new ArrayList<Image>();
        try {
            ArchiveInputStream archiveInputStream = streamFactory.createArchiveInputStream(inStream);
            ArchiveEntry entry = null;
            while ((entry = archiveInputStream.getNextEntry()) != null) {
                if (!entry.isDirectory() && isEntryTypeAllowd(entry)) {
                    byte buf[] = IOUtils.toByteArray(archiveInputStream);
                    InputStream inputStream = new ByteArrayInputStream(buf);
View Full Code Here

     *
     * @param inStream InputStream
     * @return boolean
     */
    public boolean isArchive(InputStream inStream) {
        ArchiveStreamFactory streamFactory = new ArchiveStreamFactory();
        try {
            streamFactory.createArchiveInputStream(inStream);
            return true;
        } catch (ArchiveException e) {
            e.printStackTrace();
        }
        return false;
View Full Code Here

        try {
            Pack200Utils.normalize(input, output[1],
                                   new HashMap<String, String>());
            final FileInputStream is = new FileInputStream(output[1]);
            try {
                final ArchiveInputStream in = new ArchiveStreamFactory()
                    .createArchiveInputStream("jar", is);

                ArchiveEntry entry = in.getNextEntry();
                while (entry != null) {
                    File archiveEntry = new File(dir, entry.getName());
View Full Code Here

            }

            Pack200Utils.normalize(output[1]);
            is = new FileInputStream(output[1]);
            try {
                final ArchiveInputStream in = new ArchiveStreamFactory()
                    .createArchiveInputStream("jar", is);

                ArchiveEntry entry = in.getNextEntry();
                while (entry != null) {
                    File archiveEntry = new File(dir, entry.getName());
View Full Code Here

      // Ensure that the stream supports the mark feature
      stream = new BufferedInputStream(stream);

      ArchiveInputStream ais;
      try {
        ArchiveStreamFactory factory = new ArchiveStreamFactory();
        ais = factory.createArchiveInputStream(stream);
      } catch (ArchiveException e) {
        throw new MorphlineRuntimeException("Unable to unpack document stream", e);
      }

      try {
View Full Code Here

      // Ensure that the stream supports the mark feature
      stream = new BufferedInputStream(stream);

      ArchiveInputStream ais;
      try {
        ArchiveStreamFactory factory = new ArchiveStreamFactory();
        ais = factory.createArchiveInputStream(stream);
      } catch (ArchiveException e) {
        throw new MorphlineRuntimeException("Unable to unpack document stream", e);
      }

      try {
View Full Code Here

      writer = SequenceFile.createWriter(fs, conf, sequenceName, Text.class, BytesWritable.class, CompressionType.RECORD);
        String lowerName = archive.toString().toLowerCase();
       
        if(lowerName.endsWith(".tar.gz") || lowerName.endsWith(".tgz"))
        {
          archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream("tar", new GZIPInputStream(new FileInputStream(archive)));
        }
        else if(lowerName.endsWith(".tar.bz") || lowerName.endsWith(".tar.bz2") || lowerName.endsWith(".tbz"))
        {
          FileInputStream is = new FileInputStream(archive);
          is.read(); // read 'B'
          is.read(); // read 'Z'
          archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream("tar", new CBZip2InputStream(is));
        }
        else if(lowerName.endsWith(".tar"))
        {
          archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream("tar", new FileInputStream(archive));
        }
        else if(lowerName.endsWith(".zip"))
        {
          archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream("zip", new FileInputStream(archive));
        }
        else
        {
          throw new RuntimeException("Can't handle archive format for: "+archive);
        }
View Full Code Here

    public void unzipInputFile(File inputZipFile, File unzipDir) throws ActionException {
        LOGGER.debug("Unzipping " + inputZipFile + " into " + unzipDir);
        ArchiveInputStream in = null;
        try {
            final InputStream is = new FileInputStream(inputZipFile);
            in = new ArchiveStreamFactory().createArchiveInputStream("zip", is);
            ZipArchiveEntry entry;
            while( (entry = (ZipArchiveEntry) in.getNextEntry()) != null) {
                File currentFile = new File(unzipDir, entry.getName());
                if(entry.isDirectory()) {
                    LOGGER.info("Unzipping dir  " + entry);
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.archivers.ArchiveStreamFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.