Java Code Examples for java.util.zip.Inflater

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project agit, under directory /agit/src/main/java/com/madgag/android/jgit/.

Source file: HarmonyFixInflater.java

  22 
vote

public static boolean checkHarmoniousRepose(){
  Inflater inflater=new Inflater();
  try {
    inflater.setInput(demoDeflatedZeroBytes());
    inflater.inflate(new byte[0],0,0);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
  return inflater.finished();
}
 

Example 2

From project dolphin, under directory /joytyping/src/com/tan/util/.

Source file: Compressor.java

  22 
vote

public int inflate(final byte[] data,final int offset,final int length,final byte[] results){
  Inflater inflater=new Inflater(true);
  inflater.setInput(data,offset,length);
  try {
    return inflater.inflate(results,0,results.length);
  }
 catch (  DataFormatException e) {
    e.printStackTrace();
  }
 finally {
    inflater.end();
  }
  return -1;
}
 

Example 3

From project JGit, under directory /org.spearce.jgit/src/org/spearce/jgit/lib/.

Source file: InflaterCache.java

  22 
vote

private synchronized static Inflater getImpl(){
  if (openInflaterCount > 0) {
    final Inflater r=inflaterCache[--openInflaterCount];
    inflaterCache[openInflaterCount]=null;
    return r;
  }
  return null;
}
 

Example 4

From project LateralGM, under directory /org/lateralgm/file/.

Source file: GmStreamDecoder.java

  22 
vote

public byte[] decompress(int length,int initialCapacity) throws IOException, DataFormatException {
  Inflater decompresser=new Inflater();
  byte[] compressedData=new byte[length];
  read(compressedData,0,length);
  decompresser.setInput(compressedData);
  byte[] result=new byte[131072];
  ByteArrayOutputStream baos=new ByteArrayOutputStream(initialCapacity);
  while (!decompresser.finished()) {
    int len=decompresser.inflate(result);
    baos.write(result,0,len);
  }
  decompresser.end();
  return baos.toByteArray();
}
 

Example 5

From project lesscss-servlet, under directory /src/main/java/com/asual/lesscss/.

Source file: ResourcePackage.java

  22 
vote

private static byte[] inflate(byte[] output) throws DataFormatException, IOException {
  Inflater inflater=new Inflater();
  inflater.setInput(output);
  ByteArrayOutputStream baos=new ByteArrayOutputStream(output.length);
  byte[] buf=new byte[1024];
  while (!inflater.finished()) {
    int count=inflater.inflate(buf);
    baos.write(buf,0,count);
  }
  baos.close();
  return baos.toByteArray();
}
 

Example 6

From project riot, under directory /media/src/org/riotfamily/media/meta/.

Source file: FlashInfo.java

  22 
vote

public byte[] decompress(byte[] bytes) throws DataFormatException {
  int size=readSize(bytes);
  byte[] uncompressed=new byte[size];
  System.arraycopy(bytes,0,uncompressed,0,8);
  Inflater inflater=new Inflater();
  inflater.setInput(bytes,8,bytes.length - 8);
  inflater.inflate(uncompressed,8,size - 8);
  inflater.finished();
  uncompressed[0]=70;
  return uncompressed;
}
 

Example 7

From project Switji, under directory /src/main/java/org/jinglenodes/session/persistence/.

Source file: PersistentCallSessionMapper.java

  22 
vote

public String unzip(byte[] input) throws IOException, DataFormatException {
  Inflater ifl=new Inflater();
  ifl.setInput(input);
  ByteArrayOutputStream baos=new ByteArrayOutputStream(input.length);
  byte[] buff=new byte[1024];
  while (!ifl.finished()) {
    int count=ifl.inflate(buff);
    baos.write(buff,0,count);
  }
  baos.close();
  byte[] output=baos.toByteArray();
  return new String(output);
}
 

Example 8

From project v7files, under directory /src/main/java/v7db/files/.

Source file: Compression.java

  22 
vote

/** 
 * assumes that the result buffer has exactly the needed size
 * @throws DataFormatException
 */
static void inflate(byte[] data,int off,int len,byte[] out) throws DataFormatException {
  Inflater inflater=new Inflater(true);
  inflater.setInput(data,off,len);
  int size=inflater.inflate(out);
  if (size != out.length)   throw new DataFormatException("unexpected size of deflated data: " + size + " instead of "+ out.length);
}
 

Example 9

From project AmDroid, under directory /httpclientandroidlib/src/ch/boye/httpclientandroidlib/client/entity/.

Source file: DeflateDecompressingEntity.java

  21 
vote

/** 
 * Returns the non-null InputStream that should be returned to by all requests to {@link #getContent()}.
 * @return a non-null InputStream
 * @throws IOException if there was a problem
 */
@Override InputStream getDecompressingInputStream(final InputStream wrapped) throws IOException {
  byte[] peeked=new byte[6];
  PushbackInputStream pushback=new PushbackInputStream(wrapped,peeked.length);
  int headerLength=pushback.read(peeked);
  if (headerLength == -1) {
    throw new IOException("Unable to read the response");
  }
  byte[] dummy=new byte[1];
  Inflater inf=new Inflater();
  try {
    int n;
    while ((n=inf.inflate(dummy)) == 0) {
      if (inf.finished()) {
        throw new IOException("Unable to read the response");
      }
      if (inf.needsDictionary()) {
        break;
      }
      if (inf.needsInput()) {
        inf.setInput(peeked);
      }
    }
    if (n == -1) {
      throw new IOException("Unable to read the response");
    }
    pushback.unread(peeked,0,headerLength);
    return new InflaterInputStream(pushback);
  }
 catch (  DataFormatException e) {
    pushback.unread(peeked,0,headerLength);
    return new InflaterInputStream(pushback,new Inflater(true));
  }
}
 

Example 10

From project android_5, under directory /src/aarddict/.

Source file: Volume.java

  21 
vote

static String decompressZlib(byte[] bytes) throws IOException, DataFormatException {
  Inflater decompressor=new Inflater();
  decompressor.setInput(bytes);
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  try {
    byte[] buf=new byte[1024];
    while (!decompressor.finished()) {
      int count=decompressor.inflate(buf);
      out.write(buf,0,count);
    }
  }
  finally {
    out.close();
  }
  return utf8(out.toByteArray());
}
 

Example 11

From project archive-commons, under directory /archive-commons/src/main/java/org/archive/format/gzip/.

Source file: GZIPSeriesMember.java

  21 
vote

public GZIPSeriesMember(GZIPMemberSeries series,GZIPHeader header){
  this.series=series;
  this.header=header;
  this.footer=null;
  this.inflater=new Inflater(true);
  this.crc=new CRC32();
  gotIOError=false;
  gotGZError=false;
  gotEOR=false;
}
 

Example 12

From project avro, under directory /lang/java/avro/src/main/java/org/apache/avro/file/.

Source file: DeflateCodec.java

  21 
vote

private Inflater getInflater(){
  if (null == inflater) {
    inflater=new Inflater(nowrap);
  }
  inflater.reset();
  return inflater;
}
 

Example 13

From project cas, under directory /cas-server-core/src/main/java/org/jasig/cas/authentication/principal/.

Source file: GoogleAccountsService.java

  21 
vote

private static String inflate(final byte[] bytes){
  final Inflater inflater=new Inflater(true);
  final byte[] xmlMessageBytes=new byte[10000];
  final byte[] extendedBytes=new byte[bytes.length + 1];
  System.arraycopy(bytes,0,extendedBytes,0,bytes.length);
  extendedBytes[bytes.length]=0;
  inflater.setInput(extendedBytes);
  try {
    final int resultLength=inflater.inflate(xmlMessageBytes);
    inflater.end();
    if (!inflater.finished()) {
      throw new RuntimeException("buffer not large enough.");
    }
    inflater.end();
    return new String(xmlMessageBytes,0,resultLength,"UTF-8");
  }
 catch (  final DataFormatException e) {
    return null;
  }
catch (  final UnsupportedEncodingException e) {
    throw new RuntimeException("Cannot find encoding: UTF-8",e);
  }
}
 

Example 14

From project commons-compress, under directory /src/main/java/org/apache/commons/compress/archivers/zip/.

Source file: ZipFile.java

  21 
vote

/** 
 * Returns an InputStream for reading the contents of the given entry.
 * @param ze the entry to get the stream for.
 * @return a stream to read the entry from.
 * @throws IOException if unable to create an input stream from the zipentry
 * @throws ZipException if the zipentry uses an unsupported feature
 */
public InputStream getInputStream(ZipArchiveEntry ze) throws IOException, ZipException {
  OffsetEntry offsetEntry=entries.get(ze);
  if (offsetEntry == null) {
    return null;
  }
  ZipUtil.checkRequestedFeatures(ze);
  long start=offsetEntry.dataOffset;
  BoundedInputStream bis=new BoundedInputStream(start,ze.getCompressedSize());
switch (ze.getMethod()) {
case ZipEntry.STORED:
    return bis;
case ZipEntry.DEFLATED:
  bis.addDummy();
final Inflater inflater=new Inflater(true);
return new InflaterInputStream(bis,inflater){
@Override public void close() throws IOException {
  super.close();
  inflater.end();
}
}
;
default :
throw new ZipException("Found unsupported compression method " + ze.getMethod());
}
}
 

Example 15

From project core_4, under directory /impl/src/main/java/org/richfaces/util/.

Source file: Util.java

  21 
vote

protected static byte[] decrypt(byte[] src){
  try {
    byte[] zipsrc=CODEC.decode(src);
    Inflater decompressor=new Inflater();
    byte[] uncompressed=new byte[zipsrc.length * 5];
    decompressor.setInput(zipsrc);
    int totalOut=decompressor.inflate(uncompressed);
    byte[] out=new byte[totalOut];
    System.arraycopy(uncompressed,0,out,0,totalOut);
    decompressor.end();
    return out;
  }
 catch (  Exception e) {
    throw new FacesException("Error decode resource data",e);
  }
}
 

Example 16

From project Custom-Salem, under directory /src/haven/.

Source file: Message.java

  21 
vote

public Message inflate(int length){
  Message ret=new Message(0);
  Inflater z=new Inflater();
  z.setInput(blob,off,length);
  byte[] buf=new byte[10000];
  while (true) {
    try {
      int len;
      if ((len=z.inflate(buf)) == 0) {
        if (!z.finished())         throw (new RuntimeException("Got unterminated gzip blob"));
        break;
      }
      ret.addbytes(buf,0,len);
    }
 catch (    java.util.zip.DataFormatException e) {
      throw (new RuntimeException("Got malformed gzip blob",e));
    }
  }
  return (ret);
}
 

Example 17

From project dawn-common, under directory /org.dawb.common.util/src/org/dawb/common/util/list/.

Source file: PrimitiveArrayEncoder.java

  21 
vote

/** 
 * Inflate a string
 * @param compressed
 * @return Inflated string.
 */
public static String expand(final String compressed){
  try {
    final byte[] output=compressed.getBytes("US-ASCII");
    Inflater decompresser=new Inflater();
    decompresser.setInput(output,0,output.length);
    byte[] result=new byte[output.length * 2];
    int resultLength=decompresser.inflate(result);
    decompresser.end();
    return new String(result,0,resultLength,"US-ASCII");
  }
 catch (  Exception ne) {
    ne.printStackTrace();
    return null;
  }
}
 

Example 18

From project dnieprov, under directory /src/org/dnieprov/driver/.

Source file: DnieDriver.java

  21 
vote

private byte[] deflate(byte[] zlib) throws DnieUnexpectedException {
  byte[] buf=null;
  SecureByteBuffer buffer=new SecureByteBuffer();
  try {
    Inflater decompressor=new Inflater();
    decompressor.setInput(zlib,8,zlib.length - 8);
    buf=new byte[1024];
    while (!decompressor.finished()) {
      int count=decompressor.inflate(buf);
      if (count == 0) {
        throw new DataFormatException();
      }
      buffer.write(buf,0,count);
    }
    return buffer.getByteArray();
  }
 catch (  DataFormatException ex) {
    throw new DnieUnexpectedException("Error cert compression");
  }
 finally {
    if (buf != null)     Arrays.fill(buf,DnieInterface.NULL_BYTE);
    buffer.clearAll();
  }
}
 

Example 19

From project freemind, under directory /freemind/freemind/main/.

Source file: Tools.java

  21 
vote

public static String decompress(String compressedMessage){
  byte[] compressedData=fromBase64(compressedMessage);
  Inflater decompressor=new Inflater();
  decompressor.setInput(compressedData);
  ByteArrayOutputStream bos=new ByteArrayOutputStream(compressedData.length);
  byte[] buf=new byte[1024];
  while (!decompressor.finished()) {
    try {
      int count=decompressor.inflate(buf);
      bos.write(buf,0,count);
    }
 catch (    DataFormatException e) {
    }
  }
  try {
    bos.close();
  }
 catch (  IOException e) {
  }
  byte[] decompressedData=bos.toByteArray();
  return byteArrayToUTF8String(decompressedData);
}
 

Example 20

From project gda-common, under directory /uk.ac.gda.common/src/uk/ac/gda/util/list/.

Source file: PrimitiveArrayEncoder.java

  21 
vote

/** 
 * Inflate a string
 * @param compressed
 * @return Inflated string.
 */
public static String expand(final String compressed){
  try {
    final byte[] output=compressed.getBytes("US-ASCII");
    Inflater decompresser=new Inflater();
    decompresser.setInput(output,0,output.length);
    byte[] result=new byte[output.length * 2];
    int resultLength=decompresser.inflate(result);
    decompresser.end();
    return new String(result,0,resultLength,"US-ASCII");
  }
 catch (  Exception ne) {
    ne.printStackTrace();
    return null;
  }
}
 

Example 21

From project httpClient, under directory /httpclient/src/main/java/org/apache/http/client/entity/.

Source file: DeflateDecompressingEntity.java

  21 
vote

/** 
 * Returns the non-null InputStream that should be returned to by all requests to {@link #getContent()}.
 * @return a non-null InputStream
 * @throws IOException if there was a problem
 */
@Override InputStream getDecompressingInputStream(final InputStream wrapped) throws IOException {
  byte[] peeked=new byte[6];
  PushbackInputStream pushback=new PushbackInputStream(wrapped,peeked.length);
  int headerLength=pushback.read(peeked);
  if (headerLength == -1) {
    throw new IOException("Unable to read the response");
  }
  byte[] dummy=new byte[1];
  Inflater inf=new Inflater();
  try {
    int n;
    while ((n=inf.inflate(dummy)) == 0) {
      if (inf.finished()) {
        throw new IOException("Unable to read the response");
      }
      if (inf.needsDictionary()) {
        break;
      }
      if (inf.needsInput()) {
        inf.setInput(peeked);
      }
    }
    if (n == -1) {
      throw new IOException("Unable to read the response");
    }
    pushback.unread(peeked,0,headerLength);
    return new InflaterInputStream(pushback);
  }
 catch (  DataFormatException e) {
    pushback.unread(peeked,0,headerLength);
    return new InflaterInputStream(pushback,new Inflater(true));
  }
}
 

Example 22

From project jumpnevolve, under directory /lib/slick/src/org/newdawn/slick/opengl/.

Source file: PNGImageData.java

  21 
vote

/** 
 * Decode a PNG into a data buffer
 * @param buffer The buffer to read the data into 
 * @param stride The image stride to read (i.e. the number of bytes to skip each line)
 * @param flip True if the PNG should be flipped
 * @throws IOException Indicates a failure to read the PNG either invalid data or not enough room in the buffer
 */
private void decode(ByteBuffer buffer,int stride,boolean flip) throws IOException {
  final int offset=buffer.position();
  byte[] curLine=new byte[width * bytesPerPixel + 1];
  byte[] prevLine=new byte[width * bytesPerPixel + 1];
  final Inflater inflater=new Inflater();
  try {
    for (int yIndex=0; yIndex < height; yIndex++) {
      int y=yIndex;
      if (flip) {
        y=height - 1 - yIndex;
      }
      readChunkUnzip(inflater,curLine,0,curLine.length);
      unfilter(curLine,prevLine);
      buffer.position(offset + y * stride);
switch (colorType) {
case COLOR_TRUECOLOR:
case COLOR_TRUEALPHA:
        copy(buffer,curLine);
      break;
case COLOR_INDEXED:
    copyExpand(buffer,curLine);
  break;
default :
throw new UnsupportedOperationException("Not yet implemented");
}
byte[] tmp=curLine;
curLine=prevLine;
prevLine=tmp;
}
}
  finally {
inflater.end();
}
bitDepth=hasAlpha() ? 32 : 24;
}
 

Example 23

From project JVerge, under directory /src/persist/.

Source file: ExtendedDataInputStream.java

  21 
vote

public byte[] readCompressedBytes() throws IOException {
  int uncompSize=this.readSignedIntegerLittleEndian();
  int compSize=this.readSignedIntegerLittleEndian();
  System.out.println("Reading compressed: " + compSize + " into "+ uncompSize);
  byte input[]=new byte[compSize];
  for (int j=0; j < compSize; j++)   input[j]=this.readByte();
  Inflater decompresser=new Inflater();
  decompresser.setInput(input,0,compSize);
  byte[] output=new byte[uncompSize];
  try {
    decompresser.inflate(output);
  }
 catch (  DataFormatException e) {
    e.printStackTrace();
  }
  decompresser.end();
  return output;
}
 

Example 24

From project Kairos, under directory /src/java/org/apache/nutch/util/.

Source file: DeflateUtils.java

  21 
vote

/** 
 * Returns an inflated copy of the input array, truncated to <code>sizeLimit</code> bytes, if necessary.  If the deflated input has been truncated or corrupted, a best-effort attempt is made to inflate as much as possible.  If no data can be extracted <code>null</code> is returned.
 */
public static final byte[] inflateBestEffort(byte[] in,int sizeLimit){
  ByteArrayOutputStream outStream=new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length);
  Inflater inflater=new Inflater(true);
  InflaterInputStream inStream=new InflaterInputStream(new ByteArrayInputStream(in),inflater);
  byte[] buf=new byte[BUF_SIZE];
  int written=0;
  while (true) {
    try {
      int size=inStream.read(buf);
      if (size <= 0)       break;
      if ((written + size) > sizeLimit) {
        outStream.write(buf,0,sizeLimit - written);
        break;
      }
      outStream.write(buf,0,size);
      written+=size;
    }
 catch (    Exception e) {
      LOG.info("Caught Exception in inflateBestEffort");
      e.printStackTrace(LogUtil.getWarnStream(LOG));
      break;
    }
  }
  try {
    outStream.close();
  }
 catch (  IOException e) {
  }
  return outStream.toByteArray();
}
 

