public class CompressionUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CompressionUtils.Format |
| Modifier and Type | Field and Description |
|---|---|
static long |
COMPRESSED_TEXT_WEIGHT_FACTOR |
| Constructor and Description |
|---|
CompressionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static InputStream |
decompress(InputStream in,
String fileName)
Decompress an input stream from a file, based on the filename.
|
static String |
getGzBaseName(String fname)
Get the file name without the .gz extension
|
static FileUtils.FileCopyResult |
gunzip(com.google.common.io.ByteSource in,
File outFile)
Gunzip from the input stream to the output file
|
static FileUtils.FileCopyResult |
gunzip(com.google.common.io.ByteSource in,
File outFile,
com.google.common.base.Predicate<Throwable> shouldRetry)
A gunzip function to store locally
|
static FileUtils.FileCopyResult |
gunzip(File pulledFile,
File outFile)
gunzip the file to the output file.
|
static FileUtils.FileCopyResult |
gunzip(InputStream in,
File outFile)
Unzips the input stream via a gzip filter.
|
static long |
gunzip(InputStream in,
OutputStream out)
gunzip from the source stream to the destination stream.
|
static long |
gzip(com.google.common.io.ByteSource in,
com.google.common.io.ByteSink out,
com.google.common.base.Predicate<Throwable> shouldRetry) |
static FileUtils.FileCopyResult |
gzip(File inFile,
File outFile)
GZip compress the contents of inFile into outFile
|
static FileUtils.FileCopyResult |
gzip(File inFile,
File outFile,
com.google.common.base.Predicate<Throwable> shouldRetry)
Gzips the input file to the output
|
static long |
gzip(InputStream inputStream,
OutputStream out)
Copy inputStream to out while wrapping out in a GZIPOutputStream
Closes both input and output
|
static GZIPInputStream |
gzipInputStream(InputStream in)
Fixes java bug 7036144 http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7036144 which affects concatenated GZip
|
static boolean |
isGz(String fName)
Checks to see if fName is a valid name for a "*.gz" file
|
static boolean |
isZip(String fName)
Checks to see if fName is a valid name for a "*.zip" file
|
static FileUtils.FileCopyResult |
unzip(com.google.common.io.ByteSource byteSource,
File outDir,
com.google.common.base.Predicate<Throwable> shouldRetry,
boolean cacheLocally)
Unzip the byteSource to the output directory.
|
static FileUtils.FileCopyResult |
unzip(File pulledFile,
File outDir)
Unzip the pulled file to an output directory.
|
static FileUtils.FileCopyResult |
unzip(InputStream in,
File outDir)
Unzip from the input stream to the output directory, using the entry's file name as the file name in the output directory.
|
static void |
validateZipOutputFile(String sourceFilename,
File outFile,
File outDir) |
static long |
zip(File directory,
File outputZipFile)
Zip the contents of directory into the file indicated by outputZipFile.
|
static long |
zip(File directory,
File outputZipFile,
boolean fsync)
Zip the contents of directory into the file indicated by outputZipFile.
|
static long |
zip(File directory,
OutputStream out)
Zips the contents of the input directory to the output stream.
|
public static final long COMPRESSED_TEXT_WEIGHT_FACTOR
public static long zip(File directory, File outputZipFile, boolean fsync) throws IOException
directory - The directory whose contents should be added to the zip in the output stream.outputZipFile - The output file to write the zipped data tofsync - True if the output file should be fsynced to diskIOExceptionpublic static long zip(File directory, File outputZipFile) throws IOException
directory - The directory whose contents should be added to the zip in the output stream.outputZipFile - The output file to write the zipped data toIOExceptionpublic static long zip(File directory, OutputStream out) throws IOException
directory - The directory whose contents should be added to the zip in the output stream.out - The output stream to write the zip data to. Caller is responsible for closing this stream.IOExceptionpublic static FileUtils.FileCopyResult unzip(com.google.common.io.ByteSource byteSource, File outDir, com.google.common.base.Predicate<Throwable> shouldRetry, boolean cacheLocally) throws IOException
byteSource - The ByteSource which supplies the zip dataoutDir - The output directory to put the contents of the zipshouldRetry - A predicate expression to determine if a new InputStream should be acquired from ByteSource
and the copy attempted again. If you want to retry on any exception, use
FileUtils.IS_EXCEPTION.cacheLocally - A boolean flag to indicate if the data should be cached locallyIOExceptionpublic static FileUtils.FileCopyResult unzip(File pulledFile, File outDir) throws IOException
pulledFile - The file to unzipoutDir - The directory to store the contents of the file.IOExceptionpublic static void validateZipOutputFile(String sourceFilename, File outFile, File outDir) throws IOException
IOExceptionpublic static FileUtils.FileCopyResult unzip(InputStream in, File outDir) throws IOException
in - The input stream of the zip data. This stream is closedoutDir - The directory to copy the unzipped data toIOExceptionpublic static FileUtils.FileCopyResult gunzip(File pulledFile, File outFile)
pulledFile - The source of the gz dataoutFile - A target file to put the contentsIOExceptionpublic static FileUtils.FileCopyResult gunzip(InputStream in, File outFile) throws IOException
in - The input stream to run through the gunzip filter. This stream is closedoutFile - The file to output toIOExceptionpublic static GZIPInputStream gzipInputStream(InputStream in) throws IOException
in - The raw input streamIOExceptionwhich should be used instead for streams coming from filespublic static long gunzip(InputStream in, OutputStream out) throws IOException
in - The input stream which is to be decompressed. This stream is closed.out - The output stream to write to. This stream is closedIOExceptionpublic static FileUtils.FileCopyResult gunzip(com.google.common.io.ByteSource in, File outFile, com.google.common.base.Predicate<Throwable> shouldRetry)
in - The factory to produce input streamsoutFile - The file to store the result intoshouldRetry - A predicate to indicate if the Throwable is recoverablepublic static FileUtils.FileCopyResult gunzip(com.google.common.io.ByteSource in, File outFile)
in - The compressed input stream to read fromoutFile - The file to write the uncompressed results topublic static long gzip(InputStream inputStream, OutputStream out) throws IOException
inputStream - The input stream to copy data from. This stream is closedout - The output stream to wrap in a GZIPOutputStream before copying. This stream is closedIOExceptionpublic static FileUtils.FileCopyResult gzip(File inFile, File outFile, com.google.common.base.Predicate<Throwable> shouldRetry)
inFile - The file to gzipoutFile - A target file to copy the uncompressed contents of inFile toshouldRetry - Predicate on a potential throwable to determine if the copy should be attempted again.IOExceptionpublic static long gzip(com.google.common.io.ByteSource in,
com.google.common.io.ByteSink out,
com.google.common.base.Predicate<Throwable> shouldRetry)
public static FileUtils.FileCopyResult gzip(File inFile, File outFile)
inFile - The source of dataoutFile - The destination for compressed dataIOExceptionpublic static boolean isZip(String fName)
fName - The name of the file in questionpublic static boolean isGz(String fName)
fName - The name of the file in questionpublic static String getGzBaseName(String fname)
fname - The name of the gzip fileIAE - if fname is not a valid "*.gz" file namepublic static InputStream decompress(InputStream in, String fileName) throws IOException
IOExceptionCopyright © 2011–2023 The Apache Software Foundation. All rights reserved.