Package java.util.zip

Examples of java.util.zip.Inflater


    if (encoding == null) {
      is = responseBodyStream;
    } else if (encoding.equalsIgnoreCase("gzip")) {
      is = new GZIPInputStream(responseBodyStream);
    } else if (encoding.equalsIgnoreCase("deflate")) {
      Inflater inflater = new Inflater(true);
      is = new InflaterInputStream(responseBodyStream, inflater);
    }

    byte[] body = IOUtils.toByteArray(is);
    return new HttpResponseBuilder()
View Full Code Here


        checkEquality(idat, "IDAT".getBytes());

        byte[] data = read(size);


        Inflater inflater = new Inflater();
        inflater.setInput(data, 0, size);

        int[] colors = new int[3];
        int[] black = new int[] {0, 0, 0};
        int[] white = new int[] {1, 1, 1};

        try {
            switch (mode) {
            case PNGSaver.BW_MODE:
                {
                    int bytes = (int)(width / 8);
                    if((width % 8) != 0) {
                        bytes++;
                    }
                    byte colorset;
                    byte[] row = new byte[bytes];
                    for (int y = 0; y < height; y++) {
                        inflater.inflate(new byte[1]);
                        inflater.inflate(row);
                        for (int x = 0; x < bytes; x++) {
                            colorset = row[x];
                            for (int sh = 0; sh < 8; sh++) {
                                if(x * 8 + sh >= width) {
                                    break;
                                }
                                if((colorset & 0x80) == 0x80) {
                                    setColors(result, x * 8 + sh, y, white);
                                } else {
                                    setColors(result, x * 8 + sh, y, black);
                                }
                                colorset <<= 1;
                            }
                        }
                    }
                }
                break;
            case PNGSaver.GREYSCALE_MODE:
                {
                    byte[] row = new byte[width];
                    for (int y = 0; y < height; y++) {
                        inflater.inflate(new byte[1]);
                        inflater.inflate(row);
                        for (int x = 0; x < width; x++) {
                            colors[0] = row[x];
                            colors[1] = colors[0];
                            colors[2] = colors[0];
                            setColors(result, x, y, colors);
                        }
                    }
                }
                break;
            case PNGSaver.COLOR_MODE:
                {
                    byte[] row = new byte[width * 3];
                    for (int y = 0; y < height; y++) {
                        inflater.inflate(new byte[1]);
                        inflater.inflate(row);
                        for (int x = 0; x < width; x++) {
                            colors[0] = (row[x * 3 + 0]&0xff);
                            colors[1] = (row[x * 3 + 1]&0xff);
                            colors[2] = (row[x * 3 + 2]&0xff);
                            setColors(result, x, y, colors);
View Full Code Here

        compressor.end();
        return bos.toByteArray();
    }

    public static byte[] decompress(byte[] compressedData) throws IOException {
        Inflater inflater = new Inflater();
        inflater.setInput(compressedData);
        ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
        byte[] buf = new byte[1024];
        while (!inflater.finished()) {
            try {
                int count = inflater.inflate(buf);
                bos.write(buf, 0, count);
            } catch (DataFormatException e) {
            }
        }
        bos.close();
        inflater.end();
        return bos.toByteArray();
    }
View Full Code Here

        }
        deflater.end();
    }

    static void decompress(byte[] compressedData, DataOutput out) throws IOException {
        Inflater inflater = new Inflater();
        inflater.setInput(compressedData);
        byte[] buf = new byte[1024];
        while (!inflater.finished()) {
            try {
                int count = inflater.inflate(buf);
                out.write(buf, 0, count);
            } catch (DataFormatException e) {
                throw new IOException(e);
            }
        }
        inflater.end();
    }
View Full Code Here

         super(in);
      }
     
      void refreshInflater()
      {
         inf = new Inflater(true);
         crc.reset();
      }
View Full Code Here

        {
            case ZipEntry.STORED:
                return bis;
            case ZipEntry.DEFLATED:
                bis.addDummy();
                return new InflaterInputStream( bis, new Inflater( true ) )
                {
                    public void close()
                        throws IOException
                    {
                        super.close();
View Full Code Here

    }
    if (fileExists(name + ".tmp1.bin")) {
      if (verifySignature()) {
        try {
          byte[] compressed = readFile(name + ".tmp1.bin");
          Inflater zip = new Inflater();
          zip.setInput(compressed, 4, compressed.length - 0x108);
          int len = ((compressed[0] << 0) & 0x000000FF)
              | ((compressed[1] << 8) & 0x0000FF00)
              | ((compressed[2] << 16) & 0x00FF0000)
              | ((compressed[3] << 24) & 0xFF000000);
          byte[] uncompressed = new byte[len];
          zip.inflate(uncompressed);
          saveFile(name + ".tmp2.bin", uncompressed);
        } catch (Exception e) {
          System.out.println("Failed to inflate .tmp1.bin file: "
              + e.toString());
        }
View Full Code Here

  public static byte[] unpack(byte[] data, int out_size) throws IOException {
    int method = data[0];

    if(method == 2) {
      Inflater i = new Inflater();
      i.setInput(data, 1, data.length-1);

      byte[] out = new byte[out_size];
      try {
        int j = i.inflate(out);
        if(j != out_size)
          throw new IOException("Invalid out size " + j + " expecting " + out_size);
        if(!i.finished())
          throw new IOException("Unfinished");
      } catch (DataFormatException e) {
        throw new IOException(e.getMessage());
      }
      return out;
View Full Code Here

            {
                case GZIP:
                    DataOutputBuffer decompressed = new DataOutputBuffer();
                    byte[] outBuffer = new byte[1024], inBuffer = new byte[1024];

                    Inflater decompressor = new Inflater();

                    int lenRead = 0;
                    while (true)
                    {
                        if (decompressor.needsInput())
                            lenRead = query.remaining() < 1024 ? query.remaining() : 1024;
                            query.get(inBuffer, 0, lenRead);
                            decompressor.setInput(inBuffer, 0, lenRead);

                        int lenWrite = 0;
                        while ((lenWrite = decompressor.inflate(outBuffer)) !=0)
                            decompressed.write(outBuffer, 0, lenWrite);

                        if (decompressor.finished())
                            break;
                    }

                    decompressor.end();

                    queryString = new String(decompressed.getData(), 0, decompressed.size(), "UTF-8");
                    break;
                case NONE:
                    try
View Full Code Here

        switch (ze.getMethod()) {
            case ZipEntry.STORED:
                return bis;
            case ZipEntry.DEFLATED:
                bis.addDummy();
                return new InflaterInputStream(bis, new Inflater(true));
            default:
                throw new ZipException("Found unsupported compression method "
                                       + ze.getMethod());
        }
    }
View Full Code Here

TOP

Related Classes of java.util.zip.Inflater

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.