org.apache.commons.compress.compressors.xz.XZCompressorInputStream Java Examples

The following examples show how to use org.apache.commons.compress.compressors.xz.XZCompressorInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvroSource.java    From beam with Apache License 2.0 6 votes vote down vote up
/**
 * Decodes a byte array as an InputStream. The byte array may be compressed using some codec.
 * Reads from the returned stream will result in decompressed bytes.
 *
 * <p>This supports the same codecs as Avro's {@link CodecFactory}, namely those defined in
 * {@link DataFileConstants}.
 *
 * <ul>
 *   <li>"snappy" : Google's Snappy compression
 *   <li>"deflate" : deflate compression
 *   <li>"bzip2" : Bzip2 compression
 *   <li>"xz" : xz compression
 *   <li>"null" (the string, not the value): Uncompressed data
 * </ul>
 */
private static InputStream decodeAsInputStream(byte[] data, String codec) throws IOException {
  ByteArrayInputStream byteStream = new ByteArrayInputStream(data);
  switch (codec) {
    case DataFileConstants.SNAPPY_CODEC:
      return new SnappyCompressorInputStream(byteStream, 1 << 16 /* Avro uses 64KB blocks */);
    case DataFileConstants.DEFLATE_CODEC:
      // nowrap == true: Do not expect ZLIB header or checksum, as Avro does not write them.
      Inflater inflater = new Inflater(true);
      return new InflaterInputStream(byteStream, inflater);
    case DataFileConstants.XZ_CODEC:
      return new XZCompressorInputStream(byteStream);
    case DataFileConstants.BZIP2_CODEC:
      return new BZip2CompressorInputStream(byteStream);
    case DataFileConstants.NULL_CODEC:
      return byteStream;
    default:
      throw new IllegalArgumentException("Unsupported codec: " + codec);
  }
}
 
Example #2
Source File: ArtifactsXmlAbsoluteUrlRemoverTest.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void removeAbsoluteUrlFromXz() throws Exception {
  when(artifactsXml.get()).thenReturn(getClass().getResourceAsStream(ARTIFACTS_XML_XZ));
  TempBlob modified = underTest.removeMirrorUrlFromArtifactsXml(artifactsXml, repository, "xml.xz");
  try (XZCompressorInputStream xz = new XZCompressorInputStream(modified.get())) {
    assertXmlMatches(xz, ARTIFACTS_XML_WITHOUT_ABSOLUTE);
  }
  catch (IOException e) {
    fail("Exception not expected. Is this file XZ compressed? " + e.getMessage());
  }
}
 
Example #3
Source File: Tar.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
List<File> uncompressTarXzFile(File inputFile, File outputDir, Consumer<ProgressEntity> stateCallback) {
    try (CountingInputStream countingInputStream = new CountingInputStream(new FileInputStream(inputFile));
            InputStream inputStream = new XZCompressorInputStream(countingInputStream)) {
        final long finalSize = FileUtils.sizeOf(inputFile);
        return uncompress(inputStream, countingInputStream, outputDir, finalSize, stateCallback);
    } catch (IOException e) {
        throw new ArchiveException(TAR_ERROR_MESSAGE, e);
    }
}
 
Example #4
Source File: P4ExtFileUtils.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public static void extractResource(@Nullable ClassLoader cl, @Nullable Object parentObject,
        @Nonnull String resourceLocation, @Nonnull File outputFile, boolean uncompress)
        throws IOException {
    // if (outputFile.exists()) {
    //     throw new IOException("Cannot overwrite existing file: " + outputFile);
    // }
    File parent = outputFile.getParentFile();
    if (parent != null && !parent.exists()) {
        if (!parent.mkdirs()) {
            throw new IOException("Could not create directory " + parent);
        }
    }
    InputStream inp = new BufferedInputStream(getStream(cl, parentObject, resourceLocation));
    if (uncompress) {
        if (resourceLocation.endsWith(".tar.bz2")) {
            extractArchive(new TarArchiveInputStream(new BZip2CompressorInputStream(inp)), outputFile);
            return;
        }
        if (resourceLocation.endsWith(".tar.xz")) {
            extractArchive(new TarArchiveInputStream(new XZCompressorInputStream(inp)), outputFile);
            return;
        }
        if (resourceLocation.endsWith(".tar.gz") || resourceLocation.endsWith(".tgz")) {
            extractArchive(new TarArchiveInputStream(new GzipCompressorInputStream(inp)), outputFile);
            return;
        }
        if (resourceLocation.endsWith(".tar")) {
            extractArchive(new TarArchiveInputStream(inp), outputFile);
            return;
        }
        if (resourceLocation.endsWith(".zip")) {
            extractArchive(new ZipArchiveInputStream(inp), outputFile);
            return;
        }
    }
    extractFile(inp, outputFile);
}
 
Example #5
Source File: XZInputStreamFactory.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public XZCompressorInputStream create(InputStream in) throws IOException {
	return new XZCompressorInputStream(in, true);
}
 
Example #6
Source File: XZInputStreamFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public XZCompressorInputStream create(InputStream in) throws IOException {
	return new XZCompressorInputStream(in, true);
}
 
Example #7
Source File: XZPayloadCoding.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public InputStream createInputStream ( final InputStream in ) throws IOException
{
    return new XZCompressorInputStream ( in );
}
 
Example #8
Source File: XZInputStreamFactory.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public XZCompressorInputStream create(InputStream in) throws IOException {
	return new XZCompressorInputStream(in, true);
}