Example 25

From project kevoree-library, under directory /kalimucho/org.kevoree.library.kalimucho.kalimuchoNode/src/main/java/util/.

Source file: DecompressByteArray.java

  21 
vote

/** 
 * Decompress the byte array
 * @return the decompressed byte array
 * @throws DataFormatException when the initial byte array is in an unknown fcompression format
 */
public byte[] decompress() throws DataFormatException {
  Inflater decompresseur=new Inflater();
  decompresseur.setInput(aDecompresser);
  ByteArrayOutputStream decompresse=new ByteArrayOutputStream(aDecompresser.length);
  byte[] buf=new byte[1024];
  while (!decompresseur.finished()) {
    int octetsLus=decompresseur.inflate(buf);
    decompresse.write(buf,0,octetsLus);
  }
  try {
    decompresse.close();
    return decompresse.toByteArray();
  }
 catch (  IOException e) {
    return null;
  }
}
 

Example 26

From project Notes, under directory /src/net/micode/notes/gtask/remote/.

Source file: GTaskClient.java

  21 
vote

private String getResponseContent(HttpEntity entity) throws IOException {
  String contentEncoding=null;
  if (entity.getContentEncoding() != null) {
    contentEncoding=entity.getContentEncoding().getValue();
    Log.d(TAG,"encoding: " + contentEncoding);
  }
  InputStream input=entity.getContent();
  if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
    input=new GZIPInputStream(entity.getContent());
  }
 else   if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) {
    Inflater inflater=new Inflater(true);
    input=new InflaterInputStream(entity.getContent(),inflater);
  }
  try {
    InputStreamReader isr=new InputStreamReader(input);
    BufferedReader br=new BufferedReader(isr);
    StringBuilder sb=new StringBuilder();
    while (true) {
      String buff=br.readLine();
      if (buff == null) {
        return sb.toString();
      }
      sb=sb.append(buff);
    }
  }
  finally {
    input.close();
  }
}
 

