Java Code Examples for java.util.zip.InflaterOutputStream#close()

The following examples show how to use java.util.zip.InflaterOutputStream#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Memory.java    From Much-Assembly-Required with GNU General Public License v3.0 6 votes vote down vote up
public Memory(Document document) {

        String zipBytesStr = (String) document.get("zipBytes");

        if (zipBytesStr != null) {
            byte[] compressedBytes = Base64.getDecoder().decode((String) document.get("zipBytes"));

            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                Inflater decompressor = new Inflater(true);
                InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(baos, decompressor);
                inflaterOutputStream.write(compressedBytes);
                inflaterOutputStream.close();

                setBytes(baos.toByteArray());

            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            LogManager.LOGGER.severe("Memory was manually deleted");
            words = new char[GameServer.INSTANCE.getConfig().getInt("memory_size")];
        }
    }
 
Example 2
Source File: DeflateCompressor.java    From ob1k with Apache License 2.0 6 votes vote down vote up
@Override
public byte[] decompress(final byte[] data) {
  if (data == null) {
    return null;
  }

  final ByteArrayOutputStream buffer = new ByteArrayOutputStream(data.length);
  final InflaterOutputStream inflaterStream = new InflaterOutputStream(buffer, new Inflater());

  try {
    inflaterStream.write(data);
    inflaterStream.close();
    buffer.close();
  } catch (final IOException e) {
    throw new RuntimeException("failed compressing using deflate", e);
  }

  return buffer.toByteArray();
}
 
Example 3
Source File: DigestUtils.java    From JobX with Apache License 2.0 5 votes vote down vote up
public static String decompressData(String encdata) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        InflaterOutputStream zos = new InflaterOutputStream(bos);
        zos.write(getdeBASE64inCodec(encdata));
        zos.close();
        return new String(bos.toByteArray());
    } catch (Exception ex) {
        ex.printStackTrace();
        return "UNZIP_ERR";
    }
}
 
Example 4
Source File: DigestUtils.java    From JobX with Apache License 2.0 5 votes vote down vote up
public static String decompressData(String encdata, String charset) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        InflaterOutputStream zos = new InflaterOutputStream(bos);
        zos.write(getdeBASE64inCodec(encdata));
        zos.close();
        return new String(bos.toByteArray(), charset);
    } catch (Exception ex) {
        ex.printStackTrace();
        return "UNZIP_ERR";
    }
}
 
Example 5
Source File: mdBase.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] zlib_decompress(byte[] encdata,int offset,int size) {
	try {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		InflaterOutputStream inf = new InflaterOutputStream(out);
		inf.write(encdata,offset, size);
		inf.close();
		return out.toByteArray();
	} catch (Exception ex) {
		ex.printStackTrace();
		//show(emptyStr);
		return "ERR".getBytes();
	}
}
 
Example 6
Source File: mdBase.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
public static byte[] zlib_decompress(byte[] encdata,int offset) {
	try {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		InflaterOutputStream inf = new InflaterOutputStream(out);
		inf.write(encdata,offset, encdata.length-offset);
		inf.close();
		return out.toByteArray();
	} catch (Exception ex) {
		ex.printStackTrace();
		return "ERR".getBytes();
	}
}
 
Example 7
Source File: BU.java    From mdict-java with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
public static byte[] zlib_decompress(byte[] encdata,int offset,int ln) {
 try {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   InflaterOutputStream inf = new InflaterOutputStream(out); 
   inf.write(encdata,offset, ln); 
   inf.close(); 
   return out.toByteArray(); 
  } catch (Exception ex) {
  	ex.printStackTrace(); 
  	return "ERR".getBytes(); 
  }
}
 
Example 8
Source File: DigestUtils.java    From opencron with Apache License 2.0 5 votes vote down vote up
public static String decompressData(String encdata) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        InflaterOutputStream zos = new InflaterOutputStream(bos);
        zos.write(getdeBASE64inCodec(encdata));
        zos.close();
        return new String(bos.toByteArray());
    } catch (Exception ex) {
        ex.printStackTrace();
        return "UNZIP_ERR";
    }
}
 
Example 9
Source File: DigestUtils.java    From opencron with Apache License 2.0 5 votes vote down vote up
public static String decompressData(String encdata, String charset) {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        InflaterOutputStream zos = new InflaterOutputStream(bos);
        zos.write(getdeBASE64inCodec(encdata));
        zos.close();
        return new String(bos.toByteArray(), charset);
    } catch (Exception ex) {
        ex.printStackTrace();
        return "UNZIP_ERR";
    }
}
 
Example 10
Source File: GelfUdpAppenderTest.java    From logback-gelf with GNU Lesser General Public License v2.1 5 votes vote down vote up
private JsonNode receiveCompressedMessage() {
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(bos);

    try {
        inflaterOutputStream.write(receive());
        inflaterOutputStream.close();

        return new ObjectMapper().readTree(bos.toByteArray());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 11
Source File: Woff1Font.java    From FontVerter with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void readCompressedData(byte[] readData) throws IOException {
    if (readData.length == originalLength) {
        this.tableData = readData;
        return;
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    InflaterOutputStream compressStream = new InflaterOutputStream(out);
    compressStream.write(readData);
    compressStream.close();

    tableData = out.toByteArray();
}
 
Example 12
Source File: InflaterOutputStreamTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.zip.InflaterOutputStream#close()
 */
public void test_close() throws IOException {
    InflaterOutputStream ios = new InflaterOutputStream(os);
    ios.close();
    // multiple close
    ios.close();
}
 
Example 13
Source File: InflaterOutputStreamTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.zip.InflaterOutputStream#write(int)
 */
public void test_write_I_Illegal() throws IOException {

    // write after close
    InflaterOutputStream ios = new InflaterOutputStream(os);
    ios.close();
    try {
        ios.write(-1);
        fail("Should throw IOException");
    } catch (IOException e) {
        // expected
    }
}