Java 类java.util.zip.InflaterInputStream 实例源码
项目:springboot-shiro-cas-mybatis
文件:CompressionUtils.java
/**
* Decode the byte[] in base64 to a string.
*
* @param bytes the data to encode
* @return the new string in {@link #UTF8_ENCODING}.
*/
public static String decodeByteArrayToString(final byte[] bytes) {
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final byte[] buf = new byte[bytes.length];
try (InflaterInputStream iis = new InflaterInputStream(bais)) {
int count = iis.read(buf);
while (count != -1) {
baos.write(buf, 0, count);
count = iis.read(buf);
}
return new String(baos.toByteArray(), Charset.forName(UTF8_ENCODING));
} catch (final Exception e) {
LOGGER.error("Base64 decoding failed", e);
return null;
}
}
项目:springboot-shiro-cas-mybatis
文件:CompressionUtils.java
/**
* Decode the byte[] in base64 to a string.
*
* @param bytes the data to encode
* @return the new string in {@link #UTF8_ENCODING}.
*/
public static String decodeByteArrayToString(final byte[] bytes) {
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final byte[] buf = new byte[bytes.length];
try (final InflaterInputStream iis = new InflaterInputStream(bais)) {
int count = iis.read(buf);
while (count != -1) {
baos.write(buf, 0, count);
count = iis.read(buf);
}
return new String(baos.toByteArray(), Charset.forName(UTF8_ENCODING));
} catch (final Exception e) {
LOGGER.error("Base64 decoding failed", e);
return null;
}
}
项目:cas-5.1.0
文件:CompressionUtils.java
/**
* Decode the byte[] in base64 to a string.
*
* @param bytes the data to encode
* @return the new string
*/
public static String decodeByteArrayToString(final byte[] bytes) {
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final byte[] buf = new byte[bytes.length];
try (InflaterInputStream iis = new InflaterInputStream(bais)) {
int count = iis.read(buf);
while (count != -1) {
baos.write(buf, 0, count);
count = iis.read(buf);
}
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
} catch (final Exception e) {
LOGGER.error("Base64 decoding failed", e);
return null;
}
}
项目:travny
文件:SchemaDecoder.java
public static Schema decode(String schemaName, String[] compressedFragments) {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
for (String part : compressedFragments) {
bos.write(BaseEncoding.base64Url().decode(part));
}
bos.flush();
try (ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray())) {
try (InflaterInputStream in = new InflaterInputStream(bin)) {
byte[] allBinary = ByteStreams.toByteArray(in);
String all = new String(allBinary, StandardCharsets.UTF_8);
return new Parser()
.parse(all)
.getSchema(schemaName);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
项目:ipack
文件:ZlibExpanderProvider.java
public InputExpander get(final AlgorithmIdentifier algorithm)
{
return new InputExpander()
{
public AlgorithmIdentifier getAlgorithmIdentifier()
{
return algorithm;
}
public InputStream getInputStream(InputStream comIn)
{
InputStream s = new InflaterInputStream(comIn);
if (limit >= 0)
{
s = new LimitedInputStream(s, limit);
}
return s;
}
};
}
项目:ipack
文件:CMSCompressedDataParser.java
/**
* @deprecated use getContent(InputExpandedProvider)
*/
public CMSTypedStream getContent()
throws CMSException
{
try
{
CompressedDataParser comData = new CompressedDataParser((ASN1SequenceParser)_contentInfo.getContent(BERTags.SEQUENCE));
ContentInfoParser content = comData.getEncapContentInfo();
ASN1OctetStringParser bytes = (ASN1OctetStringParser)content.getContent(BERTags.OCTET_STRING);
return new CMSTypedStream(content.getContentType().toString(), new InflaterInputStream(bytes.getOctetStream()));
}
catch (IOException e)
{
throw new CMSException("IOException reading compressed content.", e);
}
}
项目:ipack
文件:CMSCompressedData.java
/**
* Return the uncompressed content.
*
* @return the uncompressed content
* @throws CMSException if there is an exception uncompressing the data.
* @deprecated use getContent(InputExpanderProvider)
*/
public byte[] getContent()
throws CMSException
{
ContentInfo content = comData.getEncapContentInfo();
ASN1OctetString bytes = (ASN1OctetString)content.getContent();
InflaterInputStream zIn = new InflaterInputStream(bytes.getOctetStream());
try
{
return CMSUtils.streamToByteArray(zIn);
}
catch (IOException e)
{
throw new CMSException("exception reading compressed stream.", e);
}
}
项目:ipack
文件:CMSCompressedData.java
/**
* Return the uncompressed content, throwing an exception if the data size
* is greater than the passed in limit. If the content is exceeded getCause()
* on the CMSException will contain a StreamOverflowException
*
* @param limit maximum number of bytes to read
* @return the content read
* @throws CMSException if there is an exception uncompressing the data.
* @deprecated use getContent(InputExpanderProvider)
*/
public byte[] getContent(int limit)
throws CMSException
{
ContentInfo content = comData.getEncapContentInfo();
ASN1OctetString bytes = (ASN1OctetString)content.getContent();
InflaterInputStream zIn = new InflaterInputStream(bytes.getOctetStream());
try
{
return CMSUtils.streamToByteArray(zIn, limit);
}
catch (IOException e)
{
throw new CMSException("exception reading compressed stream.", e);
}
}
项目:AndroidSDK2.0
文件:OfflineByteParser.java
/**
* Unzip byte [ ].
*
* @param buffer the buffer
* @param sizeBeforeCompress the size before compress
* @return the byte [ ]
* @throws IOException the io exception
*/
public static byte[] unzip ( byte[] buffer, int sizeBeforeCompress) throws IOException
{
InflaterInputStream inStream = new InflaterInputStream(new ByteArrayInputStream( buffer));
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
int readByte;
byte[] buf = new byte[1024];
try {
while((readByte = inStream.read(buf)) != -1) {
outStream.write(buf, 0, readByte);
}
// readByte = inStream.read(buf,0, sizeBeforeCompress);
// outStream.write(buf, 0, readByte);
} catch(Exception e)
{
e.printStackTrace();
}
byte[] ret = outStream.toByteArray();
outStream.close();
return ret;
}
项目:spring-web-jsflow
文件:CompressionCodec.java
@Override
public OneWayCodec createDecoder() throws Exception {
return new OneWayCodec() {
private final Inflater inflater = new Inflater();
@Override
public byte[] code(final byte[] data) throws Exception {
inflater.reset();
final InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data), inflater);
final ByteArrayOutputStream out = new ByteArrayOutputStream(data.length * 2);
final byte[] b = new byte[512];
for (;;) {
final int i = in.read(b);
if (i == -1) {
break;
}
out.write(b, 0, i);
}
return out.toByteArray();
}
};
}
项目:EatDubbo
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:cas4.0.x-server-wechat
文件:GoogleAccountsService.java
private static String zlibDeflate(final byte[] bytes) {
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final InflaterInputStream iis = new InflaterInputStream(bais);
final byte[] buf = new byte[1024];
try {
int count = iis.read(buf);
while (count != -1) {
baos.write(buf, 0, count);
count = iis.read(buf);
}
return new String(baos.toByteArray());
} catch (final Exception e) {
return null;
} finally {
IOUtils.closeQuietly(iis);
}
}
项目:LucaHome-AndroidApplication
文件:Tools.java
public static String DecompressByteArrayToString(byte[] bytes) {
InputStream inputStream = new InflaterInputStream(new ByteArrayInputStream(bytes));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[8192];
int length;
while ((length = inputStream.read(buffer)) > 0) {
byteArrayOutputStream.write(buffer, 0, length);
}
return new String(byteArrayOutputStream.toByteArray(), "UTF-8");
} catch (IOException exception) {
Logger.getInstance().Error(TAG, exception.getMessage());
return "";
}
}
项目:dubbo2
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:Cubes_2
文件:SaveAreaIO.java
public static Area read(Save save, int x, int z) {
FileHandle file = file(save, x, z);
if (!file.exists()) {
// Log.warning("Area does not exist");
return null;
}
Inflater inflater = inflaterThreadLocal.get();
try {
inflater.reset();
InputStream inputStream = file.read(8192);
InflaterInputStream inflaterInputStream = new InflaterInputStream(inputStream, inflater);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inflaterInputStream);
DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);
Area area = new Area(x, z);
area.read(dataInputStream);
dataInputStream.close();
return area;
} catch (Exception e) {
Log.error("Failed to read area " + x + "," + z, e);
return null;
}
}
项目:cas-server-4.2.1
文件:CompressionUtils.java
/**
* Decode the byte[] in base64 to a string.
*
* @param bytes the data to encode
* @return the new string in {@link #UTF8_ENCODING}.
*/
public static String decodeByteArrayToString(final byte[] bytes) {
final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final byte[] buf = new byte[bytes.length];
try (final InflaterInputStream iis = new InflaterInputStream(bais)) {
int count = iis.read(buf);
while (count != -1) {
baos.write(buf, 0, count);
count = iis.read(buf);
}
return new String(baos.toByteArray(), Charset.forName(UTF8_ENCODING));
} catch (final Exception e) {
LOGGER.error("Base64 decoding failed", e);
return null;
}
}
项目:lams
文件:HTTPRedirectDeflateDecoder.java
/**
* Base64 decodes the SAML message and then decompresses the message.
*
* @param message Base64 encoded, DEFALTE compressed, SAML message
*
* @return the SAML message
*
* @throws MessageDecodingException thrown if the message can not be decoded
*/
protected InputStream decodeMessage(String message) throws MessageDecodingException {
log.debug("Base64 decoding and inflating SAML message");
byte[] decodedBytes = Base64.decode(message);
if(decodedBytes == null){
log.error("Unable to Base64 decode incoming message");
throw new MessageDecodingException("Unable to Base64 decode incoming message");
}
try {
ByteArrayInputStream bytesIn = new ByteArrayInputStream(decodedBytes);
InflaterInputStream inflater = new InflaterInputStream(bytesIn, new Inflater(true));
return inflater;
} catch (Exception e) {
log.error("Unable to Base64 decode and inflate SAML message", e);
throw new MessageDecodingException("Unable to Base64 decode and inflate SAML message", e);
}
}
项目:Jupiter
文件:Zlib.java
public static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
}
return buffer;
}
项目:Jenisys3
文件:Zlib.java
public static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
}
return buffer;
}
项目:MCPEWorldConverter
文件:Zlib.java
public static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
}
return buffer;
}
项目:dubbox-hystrix
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:Cubes
文件:SaveAreaIO.java
public static Area read(Save save, int x, int z) {
FileHandle file = file(save, x, z);
if (!file.exists()) {
//Log.warning("Area does not exist");
return null;
}
Inflater inflater = inflaterThreadLocal.get();
try {
inflater.reset();
InputStream inputStream = file.read(8192);
InflaterInputStream inflaterInputStream = new InflaterInputStream(inputStream, inflater);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inflaterInputStream);
DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);
Area area = new Area(x, z);
area.read(dataInputStream);
dataInputStream.close();
return area;
} catch (Exception e) {
Log.error("Failed to read area " + x + "," + z, e);
return null;
}
}
项目:android-project-gallery
文件:ZLibUtils.java
/**
* 解压缩
*
* @param is 输入流
* @return byte[] 解压缩后的数据
*/
public static byte[] decompress(InputStream is)
{
InflaterInputStream iis = new InflaterInputStream(is);
ByteArrayOutputStream o = new ByteArrayOutputStream(BUFFER_LENGTH);
try
{
byte[] buf = new byte[BUFFER_LENGTH];
int len = -1;
while ((len = iis.read(buf)) != -1)
{
o.write(buf, 0, len);
}
}
catch (IOException e)
{
e.printStackTrace();
}
return o.toByteArray();
}
项目:zookeeper-sandbox
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:dubbocloud
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:CoreX
文件:Zlib.java
public static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
try {
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
} finally {
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
}
return buffer;
}
项目:itext2
文件:PdfReader.java
/** A helper to FlateDecode.
* @param in the input data
* @param strict <CODE>true</CODE> to read a correct stream. <CODE>false</CODE>
* to try to read a corrupted stream
* @return the decoded data
*/
public static byte[] FlateDecode(byte in[], boolean strict) {
ByteArrayInputStream stream = new ByteArrayInputStream(in);
InflaterInputStream zip = new InflaterInputStream(stream);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte b[] = new byte[strict ? 4092 : 1];
try {
int n;
while ((n = zip.read(b)) >= 0) {
out.write(b, 0, n);
}
zip.close();
out.close();
return out.toByteArray();
}
catch (Exception e) {
if (strict)
return null;
return out.toByteArray();
}
}
项目:Mastering-Mesos
文件:ThriftBinaryCodec.java
/**
* Decodes a thrift object from a DEFLATE-compressed byte array into a target type.
*
* @param clazz Class to instantiate and deserialize to.
* @param buffer Compressed buffer to decode.
* @return A populated message.
* @throws CodingException If the message could not be decoded.
*/
public static <T extends TBase<T, ?>> T inflateNonNull(Class<T> clazz, byte[] buffer)
throws CodingException {
requireNonNull(clazz);
requireNonNull(buffer);
T tBase = newInstance(clazz);
TTransport transport = new TIOStreamTransport(
new InflaterInputStream(new ByteArrayInputStream(buffer)));
try {
TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
tBase.read(protocol);
return tBase;
} catch (TException e) {
throw new CodingException("Failed to deserialize: " + e, e);
} finally {
transport.close();
}
}
项目:dubbos
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:ModEngine
文件:Utils.java
public static String readScriptFile(String path) {
String str = "";
try {
InflaterInputStream infis = new InflaterInputStream(new FileInputStream(path));
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
int buffer;
while ((buffer = infis.read()) != -1) {
baos.write(buffer);
}
infis.close();
baos.close();
str = new String(baos.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
项目:GeoCrawler
文件:DeflateUtils.java
/**
* Returns an inflated copy of the input array.
*
* @throws IOException
* if the input cannot be properly decompressed
*/
public static final byte[] inflate(byte[] in) throws IOException {
// decompress using InflaterInputStream
ByteArrayOutputStream outStream = new ByteArrayOutputStream(
EXPECTED_COMPRESSION_RATIO * in.length);
InflaterInputStream inStream = new InflaterInputStream(
new ByteArrayInputStream(in));
byte[] buf = new byte[BUF_SIZE];
while (true) {
int size = inStream.read(buf);
if (size <= 0)
break;
outStream.write(buf, 0, size);
}
outStream.close();
return outStream.toByteArray();
}
项目:Nemisys
文件:Zlib.java
public static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
return buffer;
}
项目:baratine
文件:BootFile.java
@Override
public InputStream read()
throws IOException
{
Inflater inflater = null;
if (_isCompressed) {
inflater = inflaterAlloc();
}
InputStream is = new BootInputStream(name(), _bootMap, dataOffset(), _sizeCompressed, inflater);
if (! _isCompressed) {
return is;
}
return new InflaterInputStream(is, inflater);
}
项目:dubbo-comments
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:hillview
文件:RpcServer.java
@SuppressWarnings("unused")
@OnMessage
public void onMessage(ByteBuffer message, Session session) {
HillviewLogger.instance.info("New message from client",
"{0}", session.getId());
RpcRequest req;
try {
ByteArrayInputStream stream = new ByteArrayInputStream(message.array());
InflaterInputStream decompressed = new InflaterInputStream(stream);
Reader reader = new InputStreamReader(decompressed);
JsonReader jReader = new JsonReader(reader);
JsonElement elem = Streams.parse(jReader);
HillviewLogger.instance.info("Decoded message", "{0}", elem.toString());
req = new RpcRequest(elem);
if (RpcObjectManager.instance.getTarget(session) != null)
throw new RuntimeException("Session already associated with a request!");
} catch (Exception ex) {
HillviewLogger.instance.error("Error processing json", ex);
this.replyWithError(ex, session);
return;
}
RpcRequestContext context = new RpcRequestContext(session);
RpcServer.execute(req, context);
}
项目:dubbox
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:LucaHome-AndroidApplication
文件:Tools.java
public static String DecompressByteArrayToString(byte[] bytes) {
InputStream inputStream = new InflaterInputStream(new ByteArrayInputStream(bytes));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[8192];
int length;
while ((length = inputStream.read(buffer)) > 0) {
byteArrayOutputStream.write(buffer, 0, length);
}
return new String(byteArrayOutputStream.toByteArray(), "UTF-8");
} catch (IOException exception) {
Logger.getInstance().Error(TAG, exception.getMessage());
return "";
}
}
项目:dubbo
文件:Bytes.java
/**
* unzip.
*
* @param bytes compressed byte array.
* @return byte uncompressed array.
* @throws IOException
*/
public static byte[] unzip(byte[] bytes) throws IOException
{
UnsafeByteArrayInputStream bis = new UnsafeByteArrayInputStream(bytes);
UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
InputStream is = new InflaterInputStream(bis);
try
{
IOUtils.write(is, bos);
return bos.toByteArray();
}
finally
{
is.close();
bis.close();
bos.close();
}
}
项目:NukkitGT
文件:Zlib.java
public static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
return buffer;
}
项目:scaffold
文件:CompressHandler.java
/**
* inflater 解压
*
* @param inputStream
* @return
*/
public static byte[] decompress(InputStream inputStream) {
Closer closer = Closer.create();
try {
BufferedInputStream bufferInputStream = closer.register(new BufferedInputStream(new InflaterInputStream(inputStream, new Inflater(true))));
// bufferInputStream = closer.register(new BufferedInputStream(new GZIPInputStream(inputStream)));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ByteStreams.copy(bufferInputStream, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (Exception e) {
logger.error(String.format("decompress error:"), e);
} finally {
try {
if (closer != null) {
closer.close();
}
} catch (Exception e1) {
logger.error(String.format("decompress error,close the stream error"), e1);
}
}
return null;
}