Example 27

From project nutch, under directory /src/java/org/apache/nutch/util/.

Source file: DeflateUtils.java

  21 
vote

/** 
 * Returns an inflated copy of the input array, truncated to <code>sizeLimit</code> bytes, if necessary.  If the deflated input has been truncated or corrupted, a best-effort attempt is made to inflate as much as possible.  If no data can be extracted <code>null</code> is returned.
 */
public static final byte[] inflateBestEffort(byte[] in,int sizeLimit){
  ByteArrayOutputStream outStream=new ByteArrayOutputStream(EXPECTED_COMPRESSION_RATIO * in.length);
  Inflater inflater=new Inflater(true);
  InflaterInputStream inStream=new InflaterInputStream(new ByteArrayInputStream(in),inflater);
  byte[] buf=new byte[BUF_SIZE];
  int written=0;
  while (true) {
    try {
      int size=inStream.read(buf);
      if (size <= 0)       break;
      if ((written + size) > sizeLimit) {
        outStream.write(buf,0,sizeLimit - written);
        break;
      }
      outStream.write(buf,0,size);
      written+=size;
    }
 catch (    Exception e) {
      LOG.info("Caught Exception in inflateBestEffort",e);
      break;
    }
  }
  try {
    outStream.close();
  }
 catch (  IOException e) {
  }
  return outStream.toByteArray();
}
 

