Example usage for java.util.zip GZIPInputStream read

List of usage examples for java.util.zip GZIPInputStream read

Introduction

In this page you can find the example usage for java.util.zip GZIPInputStream read.

Prototype

public int read() throws IOException 

Source Link

Document

Reads a byte of uncompressed data.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    ServerSocket ssock = new ServerSocket(Integer.parseInt(args[0]));
    Socket sock = ssock.accept();
    GZIPInputStream zip = new GZIPInputStream(sock.getInputStream());
    while (true) {
        int c;//  w ww  .  j av  a 2  s. c  om
        c = zip.read();
        if (c == -1)
            break;
        System.out.print((char) c);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("a.gz");
    GZIPInputStream gzin = new GZIPInputStream(fin);
    FileOutputStream fout = new FileOutputStream("a.dat");
    for (int c = gzin.read(); c != -1; c = gzin.read()) {
        fout.write(c);/*from  w ww . j  a va 2 s .co  m*/
    }
    fout.close();
}

From source file:CompRcv.java

public static void main(String[] args) throws Exception {
    ServerSocket ssock = new ServerSocket(Integer.parseInt(args[0]));
    System.out.println("Listening");
    Socket sock = ssock.accept();
    GZIPInputStream zip = new GZIPInputStream(sock.getInputStream());
    while (true) {
        int c;//from w  ww  .j a va2  s  . c o m
        c = zip.read();
        if (c == -1)
            break;
        System.out.print((char) c);
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
        if (args[i].toLowerCase().endsWith(".gz")) {
            try {
                FileInputStream fin = new FileInputStream(args[i]);
                GZIPInputStream gzin = new GZIPInputStream(fin);
                FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 3));
                for (int c = gzin.read(); c != -1; c = gzin.read()) {
                    fout.write(c);// www .  j a va  2 s .  c  o  m
                }
                fout.close();
            } catch (IOException ex) {
                System.err.println(ex);
            }
        } else {
            System.err.println(args[i] + " does not appear to be a gzipped file.");
        }
    }
}

From source file:Main.java

public static byte[] decompressGZIP(byte bytes[]) throws IOException {
    ByteArrayInputStream is = new ByteArrayInputStream(bytes);
    GZIPInputStream gzipis = new GZIPInputStream(is);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    int i;//from   w w  w.  ja  va 2 s  .  c  o m
    while ((i = gzipis.read()) != -1) {
        os.write(i);
    }
    gzipis.close();
    os.close();
    return os.toByteArray();
}

From source file:Main.java

public static byte[] readCompressedData(ByteArrayInputStream bais) {
    int uncompressedLength = getLength(bais);
    byte[] output = new byte[uncompressedLength];
    byte[] compressed = readData(bais);
    GZIPInputStream gs;
    try {//from   ww  w. j a v  a 2 s  . c o  m
        gs = new GZIPInputStream(new ByteArrayInputStream(compressed));
        for (int i = 0; i < uncompressedLength; ++i) {
            output[i] = (byte) gs.read();
        }
    } catch (IOException e) {
        throw new RuntimeException("Cannot decompress", e);
    }

    return output;
}

From source file:net.ulno.jpunch.util.Util.java

public static byte[] unzip(byte[] data) throws IOException {
    InputStream is = new ByteArrayInputStream(data);
    GZIPInputStream gz = new GZIPInputStream(is);
    List<Byte> l = new ArrayList<Byte>();
    while (gz.available() != 0)
        l.add((byte) gz.read());
    // last byte is unnecessary (it is -1)
    byte[] uncmp = new byte[l.size() - 1];
    for (int i = 0; i < l.size() - 1; i++)
        uncmp[i] = l.get(i);// w w  w. j  a  v  a2 s .c o  m
    return uncmp;
}

From source file:com.cloudera.knittingboar.utils.Utils.java

/**
 * Ungzip an input file into an output file.
 * <p>/*  w  ww. jav a2  s  .  c  o m*/
 * The output file is created in the output folder, having the same name as
 * the input file, minus the '.gz' extension.
 * 
 * @param inputFile
 *          the input .gz file
 * @param outputDir
 *          the output directory file.
 * @throws IOException
 * @throws FileNotFoundException
 * 
 * @return The {@File} with the ungzipped content.
 */
private static File unGzip(final File inputFile, final File outputDir)
        throws FileNotFoundException, IOException {

    System.out.println(String.format("Ungzipping %s to dir %s.", inputFile.getAbsolutePath(),
            outputDir.getAbsolutePath()));

    final File outputFile = new File(outputDir,
            inputFile.getName().substring(0, inputFile.getName().length() - 3));

    final GZIPInputStream in = new GZIPInputStream(new FileInputStream(inputFile));
    final FileOutputStream out = new FileOutputStream(outputFile);

    for (int c = in.read(); c != -1; c = in.read()) {
        out.write(c);
    }

    in.close();
    out.close();

    return outputFile;
}

From source file:halive.shootinoutside.common.core.game.map.GameMap.java

public static GameMap createFromByteArray(byte[] b) throws IOException, ParseException {
    ByteArrayInputStream in = new ByteArrayInputStream(b);
    GZIPInputStream input = new GZIPInputStream(in);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int j;//from   w  ww .  j  a  v a  2  s.  c  o  m
    while ((j = input.read()) != -1) {
        out.write(j);
    }
    String s = new String(out.toByteArray());
    return loadGameMapFromJSONString(s);
}

From source file:pro.foundev.GzipCompressionOfColumnExample.java

private static String fromByteBuffer(ByteBuffer byteBuffer) {
    if (byteBuffer == null) {
        return null;
    }//  w ww  .ja  v a 2 s  .c  om
    GZIPInputStream gzipInputStream = null;
    ByteArrayOutputStream baos = null;
    ByteBuffer dup = ByteBuffer.allocate(byteBuffer.limit());
    dup.clear();
    dup.put(byteBuffer);
    dup.flip();

    try {
        gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(dup.array(), 0, dup.limit()));

        baos = new ByteArrayOutputStream();
        for (int value = 0; value != -1;) {
            value = gzipInputStream.read();
            if (value != -1) {
                baos.write(value);
            }
        }
        gzipInputStream.close();
        baos.flush();
        baos.close();
        return new String(baos.toByteArray(), charset);
    } catch (IOException e) {
        throw new RuntimeException("Error decompressing column data", e);
    } finally {
        if (gzipInputStream != null) {
            try {
                gzipInputStream.close();
            } catch (IOException e) {
            }
        }
        if (baos != null) {
            try {
                baos.flush();
                baos.close();
            } catch (IOException e) {
            }
        }
    }
}