Java Code Examples for org.apache.commons.compress.compressors.CompressorStreamFactory#GZIP

The following examples show how to use org.apache.commons.compress.compressors.CompressorStreamFactory#GZIP . 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: ModelExtractor.java    From tensorflow with Apache License 2.0 5 votes vote down vote up
/**
 * Detect the Archive and the Compressor from the file extension
 *
 * @param fileName File name with extension
 * @return Returns a tuple of the detected (Archive, Compressor). Null stands for not available archive or detector.
 * The (null, null) response stands for no Archive or Compressor discovered.
 */
private String[] detectArchiveAndCompressor(String fileName) {

	String normalizedFileName = fileName.trim().toLowerCase();

	if (normalizedFileName.endsWith(".tar.gz")
			|| normalizedFileName.endsWith(".tgz")
			|| normalizedFileName.endsWith(".taz")) {
		return new String[] { ArchiveStreamFactory.TAR, CompressorStreamFactory.GZIP };
	}
	else if (normalizedFileName.endsWith(".tar.bz2")
			|| normalizedFileName.endsWith(".tbz2")
			|| normalizedFileName.endsWith(".tbz")) {
		return new String[] { ArchiveStreamFactory.TAR, CompressorStreamFactory.BZIP2 };
	}
	else if (normalizedFileName.endsWith(".cpgz")) {
		return new String[] { ArchiveStreamFactory.CPIO, CompressorStreamFactory.GZIP };
	}
	else if (hasArchive(normalizedFileName)) {
		return new String[] { findArchive(normalizedFileName).get(), null };
	}
	else if (hasCompressor(normalizedFileName)) {
		return new String[] { null, findCompressor(normalizedFileName).get() };
	}
	else if (normalizedFileName.endsWith(".gzip")) {
		return new String[] { null, CompressorStreamFactory.GZIP };
	}
	else if (normalizedFileName.endsWith(".bz2")
			|| normalizedFileName.endsWith(".bz")) {
		return new String[] { null, CompressorStreamFactory.BZIP2 };
	}

	// No archived/compressed
	return new String[] { null, null };
}
 
Example 2
Source File: DecompressingContentReader.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public synchronized ReadableByteChannel getReadableChannel() throws ContentIOException
{
    this.ensureDelegate();
    final String mimetype = this.getMimetype();

    LOGGER.debug("Determined mimetype {} as provided via setter / content data - mimetypes to compress are {}", mimetype,
            this.mimetypesToCompress);

    final boolean shouldCompress = this.mimetypesToCompress == null || this.mimetypesToCompress.isEmpty()
            || (mimetype != null && (this.mimetypesToCompress.contains(mimetype) || this.isMimetypeToCompressWildcardMatch(mimetype)));

    ReadableByteChannel channel;
    if (shouldCompress)
    {
        LOGGER.debug("Content will be decompressed from backing store (url={})", this.getContentUrl());

        final String compressiongType = this.compressionType != null && !this.compressionType.trim().isEmpty() ? this.compressionType
                : CompressorStreamFactory.GZIP;
        try
        {
            final CompressorInputStream is = COMPRESSOR_STREAM_FACTORY.createCompressorInputStream(compressiongType,
                    this.delegate.getContentInputStream());
            channel = Channels.newChannel(is);
        }
        catch (final CompressorException e)
        {
            LOGGER.error("Failed to open decompressing channel", e);
            throw new ContentIOException("Failed to open channel: " + this, e);
        }
    }
    else
    {
        LOGGER.debug("Content will not be decompressed from backing store (url={})", this.getContentUrl());
        channel = super.getReadableChannel();
    }

    return channel;
}
 
Example 3
Source File: CompressingContentWriter.java    From alfresco-simple-content-stores with Apache License 2.0 4 votes vote down vote up
protected void writeToBackingStore()
{
    String mimetype = this.getMimetype();
    LOGGER.debug("Determined mimetype {} from write into temporary store - mimetypes to compress are {}", mimetype,
            this.mimetypesToCompress);

    if ((this.mimetypesToCompress != null && !this.mimetypesToCompress.isEmpty()) && this.mimetypeService != null
            && (mimetype == null || MimetypeMap.MIMETYPE_BINARY.equals(mimetype)))
    {
        mimetype = this.mimetypeService.guessMimetype(null, this.createReader());
        LOGGER.debug("Determined mimetype {} from MimetypeService.guessMimetype()", mimetype);

        if (mimetype == null || MimetypeMap.MIMETYPE_BINARY.equals(mimetype))
        {
            this.setMimetype(mimetype);
        }
    }

    final boolean shouldCompress = this.mimetypesToCompress == null || this.mimetypesToCompress.isEmpty()
            || (mimetype != null && (this.mimetypesToCompress.contains(mimetype) || this.isMimetypeToCompressWildcardMatch(mimetype)));

    if (shouldCompress)
    {
        LOGGER.debug("Content will be compressed to backing store (url={})", this.getContentUrl());
        final String compressiongType = this.compressionType != null && !this.compressionType.trim().isEmpty() ? this.compressionType
                : CompressorStreamFactory.GZIP;
        try (final OutputStream contentOutputStream = this.backingWriter.getContentOutputStream())
        {
            try (OutputStream compressedOutputStream = COMPRESSOR_STREAM_FACTORY.createCompressorOutputStream(compressiongType,
                    contentOutputStream))
            {
                final ContentReader reader = this.temporaryWriter.getReader();
                final InputStream contentInputStream = reader.getContentInputStream();
                FileCopyUtils.copy(contentInputStream, compressedOutputStream);
                this.properSize = this.temporaryWriter.getSize();
            }
        }
        catch (final IOException | CompressorException ex)
        {
            throw new ContentIOException("Error writing compressed content", ex);
        }
    }
    else
    {
        LOGGER.debug("Content will not be compressed to backing store (url={})", this.getContentUrl());
        this.backingWriter.putContent(this.createReader());
    }

    this.writtenToBackingWriter = true;

    final String finalContentUrl = this.backingWriter.getContentUrl();
    // we don't expect a different content URL, but just to make sure
    this.setContentUrl(finalContentUrl);

    this.cleanupTemporaryContent();
}
 
Example 4
Source File: CompressorSerializer.java    From AutoLoadCache with Apache License 2.0 4 votes vote down vote up
public CompressorSerializer(ISerializer<Object> serializer) {
    this.serializer = serializer;
    this.compressor = new CommonsCompressor(CompressorStreamFactory.GZIP);
}
 
Example 5
Source File: CompressorSerializer.java    From AutoLoadCache with Apache License 2.0 4 votes vote down vote up
public CompressorSerializer(ISerializer<Object> serializer, int compressionThreshold) {
    this.serializer = serializer;
    this.compressionThreshold = compressionThreshold;
    this.compressor = new CommonsCompressor(CompressorStreamFactory.GZIP);
}
 
Example 6
Source File: CommonsCompress.java    From darks-codec with Apache License 2.0 4 votes vote down vote up
public CommonsCompress()
{
    this.type = CompressorStreamFactory.GZIP;
}