Example 28

From project OpenEMRConnect, under directory /oeclib/src/main/java/ke/go/moh/oec/lib/.

Source file: Compresser.java

  21 
vote

static void decompress(Message m){
  byte[] compressedXml=m.getCompressedXml();
  int compressedXmlLength=m.getCompressedXmlLength();
  Inflater decompresser=new Inflater();
  decompresser.setInput(compressedXml,0,compressedXmlLength);
  byte[] inflatedBytes=new byte[60000];
  int resultLength=0;
  try {
    resultLength=decompresser.inflate(inflatedBytes);
  }
 catch (  DataFormatException ex) {
    Logger.getLogger(HttpService.class.getName()).log(Level.SEVERE,"Error decompressing message: " + m.summarize(false),ex);
  }
  decompresser.end();
  String xml=null;
  try {
    xml=new String(inflatedBytes,0,resultLength,"UTF-8");
  }
 catch (  UnsupportedEncodingException ex) {
    Logger.getLogger(Compresser.class.getName()).log(Level.SEVERE,"Error decompressing message: " + m.summarize(false),ex);
  }
  m.setXml(xml);
}
 

Example 29

From project OSM-binary, under directory /src.java/crosby/binary/file/.

Source file: FileBlockPosition.java

  21 
vote

/** 
 * Parse out and decompress the data part of a fileblock helper function. 
 */
