Example usage for java.util.zip InflaterInputStream InflaterInputStream

List of usage examples for java.util.zip InflaterInputStream InflaterInputStream

Introduction

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

Prototype

public InflaterInputStream(InputStream in) 

Source Link

Document

Creates a new input stream with a default decompressor and buffer size.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    FileInputStream fin = new FileInputStream("a.dat");
    InflaterInputStream iis = new InflaterInputStream(fin);
    FileOutputStream fout = new FileOutputStream("b.dat");
    for (int c = iis.read(); c != -1; c = iis.read()) {
        fout.write(c);//from  www.  ja  v  a  2s  . c  o m
    }
    fout.close();

}

From source file:Main.java

public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
        if (args[i].toLowerCase().endsWith(".dfl")) {
            try {
                FileInputStream fin = new FileInputStream(args[i]);
                InflaterInputStream iis = new InflaterInputStream(fin);
                FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 4));
                for (int c = iis.read(); c != -1; c = iis.read()) {
                    fout.write(c);//w ww . jav a2s . co m
                }
                fout.close();
            } catch (IOException ex) {
                System.err.println(ex);
            }
        } else {
            System.err.println(args[i] + " does not appear to be a deflated file.");
        }
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    double data[] = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6 };
    DataOutputStream fout = new DataOutputStream(new DeflaterOutputStream(new FileOutputStream("data.dat")));
    fout.writeInt(data.length);/*from w ww  .java  2 s  .c  o  m*/

    for (double d : data)
        fout.writeDouble(d);

    DataInputStream fin = new DataInputStream(new InflaterInputStream(new FileInputStream("data.dat")));
    int num = fin.readInt();

    double avg = 0.0;
    double d;

    for (int i = 0; i < num; i++) {
        d = fin.readDouble();
        avg += d;
        System.out.print(d + " ");
    }
    fin.close();
    fout.close();
}

From source file:Main.java

public static byte[] inflate(InputStream in, int bufferSize) throws IOException {
    ByteArrayOutputStream outStream = new ByteArrayOutputStream(bufferSize);

    InflaterInputStream inStream = new InflaterInputStream(in);

    byte[] buf = new byte[4096];
    while (true) {
        int size = inStream.read(buf);
        if (size <= 0)
            break;
        outStream.write(buf, 0, size);/* w  w w.  j  a  v  a2 s  .c o  m*/
    }
    outStream.close();

    return outStream.toByteArray();
}

From source file:org.fejoa.library.messages.ZipEnvelope.java

static public InputStream unzipStream(JSONObject header, InputStream inputStream)
        throws IOException, JSONException {
    // verify/*from   ww w .ja  v  a2 s  .c o  m*/
    if (!header.getString(ZIP_FORMAT_KEY).equals(ZIP_FORMAT))
        throw new IOException("Unsupported zip format: " + header.getString(ZIP_FORMAT_KEY));

    return new InflaterInputStream(inputStream);
}

From source file:Main.java

public static byte[] zlibDecompress(InputStream is) {
    if (null == is)
        return null;
    InflaterInputStream iis = new InflaterInputStream(is);
    ByteArrayOutputStream o = new ByteArrayOutputStream(1024);
    try {/*  ww  w . j  ava 2  s .c  o  m*/
        int i = 1024;
        byte[] buf = new byte[i];

        while ((i = iis.read(buf, 0, i)) > 0) {
            o.write(buf, 0, i);
        }

    } catch (IOException e) {
        e.printStackTrace();
    }
    return o.toByteArray();
}

From source file:zipB64.java

protected static String decodeMessage(String encodedMessage) {
    try {/*from  w w w.ja v  a2 s  .co  m*/
        Base64 b = new Base64();
        byte[] decodedBase64 = b.decode(encodedMessage.getBytes());

        // Decompress the bytes

        ByteArrayInputStream bytesIn = new ByteArrayInputStream(decodedBase64);
        InflaterInputStream inflater = new InflaterInputStream(bytesIn);

        int nbRead = 0;
        StringBuilder sb = new StringBuilder();
        while (nbRead >= 0) {
            byte[] result = new byte[500];
            nbRead = inflater.read(result, 0, result.length);
            if (nbRead > 0) {
                sb.append(new String(result, 0, nbRead, "UTF-8"));
            }
        }
        return sb.toString();
    } catch (Exception e) {
        return "zut";
    }
}

From source file:org.openmrs.module.shr.contenthandler.DataUtil.java

public static byte[] uncompressZLib(byte[] content) throws IOException {
    InflaterInputStream deflateIn = new InflaterInputStream(new ByteArrayInputStream(content));
    return copyToByteArray(deflateIn);
}

From source file:org.projectnyx.network.mcpe.mcpe.BatchPacket.java

@Override
@SneakyThrows({ IOException.class })
public void read() {
    byte[] deflated = readBytes(readInt());
    data = IOUtils.toByteArray(new InflaterInputStream(new ByteArrayInputStream(data)));
}

From source file:com.machinepublishers.jbrowserdriver.ResponseHandler.java

static InputStream handleResponse(StreamConnection conn, InputStream inputStream) throws IOException {
    String url = conn.getURL().toExternalForm();
    byte[] bytes = new byte[0];
    try {// w w  w.j  av a2 s . c  om
        if ("gzip".equalsIgnoreCase(conn.getContentEncoding())) {
            bytes = Util.toBytes(new GZIPInputStream(inputStream));
        } else if ("deflate".equalsIgnoreCase(conn.getContentEncoding())) {
            bytes = Util.toBytes(new InflaterInputStream(inputStream));
        } else {
            bytes = Util.toBytes(inputStream);
        }
        conn.removeContentEncoding();
        conn.setContentLength(bytes.length);

        Settings settings = SettingsManager.settings();
        if (settings != null) {
            String disposition = conn.getHeaderField("Content-Disposition");

            if (settings.saveAttachments() && disposition != null
                    && StatusMonitor.instance().isPrimaryDocument(true, url)) {
                writeContentToDisk(bytes, StreamConnection.attachmentsDir(), url, conn.getContentTypeRaw(),
                        disposition);
            }

            if (settings.saveMedia() && ((StreamConnection) conn).isMedia()) {
                writeContentToDisk(bytes, StreamConnection.mediaDir(), url, conn.getContentTypeRaw(),
                        disposition);
            }
        }
        byte[] newContent = getBody(conn, bytes, url);
        if (newContent != null) {
            bytes = newContent;
        }
    } catch (Throwable t) {
        LogsServer.instance().exception(t);
    } finally {
        Util.close(inputStream);
    }
    conn.setContentLength(bytes.length);
    return new ByteArrayInputStream(bytes);
}