Examples of ZipArchiveInputStream


Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

  public void testImageXSL() throws Exception {
    Response response = WebClient.create(endPoint + UNPACKER_PATH)
        .accept("application/zip")
        .put(ClassLoader.getSystemResourceAsStream("pic.xls"));

    ZipArchiveInputStream zip = new ZipArchiveInputStream(
        (InputStream) response.getEntity());

    Map<String, String> data = readArchive(zip);
    assertEquals(XSL_IMAGE1_MD5, data.get("0.jpg"));
    assertEquals(XSL_IMAGE2_MD5, data.get("1.jpg"));
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

    Response response = WebClient.create(endPoint + ALL_PATH)
        .header(CONTENT_TYPE, APPLICATION_XML)
        .accept("application/zip")
        .put(ClassLoader.getSystemResourceAsStream("test.doc"));

    String responseMsg = readArchiveText(new ZipArchiveInputStream(
        (InputStream) response.getEntity()));
    assertNotNull(responseMsg);
    assertTrue(responseMsg.contains("test"));
  }
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

     * @param encoding the encoding of the entry names
     */
    public ArchiveInputStream getArchiveStream(InputStream stream,
                                               String encoding)
        throws IOException {
        return new ZipArchiveInputStream(stream, encoding, true);
    }
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

    LOG.info(String.format("Unzipping %s to dir %s.", inputFile
        .getAbsolutePath(), outputDir.getAbsolutePath()));

    final List<File> unzippedFiles = new LinkedList<File>();
    final InputStream is = new FileInputStream(inputFile);
    final ZipArchiveInputStream debInputStream = (ZipArchiveInputStream) new ArchiveStreamFactory()
        .createArchiveInputStream("zip", is);
    ZipArchiveEntry entry = null;
    while ((entry = (ZipArchiveEntry) debInputStream.getNextEntry()) != null) {
      final File outputFile = new File(outputDir, entry.getName());
      if (entry.isDirectory()) {
        LOG.info(String.format(
            "Attempting to write output directory %s.", outputFile
                .getAbsolutePath()));
        if (!outputFile.exists()) {
          LOG.info(String.format(
              "Attempting to create output directory %s.",
              outputFile.getAbsolutePath()));
          if (!outputFile.mkdirs()) {
            throw new IllegalStateException(String.format(
                "Couldn't create directory %s.", outputFile
                    .getAbsolutePath()));
          }
        }
      } else {
        LOG.info(String.format("Creating output file %s.", outputFile
            .getAbsolutePath()));
        File parent = outputFile.getParentFile();
        if (!parent.exists()) {
          LOG
              .info(String
                  .format(
                      "Got a file entry before the parent directory entry."
                          + " Attempting to create the parent directory directory %s.",
                      parent.getAbsolutePath()));
          if (!parent.mkdirs()) {
            throw new IllegalStateException(String.format(
                "Couldn't create directory %s.", parent
                    .getAbsolutePath()));
          }
        }
        outputFile.createNewFile();
        final OutputStream outputFileStream = new FileOutputStream(
            outputFile);
        IOUtils.copy(debInputStream, outputFileStream);
        outputFileStream.close();
      }
      unzippedFiles.add(outputFile);
    }
    debInputStream.close();
    return unzippedFiles;
  }
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

            throws IOException, TikaException, SAXException {
        metadata.set(Metadata.CONTENT_TYPE, "application/zip");

        // At the end we want to close the Zip stream to release any associated
        // resources, but the underlying document stream should not be closed
        ZipArchiveInputStream zip =
            new ZipArchiveInputStream(new CloseShieldInputStream(stream));
        try {
            parseArchive(zip, handler, metadata, context);
        } finally {
            zip.close();
        }
    }
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

        return supportedTypes;
    }

    public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
            throws IOException, SAXException, TikaException {
        ArchiveInputStream zip = new ZipArchiveInputStream(stream);
        ArchiveEntry entry = zip.getNextEntry();
        Parser parser = context.get(Parser.class, EmptyParser.INSTANCE);
        while (entry != null) {
            if (!relevantFileNames.contains(entry.getName())) {
                entry = zip.getNextEntry();
                continue;
            }

            parser.parse(new CloseShieldInputStream(zip), handler, metadata, context);
            entry = zip.getNextEntry();
        }
        zip.close();
    }
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

        } else if (a == 0x1f && b == 0x8b) {
            metadata.set(Metadata.CONTENT_TYPE, "application/x-gzip");
            decompress(new GZIPInputStream(stream), xhtml);
        } else if (a == 'P' && b == 'K') {
            metadata.set(Metadata.CONTENT_TYPE, "application/zip");
            unpack(new ZipArchiveInputStream(stream), xhtml);
        } else if ((a == '0' && b == '7')
                || (a == 0x71 && b == 0xc7)
                || (a == 0xc7 && b == 0x71)) {
            metadata.set(Metadata.CONTENT_TYPE, "application/x-cpio");
            unpack(new CpioArchiveInputStream(stream), xhtml);
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

            return name;
        }
       
        public LineIterator getEntries() throws IOException {
            if(name.endsWith(".zip")){
                ZipArchiveInputStream zipIn = new ZipArchiveInputStream(is);
                zipIn.getNextEntry();
                return IOUtils.lineIterator(zipIn, "UTF-8");
            } else {
                return IOUtils.lineIterator(is, "UTF-8");
            }
        }
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

        return supportedTypes;
    }

    public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
            throws IOException, SAXException, TikaException {
        ZipArchiveInputStream zip = new ZipArchiveInputStream(stream);
        ZipArchiveEntry entry = zip.getNextZipEntry();

        while (entry != null) {
            if (!IWORK_CONTENT_ENTRIES.contains(entry.getName())) {
                entry = zip.getNextZipEntry();
                continue;
            }

            InputStream entryStream = new BufferedInputStream(zip, 4096);
            entryStream.mark(4096);
            IWORKDocumentType type = IWORKDocumentType.detectType(entryStream);
            entryStream.reset();
           
            if(type != null) {
               XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
               ContentHandler contentHandler;
              
               switch(type) {
               case KEYNOTE:
                  contentHandler = new KeynoteContentHandler(xhtml, metadata);
                  break;
               case NUMBERS:
                  contentHandler = new NumbersContentHandler(xhtml, metadata);
                  break;
               case PAGES:
                  contentHandler = new PagesContentHandler(xhtml, metadata);
                  break;
               case ENCRYPTED:
                   // We can't do anything for the file right now
                   contentHandler = null;
                   break;
               default:
                  throw new TikaException("Unhandled iWorks file " + type);
               }

               metadata.add(Metadata.CONTENT_TYPE, type.getType().toString());
               xhtml.startDocument();
               if (contentHandler != null) {
                  context.getSAXParser().parse(
                          new CloseShieldInputStream(entryStream),
                          new OfflineContentHandler(contentHandler)
                  );
               }
               xhtml.endDocument();
            }
           
            entry = zip.getNextZipEntry();
        }
        zip.close();
    }
View Full Code Here

Examples of org.apache.commons.compress.archivers.zip.ZipArchiveInputStream

        extract(new TarArchiveInputStream(new FileInputStream(uncompressedFile)), targetFolder);
        FileUtils.forceDelete(uncompressedFile);
    }

    private void extractZipDistribution(URL sourceDistribution, File targetFolder) throws IOException {
        extract(new ZipArchiveInputStream(sourceDistribution.openStream()), targetFolder);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.