List of usage examples for java.util.zip Inflater setInput
public void setInput(byte[] input, int off, int len)
From source file:com.simiacryptus.text.CompressionUtil.java
/** * Decode lz byte [ ]./*from www .j a va2s . c om*/ * * @param data the data * @param dictionary the dictionary * @return the byte [ ] */ public static byte[] decodeLZ(byte[] data, String dictionary) { try { Inflater decompresser = new Inflater(); decompresser.setInput(data, 0, data.length); byte[] result = new byte[data.length * 32]; int resultLength = 0; if (!dictionary.isEmpty()) { resultLength = decompresser.inflate(result); assert (0 == resultLength); if (decompresser.needsDictionary()) { byte[] bytes = dictionary.getBytes("UTF-8"); decompresser.setDictionary(bytes); } } resultLength = decompresser.inflate(result); decompresser.end(); return Arrays.copyOfRange(result, 0, resultLength); } catch (DataFormatException | UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:com.bigdata.dastor.utils.FBUtilities.java
public static byte[] decompress(byte[] compressedData, int off, int len) throws IOException, DataFormatException { // Create the decompressor and give it the data to compress Inflater decompressor = new Inflater(); decompressor.setInput(compressedData, off, len); // Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length); // Decompress the data byte[] buf = new byte[1024]; while (!decompressor.finished()) { int count = decompressor.inflate(buf); bos.write(buf, 0, count);// ww w . j ava 2s .c o m } bos.close(); // Get the decompressed data return bos.toByteArray(); }
From source file:r.base.Connections.java
public static byte[] decompress1(byte buffer[]) throws IOException, DataFormatException { DataInputStream in = new DataInputStream(new ByteArrayInputStream(buffer)); int outLength = in.readInt(); Inflater inflater = new Inflater(); inflater.setInput(buffer, 4, buffer.length - 4); byte[] result = new byte[outLength]; inflater.inflate(result);//from ww w . jav a 2s . c o m inflater.end(); return result; }
From source file:org.apache.geode.management.internal.cli.CliUtil.java
public static DeflaterInflaterData uncompressBytes(byte[] output, int compressedDataLength) throws DataFormatException { Inflater decompresser = new Inflater(); decompresser.setInput(output, 0, compressedDataLength); byte[] buffer = new byte[512]; byte[] result = new byte[0]; int bytesRead; while (!decompresser.needsInput()) { bytesRead = decompresser.inflate(buffer); byte[] newResult = new byte[result.length + bytesRead]; System.arraycopy(result, 0, newResult, 0, result.length); System.arraycopy(buffer, 0, newResult, result.length, bytesRead); result = newResult;//ww w. j ava 2s . c o m } decompresser.end(); return new DeflaterInflaterData(result.length, result); }
From source file:acp.sdk.SecureUtil.java
/** * .// w w w . j ava2 s . co m * * @param inputByte * byte[]? * @return ?? * @throws IOException */ public static byte[] inflater(final byte[] inputByte) throws IOException { int compressedDataLength = 0; Inflater compresser = new Inflater(false); compresser.setInput(inputByte, 0, inputByte.length); ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length); byte[] result = new byte[1024]; try { while (!compresser.finished()) { compressedDataLength = compresser.inflate(result); if (compressedDataLength == 0) { break; } o.write(result, 0, compressedDataLength); } } catch (Exception ex) { System.err.println("Data format error!\n"); ex.printStackTrace(); } finally { o.close(); } compresser.end(); return o.toByteArray(); }
From source file:org.apache.pdfbox.filter.FlateFilter.java
private ByteArrayOutputStream decompress(InputStream in) throws IOException, DataFormatException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[2048]; int read = in.read(buf); if (read > 0) { Inflater inflater = new Inflater(); inflater.setInput(buf, 0, read); byte[] res = new byte[2048]; while (true) { int resRead = inflater.inflate(res); if (resRead != 0) { out.write(res, 0, resRead); continue; }//from www .j av a 2s. com if (inflater.finished() || inflater.needsDictionary() || in.available() == 0) { break; } read = in.read(buf); inflater.setInput(buf, 0, read); } } out.close(); return out; }
From source file:com.itude.mobile.android.util.DataUtil.java
public byte[] decompress(byte[] compressed, int bytesToSkip) { Inflater decompressor = new Inflater(); decompressor.setInput(compressed, bytesToSkip, compressed.length - bytesToSkip); // Create an expandable byte array to hold the decompressed data ByteArrayOutputStream bos = new ByteArrayOutputStream(compressed.length); // Decompress the data byte[] buf = new byte[1024]; while (!decompressor.finished()) { try {/*from w ww . j a v a 2s.com*/ int count = decompressor.inflate(buf); bos.write(buf, 0, count); } catch (DataFormatException e) { decompressor.end(); return null; } } decompressor.end(); try { if (bos != null) bos.close(); } catch (IOException e) { MBLog.w(TAG, "Unable to close stream"); } // Get the decompressed data byte[] decompressedData = bos.toByteArray(); return decompressedData; }
From source file:org.eclipsetrader.directa.internal.core.connector.BackfillConnector.java
protected void parseIntradayStream(BufferedInputStream in, List<OHLC> list) throws Exception { Calendar cal = Calendar.getInstance(); int startTime = 9 * 60; int endTime = 17 * 60 + 25; ;//from w ww.j a v a 2 s . c o m byte[] buffer = new byte[1]; while (in.read(buffer) == 1) { if (buffer[0] == '<') { StringBuilder sb = new StringBuilder(); while (in.read(buffer) == 1) { if (buffer[0] == '>') { break; } sb.append(new String(buffer)); } String line = sb.toString(); if (line.startsWith("GRA")) { //$NON-NLS-1$ int s = line.indexOf("L=") + 2; //$NON-NLS-1$ int e = line.indexOf(" ", s); //$NON-NLS-1$ int uncompressLen = Integer.parseInt(line.substring(s, e)); byte[] output = new byte[uncompressLen]; boolean compressed = line.indexOf("LC=") != -1; //$NON-NLS-1$ if (compressed) { s = line.indexOf("LC=") + 3; //$NON-NLS-1$ e = line.indexOf(" ", s); //$NON-NLS-1$ int compressLen = Integer.parseInt(line.substring(s, e)); while (in.read(buffer) == 1) { if (buffer[0] == 0x78) { break; } } if (buffer[0] != 0x78) { break; } int readed = 1, len; byte[] input = new byte[compressLen]; input[0] = buffer[0]; do { len = in.read(input, readed, input.length - readed); readed += len; } while (len > 0 && readed < input.length); Inflater infl = new Inflater(); infl.setInput(input, 0, readed); infl.inflate(output); infl.end(); } else { in.read(buffer); int readed = 0, len; do { len = in.read(output, readed, output.length - readed); readed += len; } while (len > 0 && readed < output.length); } for (int i = 0; i < output.length; i += 28) { Date date = getDate(output, i); cal.setTime(date); int time = cal.get(Calendar.HOUR_OF_DAY) * 60 + cal.get(Calendar.MINUTE); if (time >= startTime && time <= endTime) { float low = getFloat(output, i + 8); float high = getFloat(output, i + 12); float close = getFloat(output, i + 16); float volume = getFloat(output, i + 20); float open = getFloat(output, i + 24); list.add(new OHLC(date, (double) open, (double) high, (double) low, (double) close, (long) volume)); } } } } } }
From source file:PNGDecoder.java
/** * Decodes image from an input stream passed into constructor. * @return a BufferedImage object//ww w . j a v a2 s . c o m * @throws IOException */ public BufferedImage decode() throws IOException { byte[] id = read(12); checkEquality(id, new byte[] { -119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13 }); byte[] ihdr = read(4); checkEquality(ihdr, "IHDR".getBytes()); int width = readInt(); int height = readInt(); BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); byte[] head = read(5); int mode; if (compare(head, new byte[] { 1, 0, 0, 0, 0 })) { mode = PNGEncoder.BW_MODE; } else if (compare(head, new byte[] { 8, 0, 0, 0, 0 })) { mode = PNGEncoder.GREYSCALE_MODE; } else if (compare(head, new byte[] { 8, 2, 0, 0, 0 })) { mode = PNGEncoder.COLOR_MODE; } else { throw (new RuntimeException("Format error")); } readInt();//!!crc int size = readInt(); byte[] idat = read(4); checkEquality(idat, "IDAT".getBytes()); byte[] data = read(size); Inflater inflater = new Inflater(); inflater.setInput(data, 0, size); int color; try { switch (mode) { case PNGEncoder.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) { result.setRGB(x * 8 + sh, y, Color.white.getRGB()); } else { result.setRGB(x * 8 + sh, y, Color.black.getRGB()); } colorset <<= 1; } } } } break; case PNGEncoder.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++) { color = row[x]; result.setRGB(x, y, (color << 16) + (color << 8) + color); } } } break; case PNGEncoder.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++) { result.setRGB(x, y, ((row[x * 3 + 0] & 0xff) << 16) + ((row[x * 3 + 1] & 0xff) << 8) + ((row[x * 3 + 2] & 0xff))); } } } } } catch (DataFormatException e) { throw (new RuntimeException("ZIP error" + e)); } readInt();//!!crc readInt();//0 byte[] iend = read(4); checkEquality(iend, "IEND".getBytes()); readInt();//!!crc in.close(); return (result); }
From source file:de.tudarmstadt.ukp.wikipedia.revisionmachine.difftool.data.codec.RevisionDecoder.java
/** * Inflates the zipped input.//w w w.j av a 2 s . c o m * * @param zipinput * zipped input * @param start * start position * @return inflated input */ private byte[] inflateInput(final byte[] zipinput, final int start) { ByteArrayOutputStream stream; try { byte[] compressedInput = zipinput; Inflater decompresser = new Inflater(); decompresser.setInput(compressedInput, start, compressedInput.length - start); byte[] output = new byte[1000]; stream = new ByteArrayOutputStream(); int cLength; do { cLength = decompresser.inflate(output); stream.write(output, 0, cLength); } while (cLength == 1000); } catch (DataFormatException e) { throw new RuntimeException(e); } return stream.toByteArray(); }