FileBlock parseData(byte buf[]) throws InvalidProtocolBufferException {
  FileBlock out=FileBlock.newInstance(type,null,indexdata);
  Fileformat.Blob blob=Fileformat.Blob.parseFrom(buf);
  if (blob.hasRaw()) {
    out.data=blob.getRaw();
  }
 else   if (blob.hasZlibData()) {
    byte buf2[]=new byte[blob.getRawSize()];
    Inflater decompresser=new Inflater();
    decompresser.setInput(blob.getZlibData().toByteArray());
    try {
      decompresser.inflate(buf2);
    }
 catch (    DataFormatException e) {
      e.printStackTrace();
      throw new Error(e);
    }
    assert(decompresser.finished());
    decompresser.end();
    out.data=ByteString.copyFrom(buf2);
  }
  return out;
}
 

Example 30

From project PSXperia, under directory /src/com/yifanlu/PSXperiaTool/.

Source file: PSImageExtract.java

  21 
vote

public void uncompress(OutputStream out) throws IOException, DataFormatException {
  Logger.info("Extracting PS Image [BETA! This tool WILL return with an exception, even if successful].");
  check();
  mIn.skip(HEADER.length);
  mBytesRead=HEADER.length;
  mBytesWritten=0;
  Inflater inf=new Inflater();
  int n;
  byte[] buff=new byte[BLOCK_SIZE];
  try {
    while ((n=inf.inflate(buff,0,BLOCK_SIZE)) != -1) {
      out.write(buff,0,n);
      addBytesWritten(n);
      if (inf.finished() || inf.needsDictionary()) {
        int remainder=inf.getRemaining();
        changeBuffer(remainder);
        inf.reset();
        inf.setInput(mBuff,0,remainder);
      }
 else       if (inf.needsInput()) {
        fill(inf);
      }
    }
  }
 catch (  DataFormatException ex) {
    out.write(new byte[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
    out.write(mBuff);
    byte[] b=new byte[1024];
    mIn.read(b);
    out.write(b);
    out.close();
    throw ex;
  }
  Logger.debug("Extraction done.");
}
 

Example 31

From project salem, under directory /src/haven/.

Source file: Message.java

  21 
vote

public Message inflate(int length){
  Message ret=new Message(0);
  Inflater z=new Inflater();
  z.setInput(blob,off,length);
  byte[] buf=new byte[10000];
  while (true) {
    try {
      int len;
      if ((len=z.inflate(buf)) == 0) {
        if (!z.finished())         throw (new RuntimeException("Got unterminated gzip blob"));
        break;
      }
      ret.addbytes(buf,0,len);
    }
 catch (    java.util.zip.DataFormatException e) {
      throw (new RuntimeException("Got malformed gzip blob",e));
    }
  }
  return (ret);
}
 

Example 32

From project SpoutPlugin, under directory /src/main/java/org/getspout/spoutapi/packet/.

Source file: PacketAddonData.java

  21 
vote

@Override public void decompress(){
  if (compressed) {
    Inflater decompressor=new Inflater();
    decompressor.setInput(data);
    ByteArrayOutputStream bos=new ByteArrayOutputStream(data.length);
    byte[] buf=new byte[1024];
    while (!decompressor.finished()) {
      try {
        int count=decompressor.inflate(buf);
        bos.write(buf,0,count);
      }
 catch (      DataFormatException e) {
      }
    }
    try {
      bos.close();
    }
 catch (    IOException e) {
    }
    data=bos.toByteArray();
    compressed=false;
  }
}
 

Example 33

From project SWGRapDev, under directory /src/client/.

Source file: TreeFile.java

  21 
vote

public void extractTo(java.io.File saveLocation) throws IOException, DataFormatException {
  saveLocation.getParentFile().mkdirs();
  FileInputStream fin=new FileInputStream(TreeFile.this.file);
  FileOutputStream fos=new FileOutputStream(saveLocation.getAbsoluteFile());
  byte[] decompressedData=new byte[uncompressedSize];
  if (format == 0) {
    fin.skip(offset);
    fin.read(decompressedData);
    fos.write(decompressedData);
  }
 else {
    byte[] compressedData=new byte[size];
    fin.skip(offset);
    fin.read(compressedData);
    Inflater inflates=new Inflater();
    inflates.setInput(compressedData);
    inflates.inflate(decompressedData);
    inflates.end();
    fos.write(decompressedData);
  }
  fin.close();
  fos.close();
}
 

Example 34

From project TomP2P, under directory /src/main/java/net/tomp2p/utils/.

Source file: Utils.java

  21 
vote

public static byte[] uncompress(byte[] compressedData,int offset,int length){
  Inflater decompressor=new Inflater();
  decompressor.setInput(compressedData,offset,length);
  ByteArrayOutputStream bos=new ByteArrayOutputStream(length);
  byte[] buf=new byte[1024];
  while (!decompressor.finished()) {
    try {
      int count=decompressor.inflate(buf);
      bos.write(buf,0,count);
    }
 catch (    DataFormatException e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }
  }
  try {
    bos.close();
  }
 catch (  IOException e) {
    e.printStackTrace();
    throw new RuntimeException(e);
  }
  return bos.toByteArray();
}
 

Example 35

From project xnio_1, under directory /api/src/main/java/org/xnio/.

Source file: XnioWorker.java

  21 
vote

/** 
 * Create a stream channel that decompresses the source data according to the configuration in the given option map.
 * @param delegate the compressed channel
 * @param options the configuration options for the channel
 * @return a decompressed channel
 * @throws IOException if the channel could not be constructed
 */
public StreamSourceChannel getInflatingChannel(final StreamSourceChannel delegate,OptionMap options) throws IOException {
  final boolean nowrap;
switch (options.get(Options.COMPRESSION_TYPE,CompressionType.DEFLATE)) {
case DEFLATE:
    nowrap=false;
  break;
case GZIP:
nowrap=true;
break;
default :
throw new IllegalArgumentException("Compression format not supported");
}
return getInflatingChannel(delegate,new Inflater(nowrap));
}
 

Example 36

From project vnc, under directory /src/com/tigervnc/decoder/.

Source file: ZlibDecoder.java

  20 
vote

public void handleRect(int x,int y,int w,int h) throws IOException {
  if (dos != null) {
    dos.writeInt(RawDecoder.EncodingRaw);
  }
  int nBytes=rfbis.readU32();
  if (zlibBuf == null || zlibBufLen < nBytes) {
    zlibBufLen=nBytes * 2;
    zlibBuf=new byte[zlibBufLen];
  }
  rfbis.readFully(zlibBuf,0,nBytes);
  if (zlibInflater == null) {
    zlibInflater=new Inflater();
  }
  zlibInflater.setInput(zlibBuf,0,nBytes);
  try {
    if (bytesPerPixel == 1) {
      for (int dy=y; dy < y + h; dy++) {
        zlibInflater.inflate(pixels8,dy * framebufferWidth + x,w);
        if (dos != null)         dos.write(pixels8,dy * framebufferWidth + x,w);
      }
    }
 else {
      byte[] buf=new byte[w * 4];
      int i, offset;
      for (int dy=y; dy < y + h; dy++) {
        zlibInflater.inflate(buf);
        offset=dy * framebufferWidth + x;
        for (i=0; i < w; i++) {
          RawDecoder.pixels24[offset + i]=(buf[i * 4 + 2] & 0xFF) << 16 | (buf[i * 4 + 1] & 0xFF) << 8 | (buf[i * 4] & 0xFF);
        }
        if (dos != null)         dos.write(buf);
      }
    }
  }
 catch (  DataFormatException ex) {
    ex.printStackTrace();
  }
  handleUpdatedPixels(x,y,w,h);
}
 

Example 37

From project and-bible, under directory /jsword-tweaks/bakup/.

Source file: Zip.java

  19 
vote

public ByteArrayOutputStream uncompress(int expectedLength) throws IOException {
  ByteArrayOutputStream out=new ByteArrayOutputStream(expectedLength);
  InflaterInputStream in=new InflaterInputStream(input,new Inflater(),expectedLength);
  byte[] buf=new byte[expectedLength];
  for (int count=in.read(buf); count != -1; count=in.read(buf)) {
    out.write(buf,0,count);
  }
  in.close();
  out.flush();
  out.close();
  return out;
}
 

Example 38

From project dcm4che, under directory /dcm4che-core/src/main/java/org/dcm4che/io/.

Source file: DicomInputStream.java

  19 
vote

private void switchTransferSyntax(String tsuid) throws IOException {
  this.tsuid=tsuid;
  bigEndian=tsuid.equals(UID.ExplicitVRBigEndian);
  explicitVR=!tsuid.equals(UID.ImplicitVRLittleEndian);
  if (tsuid.equals(UID.DeflatedExplicitVRLittleEndian) || tsuid.equals(UID.JPIPReferencedDeflate)) {
    if (hasZLIBHeader()) {
      LOG.warn(DEFLATED_WITH_ZLIB_HEADER);
      super.in=new InflaterInputStream(super.in);
    }
 else     super.in=new InflaterInputStream(super.in,new Inflater(true));
  }
}
 

Example 39

From project gnip4j, under directory /core/src/main/java/com/zaubersoftware/gnip4j/api/support/http/.

Source file: JRERemoteResourceProvider.java

  19 
vote

@Override public final InputStream getResource(final URI uri) throws AuthenticationGnipException, TransportGnipException {
  try {
    final URLConnection uc=uri.toURL().openConnection();
    HttpURLConnection huc=null;
    if (uc instanceof HttpURLConnection) {
      huc=(HttpURLConnection)uc;
    }
    uc.setAllowUserInteraction(false);
    uc.setDefaultUseCaches(false);
    uc.setConnectTimeout(connectTimeout);
    uc.setReadTimeout(readTimeout);
    uc.setRequestProperty("Accept-Encoding","gzip, deflate");
    uc.setRequestProperty("User-Agent",USER_AGENT);
    uc.setRequestProperty("Authorization","Basic " + encoder.encode(authentication));
    doConfiguration(uc);
    uc.connect();
    if (huc != null) {
      validateStatusLine(uri,huc.getResponseCode(),huc.getResponseMessage());
    }
    InputStream is=uc.getInputStream();
    final String encoding=uc.getContentEncoding();
    if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
      is=new GZIPInputStream(is);
    }
 else     if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
      is=new InflaterInputStream(is,new Inflater(true));
    }
    return new JREReleaseInputStream(uc,is);
  }
 catch (  final MalformedURLException e) {
    throw new TransportGnipException(e);
  }
catch (  final IOException e) {
    throw new TransportGnipException(e);
  }
}
 

