Package org.apache.commons.compress.compressors

Examples of org.apache.commons.compress.compressors.CompressorStreamFactory


  /**
   * Wrap the compressor input stream so that calling close will also close
   * the underlying stream - workaround for CommonsCompress bug (COMPRESS-127).
   */
  private static InputStream closableCompressorInputStream(Type type, final InputStream is) throws CompressorException {
    final InputStream delegee = new CompressorStreamFactory().createCompressorInputStream(type.csfType, is);
    if (!Type.GZIP.equals(type)) {
      return delegee; //compressor bug affects only gzip
    }
    return new InputStream() {
      @Override  public int read() throws IOException { return delegee.read()}
View Full Code Here


      } else {
        // unix: download a tar.gz file with pt.py set with execute permissions
        response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\"");

        OutputStream os = response.getOutputStream();
        CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, os);
        TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
        tos.setAddPaxHeadersForNonAsciiNames(true);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

        // add the Python script
View Full Code Here

    }

    OutputStream cos = os;
    if (!StringUtils.isEmpty(algorithm)) {
      try {
        cos = new CompressorStreamFactory().createCompressorOutputStream(algorithm, os);
      } catch (CompressorException e1) {
        error(e1, repository, "{0} failed to open {1} stream", algorithm);
      }
    }
    boolean success = false;
View Full Code Here

      } else {
        // unix: download a tar.gz file with pt.py set with execute permissions
        response.setHeader("Content-Disposition", "attachment; filename=\"pt.tar.gz\"");

        OutputStream os = response.getOutputStream();
        CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, os);
        TarArchiveOutputStream tos = new TarArchiveOutputStream(cos);
        tos.setAddPaxHeadersForNonAsciiNames(true);
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

        // add the Python script
View Full Code Here

    }

    OutputStream cos = os;
    if (!StringUtils.isEmpty(algorithm)) {
      try {
        cos = new CompressorStreamFactory().createCompressorOutputStream(algorithm, os);
      } catch (CompressorException e1) {
        error(e1, repository, "{0} failed to open {1} stream", algorithm);
      }
    }
    boolean success = false;
View Full Code Here

     * @throws IOException
     */
    public void loadFile(File file, LoaderHandler handler, RDFFormat format, String compression) throws RDFParseException, IOException {
        log.info("loading file {} ...", file);

        CompressorStreamFactory cf = new CompressorStreamFactory();
        cf.setDecompressConcatenated(true);

        // detect the file compression
        String detectedCompression = detectCompression(file);
        if(compression == null) {
            if(detectedCompression != null) {
                log.info("using auto-detected compression ({})", detectedCompression);
                compression = detectedCompression;
            }
        } else {
            if(detectedCompression != null && !compression.equals(detectedCompression)) {
                log.warn("user-specified compression ({}) overrides auto-detected compression ({})", compression, detectedCompression);
            } else {
                log.info("using user-specified compression ({})", compression);
            }
        }


        // detect the file format
        RDFFormat detectedFormat = Rio.getParserFormatForFileName(uncompressedName(file));
        if(format == null) {
            if(detectedFormat != null) {
                log.info("using auto-detected format ({})", detectedFormat.getName());
                format = detectedFormat;
            } else {
                throw new RDFParseException("could not detect input format of file "+ file);
            }
        } else {
            if(detectedFormat != null && !format.equals(detectedFormat)) {
                log.warn("user-specified format ({}) overrides auto-detected format ({})", format.getName(), detectedFormat.getName());
            }
        }

        // create input stream from file and wrap in compressor stream
        InputStream in;
        InputStream fin = new BufferedInputStream(new FileInputStream(file));
        try {
            if(compression != null) {
                if (CompressorStreamFactory.GZIP.equalsIgnoreCase(compression)) {
                    in = new GzipCompressorInputStream(fin,true);
                } else if (CompressorStreamFactory.BZIP2.equalsIgnoreCase(compression)) {
                    in = new BZip2CompressorInputStream(fin, true);
                } else {
                    // does not honour decompressConcatenated
                    in = cf.createCompressorInputStream(compression, fin);
                }
            } else {
                in = cf.createCompressorInputStream(fin);
            }
        } catch (CompressorException ex) {
            log.info("no compression detected, using plain input stream");
            in = fin;
        }
View Full Code Here

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

      CompressorInputStream cis;
      try {
        CompressorStreamFactory factory = new CompressorStreamFactory();
        cis = factory.createCompressorInputStream(stream);
      } catch (CompressorException e) {
        throw new MorphlineRuntimeException("Unable to uncompress document stream", e);
      }

      try {
View Full Code Here

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

      CompressorInputStream cis;
      try {
        CompressorStreamFactory factory = new CompressorStreamFactory();
        cis = factory.createCompressorInputStream(stream);
      } catch (CompressorException e) {
        throw new MorphlineRuntimeException("Unable to uncompress document stream", e);
      }

      try {
View Full Code Here

    if (doBzipCompression) {
      // Wrap with BOS since BZip2CompressorOutputStream calls out.write(int)
      // and does not use the write(byte[]) version. This proved to speed the
      // compression process by 70% !
      out = new BufferedOutputStream(out, 1 << 16);
      out = new CompressorStreamFactory().createCompressorOutputStream("bzip2", out);
    }
    lineFileOut = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"), 1 << 16);
    docMaker = runData.getDocMaker();
  }
View Full Code Here

    return f;
  }
 
  private File rawGzipFile(String ext) throws Exception {
    File f = new File(testDir,"testfile." +  ext);
    OutputStream os = new CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.GZIP, new FileOutputStream(f));
    writeText(os);
    return f;
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.compress.compressors.CompressorStreamFactory

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.