本文整理汇总了Java中java.util.zip.Inflater.needsInput方法的典型用法代码示例。如果您正苦于以下问题:Java Inflater.needsInput方法的具体用法?Java Inflater.needsInput怎么用?Java Inflater.needsInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.Inflater
的用法示例。
在下文中一共展示了Inflater.needsInput方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readChunkUnzip
import java.util.zip.Inflater; //导入方法依赖的package包/类
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
try {
do {
int read = inflater.inflate(buffer, offset, length);
if(read <= 0) {
if(inflater.finished()) {
throw new EOFException();
}
if(inflater.needsInput()) {
refillInflater(inflater);
} else {
throw new IOException("Can't inflate " + length + " bytes");
}
} else {
offset += read;
length -= read;
}
} while(length > 0);
} catch (DataFormatException ex) {
throw (IOException)(new IOException("inflate error").initCause(ex));
}
}
示例2: uncompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) throws IOException
{
Inflater inf = inflater.get();
inf.reset();
inf.setInput(input, inputOffset, inputLength);
if (inf.needsInput())
return 0;
// We assume output is big enough
try
{
return inf.inflate(output, outputOffset, maxOutputLength);
}
catch (DataFormatException e)
{
throw new IOException(e);
}
}
示例3: readChunkUnzip
import java.util.zip.Inflater; //导入方法依赖的package包/类
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
assert(buffer != this.buffer);
try {
do {
int read = inflater.inflate(buffer, offset, length);
if(read <= 0) {
if(inflater.finished()) {
throw new EOFException();
}
if(inflater.needsInput()) {
refillInflater(inflater);
} else {
throw new IOException("Can't inflate " + length + " bytes");
}
} else {
offset += read;
length -= read;
}
} while(length > 0);
} catch (DataFormatException ex) {
throw (IOException)(new IOException("inflate error").initCause(ex));
}
}
示例4: b
import java.util.zip.Inflater; //导入方法依赖的package包/类
public static byte[] b(byte[] bArr) throws UnsupportedEncodingException, DataFormatException {
int i = 0;
if (bArr == null || bArr.length == 0) {
return null;
}
Inflater inflater = new Inflater();
inflater.setInput(bArr, 0, bArr.length);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] bArr2 = new byte[1024];
while (!inflater.needsInput()) {
int inflate = inflater.inflate(bArr2);
byteArrayOutputStream.write(bArr2, i, inflate);
i += inflate;
}
inflater.end();
return byteArrayOutputStream.toByteArray();
}
示例5: uncompressBytes
import java.util.zip.Inflater; //导入方法依赖的package包/类
public static DeflaterInflaterData uncompressBytes(byte[] output, int compressedDataLength)
throws DataFormatException {
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0, compressedDataLength);
byte[] buffer = new byte[512];
byte[] result = new byte[0];
int bytesRead;
while (!decompresser.needsInput()) {
bytesRead = decompresser.inflate(buffer);
byte[] newResult = new byte[result.length + bytesRead];
System.arraycopy(result, 0, newResult, 0, result.length);
System.arraycopy(buffer, 0, newResult, result.length, bytesRead);
result = newResult;
}
// System.out.println(new String(result));
decompresser.end();
return new DeflaterInflaterData(result.length, result);
}
示例6: decompressForZlib
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* zlib decompress 2 byte
*
* @param bytesToDecompress byte[]
* @return byte[]
*/
public static byte[] decompressForZlib(byte[] bytesToDecompress) {
byte[] returnValues = null;
Inflater inflater = new Inflater();
int numberOfBytesToDecompress = bytesToDecompress.length;
inflater.setInput(bytesToDecompress, 0, numberOfBytesToDecompress);
int numberOfBytesDecompressedSoFar = 0;
List<Byte> bytesDecompressedSoFar = new ArrayList<>();
try {
while (!inflater.needsInput()) {
byte[] bytesDecompressedBuffer = new byte[numberOfBytesToDecompress];
int numberOfBytesDecompressedThisTime = inflater.inflate(bytesDecompressedBuffer);
numberOfBytesDecompressedSoFar += numberOfBytesDecompressedThisTime;
for (int b = 0; b < numberOfBytesDecompressedThisTime; b++) {
bytesDecompressedSoFar.add(bytesDecompressedBuffer[b]);
}
}
returnValues = new byte[bytesDecompressedSoFar.size()];
for (int b = 0; b < returnValues.length; b++) {
returnValues[b] = (byte) (bytesDecompressedSoFar.get(b));
}
} catch (DataFormatException dfe) {
dfe.printStackTrace();
}
inflater.end();
return returnValues;
}
示例7: getData
import java.util.zip.Inflater; //导入方法依赖的package包/类
public ByteBuffer getData() {
try {
byte[] input = new byte[1024];
byte[] output = new byte[1024];
FileInputStream fin = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Inflater inflater = new Inflater(true);
while (true) {
int numRead = fin.read(input);
if (numRead != -1) {
inflater.setInput(input, 0, numRead);
}
int numDecompressed;
while ((numDecompressed = inflater.inflate(output, 0, output.length)) != 0) {
bos.write(output, 0, numDecompressed);
}
if (inflater.finished()) {
break;
}
else if (inflater.needsInput()) {
continue;
}
}
inflater.end();
ByteBuffer result = ByteBuffer.wrap(bos.toByteArray(), 0, bos.size());
bos.close();
fin.close();
return result;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return null;
}
示例8: decompressForZlib
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* zlib decompress 2 byte
*
* @param bytesToDecompress
* @return
*/
public static byte[] decompressForZlib(byte[] bytesToDecompress) {
byte[] returnValues = null;
Inflater inflater = new Inflater();
int numberOfBytesToDecompress = bytesToDecompress.length;
inflater.setInput(bytesToDecompress, 0, numberOfBytesToDecompress);
int numberOfBytesDecompressedSoFar = 0;
List<Byte> bytesDecompressedSoFar = new ArrayList<>();
try {
while (!inflater.needsInput()) {
byte[] bytesDecompressedBuffer = new byte[numberOfBytesToDecompress];
int numberOfBytesDecompressedThisTime = inflater.inflate(bytesDecompressedBuffer);
numberOfBytesDecompressedSoFar += numberOfBytesDecompressedThisTime;
for (int b = 0; b < numberOfBytesDecompressedThisTime; b++) {
bytesDecompressedSoFar.add(bytesDecompressedBuffer[b]);
}
}
returnValues = new byte[bytesDecompressedSoFar.size()];
for (int b = 0; b < returnValues.length; b++) {
returnValues[b] = (byte) (bytesDecompressedSoFar.get(b));
}
} catch (DataFormatException dfe) {
dfe.printStackTrace();
}
inflater.end();
return returnValues;
}
示例9: decompressForZlib
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* zlib decompress 2 byte
*
* @param bytesToDecompress
* @return
*/
public static byte[] decompressForZlib(byte[] bytesToDecompress) {
byte[] returnValues = null;
Inflater inflater = new Inflater();
int numberOfBytesToDecompress = bytesToDecompress.length;
inflater.setInput
(
bytesToDecompress,
0,
numberOfBytesToDecompress
);
int bufferSizeInBytes = numberOfBytesToDecompress;
int numberOfBytesDecompressedSoFar = 0;
List<Byte> bytesDecompressedSoFar = new ArrayList<Byte>();
try {
while (inflater.needsInput() == false) {
byte[] bytesDecompressedBuffer = new byte[bufferSizeInBytes];
int numberOfBytesDecompressedThisTime = inflater.inflate
(
bytesDecompressedBuffer
);
numberOfBytesDecompressedSoFar += numberOfBytesDecompressedThisTime;
for (int b = 0; b < numberOfBytesDecompressedThisTime; b++) {
bytesDecompressedSoFar.add(bytesDecompressedBuffer[b]);
}
}
returnValues = new byte[bytesDecompressedSoFar.size()];
for (int b = 0; b < returnValues.length; b++) {
returnValues[b] = (byte) (bytesDecompressedSoFar.get(b));
}
} catch (DataFormatException dfe) {
dfe.printStackTrace();
}
inflater.end();
return returnValues;
}
示例10: decompressForZlib
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* zlib decompress 2 byte
*
* @param bytesToDecompress
* @return
*/
public static byte[] decompressForZlib(byte[] bytesToDecompress) {
byte[] returnValues = null;
Inflater inflater = new Inflater();
int numberOfBytesToDecompress = bytesToDecompress.length;
inflater.setInput
(bytesToDecompress, 0, numberOfBytesToDecompress);
int bufferSizeInBytes = numberOfBytesToDecompress;
int numberOfBytesDecompressedSoFar = 0;
List<Byte> bytesDecompressedSoFar = new ArrayList<Byte>();
try {
while (inflater.needsInput() == false) {
byte[] bytesDecompressedBuffer = new byte[bufferSizeInBytes];
int numberOfBytesDecompressedThisTime = inflater.inflate(bytesDecompressedBuffer);
numberOfBytesDecompressedSoFar += numberOfBytesDecompressedThisTime;
for (int b = 0; b < numberOfBytesDecompressedThisTime; b++) {
bytesDecompressedSoFar.add(bytesDecompressedBuffer[b]);
}
}
returnValues = new byte[bytesDecompressedSoFar.size()];
for (int b = 0; b < returnValues.length; b++) {
returnValues[b] = (byte) (bytesDecompressedSoFar.get(b));
}
} catch (DataFormatException dfe) {
dfe.printStackTrace();
}
inflater.end();
return returnValues;
}
示例11: decompressForZlib
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* zlib decompress 2 byte
*
* @param bytesToDecompress
* @return
*/
public static byte[] decompressForZlib(byte[] bytesToDecompress) {
byte[] returnValues = null;
Inflater inflater = new Inflater();
int numberOfBytesToDecompress = bytesToDecompress.length;
inflater.setInput(
bytesToDecompress,
0,
numberOfBytesToDecompress);
int bufferSizeInBytes = numberOfBytesToDecompress;
int numberOfBytesDecompressedSoFar = 0;
List<Byte> bytesDecompressedSoFar = new ArrayList<Byte>();
try {
while (inflater.needsInput() == false) {
byte[] bytesDecompressedBuffer = new byte[bufferSizeInBytes];
int numberOfBytesDecompressedThisTime = inflater.inflate(
bytesDecompressedBuffer);
numberOfBytesDecompressedSoFar += numberOfBytesDecompressedThisTime;
for (int b = 0; b < numberOfBytesDecompressedThisTime; b++) {
bytesDecompressedSoFar.add(bytesDecompressedBuffer[b]);
}
}
returnValues = new byte[bytesDecompressedSoFar.size()];
for (int b = 0; b < returnValues.length; b++) {
returnValues[b] = (byte) (bytesDecompressedSoFar.get(b));
}
} catch (DataFormatException dfe) {
dfe.printStackTrace();
}
inflater.end();
return returnValues;
}