本文整理汇总了Java中java.util.zip.InflaterInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java InflaterInputStream.read方法的具体用法?Java InflaterInputStream.read怎么用?Java InflaterInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.InflaterInputStream
的用法示例。
在下文中一共展示了InflaterInputStream.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
};
}
示例3: 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);
}
}
示例4: 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;
}
示例5: decompress
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
/**
* 解压缩
*
* @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();
}
示例6: FlateDecode
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
/** 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();
}
}
示例7: readScriptFile
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
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;
}
示例8: inflate
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
/**
* 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();
}
示例9: 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;
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
buffer = outputStream.toByteArray();
outputStream.flush();
outputStream.close();
inputStream.close();
return buffer;
}
示例10: read
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
private byte[] read(byte[] data, int pos) throws IOException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream bis = new ByteArrayInputStream(data);
Header header = new Header();
header.read(data, pos);
bis.skip(pos + header.getSize());
InflaterInputStream inflater = new InflaterInputStream(bis);
byte[] chunk = new byte[4096];
int count;
while ((count = inflater.read(chunk)) >= 0)
{
out.write(chunk, 0, count);
}
inflater.close();
return out.toByteArray();
}
示例11: inflatePictureData
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
/**
* Decompresses the provided data, returning the inflated result.
*
* @param data the deflated picture data.
* @return the inflated picture data.
*/
private static byte[] inflatePictureData(byte[] data) {
try {
InflaterInputStream in = new InflaterInputStream(
new ByteArrayInputStream( data ) );
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
int readBytes;
while ((readBytes = in.read(buf)) > 0) {
out.write(buf, 0, readBytes);
}
return out.toByteArray();
} catch (IOException e) {
log.log(POILogger.WARN, "Possibly corrupt compression or non-compressed data", e);
return data;
}
}
示例12: decompress
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
/**
* Decompresses a byte array.
*
* @param data The compressed byte array
* @param pos The starting position into the byte array
* @param length The number of compressed bytes to decompress
* @return An uncompressed byte array
* @see InflaterInputStream#read
*/
public static byte[] decompress( byte[] data, int pos, int length )
{
byte[] compressedData = new byte[length];
System.arraycopy( data, pos + 50, compressedData, 0, length );
InputStream compressedInputStream = new ByteArrayInputStream( compressedData );
InflaterInputStream inflaterInputStream = new InflaterInputStream( compressedInputStream );
ByteArrayOutputStream out = new ByteArrayOutputStream();
int c;
try
{
while ( ( c = inflaterInputStream.read() ) != -1 )
out.write( c );
}
catch ( IOException e )
{
throw new RecordFormatException( e.toString() );
}
return out.toByteArray();
}
示例13: writeTempFile
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
public String writeTempFile(InflaterInputStream in)
{
String name = String.valueOf(System.currentTimeMillis()) + ".tmp";
File file = new File(picTempPath + File.separator + name);
try
{
file.createNewFile();
FileOutputStream out = new FileOutputStream(file);
byte[] buf = new byte[4096];
int readBytes;
while ((readBytes = in.read(buf)) > 0)
{
out.write(buf, 0, readBytes);
}
}
catch (Exception e)
{
control.getSysKit().getErrorKit().writerLog(e);
}
return file.getAbsolutePath();
}
示例14: inflate
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
private static byte[] inflate(InputStream stream) throws IOException {
InflaterInputStream inputStream = new InflaterInputStream(stream);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
int length;
try {
while ((length = inputStream.read(buf.get())) != -1) {
outputStream.write(buf.get(), 0, length);
}
} finally {
buf.set(outputStream.toByteArray());
outputStream.flush();
outputStream.close();
inputStream.close();
}
return buf.get();
}
示例15: unzip
import java.util.zip.InflaterInputStream; //导入方法依赖的package包/类
/** 从zlib解压
* @throws IOException */
private static byte[] unzip(byte[] ziped) throws IOException {
InflaterInputStream iis = new InflaterInputStream(new ByteArrayInputStream(ziped));
ByteArrayOutputStream o = new ByteArrayOutputStream(1024);
int i = 1024;
byte[] buf = new byte[i];
while ((i = iis.read(buf, 0, i)) > 0) {
o.write(buf, 0, i);
}
return o.toByteArray();
}