Java Utililty Methods Gunzip File

List of utility methods to do Gunzip File

Description

The list of methods to do Gunzip File are organized into topic(s).

Method

Filegunzip(File gzippedFile)
Unzips a file.
OutputStream out = null;
GZIPInputStream gzipInputStream = null;
File gunzippedFile = new File(System.getProperty("java.io.tmpdir") + File.separatorChar
        + gzippedFile.getName().replace(".gz", ""));
try {
    InputStream in = new FileInputStream(gzippedFile);
    gzipInputStream = new GZIPInputStream(in);
    out = new FileOutputStream(gunzippedFile);
...
voidgunzip(File gzippedFile, File destinationFile)
Uncompress gzipped files
int buffer = 2048;
FileInputStream in = new FileInputStream(gzippedFile);
GZIPInputStream zipin = new GZIPInputStream(in);
byte[] data = new byte[buffer];
FileOutputStream out = new FileOutputStream(destinationFile);
try {
    int length;
    while ((length = zipin.read(data, 0, buffer)) != -1)
...
voidgUnzip(File srcFile, File destFile)
GUnzips a source File to a destination File.
FileOutputStream fos = null;
GZIPInputStream zIn = null;
InputStream fis = null;
try {
    fos = new FileOutputStream(destFile);
    fis = new FileInputStream(srcFile);
    zIn = new GZIPInputStream(fis);
    copy(zIn, fos);
...
voidgunzip(InputStream packedData, OutputStream unpackedData)
gunzip
copy(new GZIPInputStream(packedData), unpackedData);
Stringgunzip(String compressedStr)
gunzip
if (compressedStr == null) {
    return null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = null;
GZIPInputStream ginzip = null;
byte[] compressed = null;
String decompressed = null;
...
voidgunzip(String inFile, String outFile)
gunzip
byte[] buffer = new byte[1024];
try {
    System.out.println("Gunzip...");
    GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(inFile));
    FileOutputStream out = new FileOutputStream(outFile);
    int len;
    while ((len = gzis.read(buffer)) > 0) {
        out.write(buffer, 0, len);
...
voidgunzipFile(File baseDir, File gzFile)
gunzip File
System.out.println("gunzip'ing File: " + gzFile.toString());
Process p = Runtime.getRuntime().exec(String.format("gunzip %s", gzFile.getAbsolutePath()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
System.out.println("Here is the standard error of the command (if any):\n");
String s;
while ((s = stdError.readLine()) != null) {
    System.out.println(s);
stdError.close();
intgunzipFile(File file_input, File dir_output)
Gunzip an input file.
GZIPInputStream gzip_in_stream;
try {
    FileInputStream in = new FileInputStream(file_input);
    BufferedInputStream source = new BufferedInputStream(in);
    gzip_in_stream = new GZIPInputStream(source);
} catch (IOException e) {
    System.out.println("Error in gunzipFile(): " + e.toString());
    return 0;
...
voidgunzipFile(File inputGZippedFile, File outputFile)
Gunzips one file from the inputGZippedFile and unzips to outputUnZippedFile
java.util.zip.GZIPInputStream input = new java.util.zip.GZIPInputStream(
        new java.io.FileInputStream(inputGZippedFile));
java.io.FileOutputStream output = new java.io.FileOutputStream(outputFile);
int buffersize = 100;
byte[] buf = new byte[buffersize];
int read = input.read(buf, 0, buffersize);
while (read != -1) {
    output.write(buf, 0, read);
...
Stringungzip(byte[] bytes)
ungzip
InputStreamReader isr = new InputStreamReader(new GZIPInputStream(new ByteArrayInputStream(bytes)),
        StandardCharsets.UTF_8);
StringWriter sw = new StringWriter();
char[] chars = new char[1024];
for (int len; (len = isr.read(chars)) > 0;) {
    sw.write(chars, 0, len);
return sw.toString();
...