Example 40

From project HBase-Lattice, under directory /hbl/src/main/java/com/inadco/hbl/compiler/.

Source file: YamlModelParser.java

  19 
vote

public static Cube decodeCubeModel(String encoded) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  OutputStream os=new InflaterOutputStream(baos,new Inflater(false));
  os.write(Base64.decodeBase64(encoded.getBytes("US-ASCII")));
  os.close();
  return parseYamlModel(new String(baos.toByteArray(),"utf-8"));
}
 

Example 41

From project heritrix3, under directory /commons/src/main/java/org/archive/util/zip/.

Source file: OpenJDK7InflaterInputStream.java

  19 
vote

/** 
 * Creates a new input stream with the specified decompressor and buffer size.
 * @param in the input stream
 * @param inf the decompressor ("inflater")
 * @param size the input buffer size
 * @exception IllegalArgumentException if size is <= 0
 */
public OpenJDK7InflaterInputStream(InputStream in,Inflater inf,int size){
  super(in);
  if (in == null || inf == null) {
    throw new NullPointerException();
  }
 else   if (size <= 0) {
    throw new IllegalArgumentException("buffer size <= 0");
  }
  this.inf=inf;
  buf=new byte[size];
}
 

Example 42

From project JMaNGOS, under directory /Tools/src/main/java/org/jmangos/tools/openGL/.

