本文整理汇总了Java中java.util.zip.InflaterInputStream类的典型用法代码示例。如果您正苦于以下问题:Java InflaterInputStream类的具体用法?Java InflaterInputStream怎么用?Java InflaterInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InflaterInputStream类属于java.util.zip包,在下文中一共展示了InflaterInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decodeByteArrayToString
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
/**
* 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;
}
}
示例2: decodeByteArrayToString
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
/**
* 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;
}
}
示例3: decodeByteArrayToString
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
/**
* 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;
}
}
示例4: decode
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
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);
}
}
示例5: get
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
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;
}
};
}
示例6: getContent
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
/**
* @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);
}
}
示例7: getContent
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
/**
* 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);
}
}
示例8: unzip
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
/**
* 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;
}
示例9: createDecoder
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
@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();
}
};
}
示例10: unzip
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
/**
* 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();
}
}
示例11: zlibDeflate
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
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);
}
}
示例12: DecompressByteArrayToString
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
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 "";
}
}
示例13: read
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
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;
}
}
示例14: decodeMessage
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
/**
* 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);
}
}
示例15: inflate
import java.util.zip.InflaterInputStream; //导入依赖的package包/类
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;
}