本文整理匯總了Java中org.apache.commons.compress.compressors.CompressorStreamFactory.GZIP屬性的典型用法代碼示例。如果您正苦於以下問題:Java CompressorStreamFactory.GZIP屬性的具體用法?Java CompressorStreamFactory.GZIP怎麽用?Java CompressorStreamFactory.GZIP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.commons.compress.compressors.CompressorStreamFactory
的用法示例。
在下文中一共展示了CompressorStreamFactory.GZIP屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testOpenForGeneratedCompression
@Test
public void testOpenForGeneratedCompression() throws Exception
{
String[] testFormats = new String[]{
CompressorStreamFactory.BZIP2,
CompressorStreamFactory.DEFLATE,
CompressorStreamFactory.GZIP,
// CompressorStreamFactory.LZMA, // CompressorException: Compressor: lzma not found.
// CompressorStreamFactory.PACK200, // Failed to generate compressed file.
// CompressorStreamFactory.SNAPPY_FRAMED, // CompressorException: Compressor: snappy-framed not found.
// CompressorStreamFactory.SNAPPY_RAW, // CompressorException: Compressor: snappy-raw not found.
// CompressorStreamFactory.XZ, // ClassNotFoundException: org.tukaani.xz.FilterOptions
// CompressorStreamFactory.Z, // CompressorException: Compressor: z not found.
};
for (String format : testFormats) {
TaskSource mockTaskSource = new MockTaskSource(format);
FileInput mockInput = new MockFileInput(
getInputStreamAsBuffer(
getCompressorInputStream(format, "sample_1.csv")));
CommonsCompressDecoderPlugin plugin = new CommonsCompressDecoderPlugin();
FileInput archiveFileInput = plugin.open(mockTaskSource, mockInput);
verifyContents(archiveFileInput, "1,foo");
}
}
示例2: afterPropertiesSet
@Override
public void afterPropertiesSet() throws Exception
{
// Compression type is optional, use GZip if in doubt
if (compressionType == null || compressionType.isEmpty())
{
compressionType = CompressorStreamFactory.GZIP;
}
// Real Content Store and MimeTypes must be given
if (compressMimeTypes == null || compressMimeTypes.isEmpty())
{
throw new IllegalArgumentException("'compressMimeTypes' must be given");
}
if (realContentStore == null)
{
throw new IllegalArgumentException("'realContentStore' must be given");
}
if (mimetypeService == null)
{
throw new IllegalArgumentException("'mimetypeService' must be given");
}
}
示例3: getReadableChannel
/**
* {@inheritDoc}
*/
@Override
public synchronized ReadableByteChannel getReadableChannel() throws ContentIOException
{
this.ensureDelegate();
final String mimetype = this.getMimetype();
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;
}
示例4: normalizeFormats
private static String[] normalizeFormats(String... formats) {
if (formats == null || formats.length == 0) {
return formats;
}
for (int i = 0;i < formats.length;i++) {
if (formats[i].equalsIgnoreCase("gzip")) {
formats[i] = CompressorStreamFactory.GZIP;
} else if (formats[i].equalsIgnoreCase("bz2")) {
formats[i] = CompressorStreamFactory.BZIP2;
}
}
return formats;
}
示例5: detectCompression
/**
* Detect the compression format from the filename, or null in case auto-detection failed.
* @param file
* @return
*/
private String detectCompression(File file) {
if(BZip2Utils.isCompressedFilename(file.getName())) {
return CompressorStreamFactory.BZIP2;
} else if(GzipUtils.isCompressedFilename(file.getName())) {
return CompressorStreamFactory.GZIP;
} else if(XZUtils.isCompressedFilename(file.getName())) {
return CompressorStreamFactory.XZ;
} else {
return null;
}
}
示例6: writeToBackingStore
protected void writeToBackingStore()
{
String mimetype = this.getMimetype();
LOGGER.debug("Determined mimetype {} from write into temporary store", mimetype);
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);
}
}
try
{
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.createReader();
final InputStream contentInputStream = reader.getContentInputStream();
FileCopyUtils.copy(contentInputStream, compressedOutputStream);
}
}
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());
}
final String finalContentUrl = this.backingWriter.getContentUrl();
// we don't expect a different content URL, but just to make sure
this.setContentUrl(finalContentUrl);
}
finally
{
this.writtenToBackingWriter = true;
}
}
示例7: CompressorSerializer
public CompressorSerializer(ISerializer<Object> serializer) {
this.serializer=serializer;
this.compressor=new CommonsCompressor(CompressorStreamFactory.GZIP);
}
示例8: CommonsCompress
public CommonsCompress()
{
this.type = CompressorStreamFactory.GZIP;
}
示例9: Tarball
/**
* Constructs a new instance of this class using the TAR constant of
* {@link ArchiveStreamFactory} and the GZIP constant of
* {@link CompressorStreamFactory}.
*/
public Tarball() {
super(ArchiveStreamFactory.TAR, CompressorStreamFactory.GZIP);
}