Source file: PNGDecoder.java

  19 
vote

private void refillInflater(final Inflater inflater) throws IOException {
  while (this.chunkRemaining == 0) {
    closeChunk();
    openChunk(IDAT);
  }
  final int read=readChunk(this.buffer,0,this.buffer.length);
  inflater.setInput(this.buffer,0,read);
}
 

Example 43

From project jsword, under directory /src/main/java/org/crosswire/common/compress/.

Source file: Zip.java

  19 
vote

public ByteArrayOutputStream uncompress(int expectedLength) throws IOException {
  ByteArrayOutputStream out=new ByteArrayOutputStream(expectedLength);
  InflaterInputStream in=new InflaterInputStream(input,new Inflater(),expectedLength);
  byte[] buf=new byte[expectedLength];
  for (int count=in.read(buf); count != -1; count=in.read(buf)) {
    out.write(buf,0,count);
  }
  in.close();
  out.flush();
  out.close();
  return out;
}
 

Example 44

From project plexus-archiver, under directory /src/main/java/org/codehaus/plexus/archiver/zip/.

Source file: ZipFile.java

  19 
vote

/** 
 * Returns an InputStream for reading the contents of the given entry.
 * @param ze the entry to get the stream for.
 * @return a stream to read the entry from.
 */
public InputStream getInputStream(ZipEntry ze) throws IOException {
  Long start=dataOffsets.get(ze);
  if (start == null) {
    return null;
  }
  BoundedInputStream bis=new BoundedInputStream(start,ze.getCompressedSize());
switch (ze.getMethod()) {
case ZipEntry.STORED:
    return bis;
case ZipEntry.DEFLATED:
  bis.addDummy();
return new InflaterInputStream(bis,new Inflater(true)){
  public void close() throws IOException {
    super.close();
    inf.end();
  }
}
;
default :
throw new ZipException("Found unsupported compression method " + ze.getMethod());
}
}
 

Example 45

From project qpid-hessian, under directory /src/main/java/org/apache/qpid/contrib/hessian/.

Source file: HessianEndpoint.java

  19 
vote

/** 
 * Execute a request.
 */
private byte[] createResponseBody(byte[] request,boolean compressed) throws Exception {
  InputStream in=new ByteArrayInputStream(request);
  if (compressed) {
    in=new InflaterInputStream(new ByteArrayInputStream(request),new Inflater(true));
  }
  ByteArrayOutputStream bout=new ByteArrayOutputStream();
  OutputStream out;
  if (compressed) {
    Deflater deflater=new Deflater(Deflater.DEFAULT_COMPRESSION,true);
    out=new DeflaterOutputStream(bout,deflater);
  }
 else {
    out=bout;
  }
  HessianSkeleton skeleton=new HessianSkeleton(serviceImpl,serviceAPI);
  skeleton.invoke(in,out,getSerializerFactory());
  if (out instanceof DeflaterOutputStream) {
    ((DeflaterOutputStream)out).finish();
  }
  out.flush();
  out.close();
  return bout.toByteArray();
}
 

Example 46

From project QuakeInjector, under directory /src/de/haukerehfeld/quakeinjector/.

Source file: Download.java

  19 
vote

public InputStream getStream(ProgressListener progress) throws IOException {
  if (stream == null) {
    String encoding=connection.getContentEncoding();
    stream=connection.getInputStream();
    if (progress != null) {
      stream=new ProgressListenerInputStream(stream,progress);
    }
    if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
      stream=new GZIPInputStream(stream);
    }
 else     if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
      stream=new InflaterInputStream(stream,new Inflater(true));
    }
  }
  return stream;
}
 

Example 47

From project rapid, under directory /rapid-generator/rapid-generator/src/main/java/cn/org/rapid_framework/generator/util/paranamer/.

Source file: JavadocParanamer.java

  19 
vote

private InputStream urlToInputStream(URL url) throws IOException {
  URLConnection conn=url.openConnection();
  conn.setRequestProperty("User-Agent",IE);
  conn.setRequestProperty("Accept-Encoding","gzip, deflate");
  conn.connect();
  String encoding=conn.getContentEncoding();
  if ((encoding != null) && encoding.equalsIgnoreCase("gzip"))   return new GZIPInputStream(conn.getInputStream());
 else   if ((encoding != null) && encoding.equalsIgnoreCase("deflate"))   return new InflaterInputStream(conn.getInputStream(),new Inflater(true));
 else   return conn.getInputStream();
}
 

Example 48

From project showcase, under directory /src/main/java/org/richfaces/demo/mediaOutput/.

Source file: MediaBean.java

  19 
vote

@Override public void write(InputStream inChannel,OutputStream outChannel) throws IOException {
  if (isIndexed) {
    super.write(inChannel,outChannel);
  }
 else {
    byte[] ps=new byte[imageWidth * 3 + 1];
    byte[] bs=new byte[imageWidth * 3 + 1];
    assert(bs.length < BUFFER_SIZE);
    int read=0;
    InputStream inflaterInputStream=new BufferedInputStream(new InflaterInputStream(new LimitedInputStream(inChannel),new Inflater(),2048),BUFFER_SIZE);
    ByteArrayOutputStream baos=new ByteArrayOutputStream(sectionLength);
    DeflaterOutputStream deflaterOutputStream=new DeflaterOutputStream(baos,new Deflater(),2048);
    while ((read=(inflaterInputStream.read(bs))) > 0) {
      reconstruct(bs,ps);
      transformColors(bs,1,read - 1);
      deflaterOutputStream.write(bs,0,read);
      byte[] swapVar=bs;
      bs=ps;
      ps=swapVar;
    }
    deflaterOutputStream.finish();
    byte[] compressedSectionBytes=baos.toByteArray();
    writeInt(outChannel,compressedSectionBytes.length);
    CRC32 crc32=new CRC32();
    outChannel.write(chunkTypeBytes);
    crc32.update(chunkTypeBytes);
    if (inChannel.skip(4) < 4) {
      throw new IllegalArgumentException();
    }
    outChannel.write(compressedSectionBytes);
    writeInt(outChannel,(int)crc32.getValue());
  }
}
 

Example 49

From project Sketchy-Truck, under directory /andengine/src/org/anddev/andengine/opengl/texture/compressed/pvr/.

Source file: PVRCCZTexture.java

  19 
vote

public InputStream wrap(final InputStream pInputStream) throws IOException {
switch (this) {
case GZIP:
    return new GZIPInputStream(pInputStream);
case ZLIB:
  return new InflaterInputStream(pInputStream,new Inflater());
case NONE:
case BZIP2:
default :
throw new IllegalArgumentException("Unexpected " + CCZCompressionFormat.class.getSimpleName() + ": '"+ this+ "'.");
}
}