本文整理汇总了Java中java.util.zip.Inflater.finished方法的典型用法代码示例。如果您正苦于以下问题:Java Inflater.finished方法的具体用法?Java Inflater.finished怎么用?Java Inflater.finished使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.Inflater
的用法示例。
在下文中一共展示了Inflater.finished方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getZipString
import java.util.zip.Inflater; //导入方法依赖的package包/类
public String getZipString() {
int length = getBInt() - 4;
int zlength = getLInt();
if (remaining() > length) {
Inflater decompressor = new Inflater();
decompressor.setInput(buffer, offset, length);
offset += length;
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream(zlength);
byte[] buf = new byte[1024];
int count;
while ((!decompressor.finished()) && ((count = decompressor.inflate(buf)) > 0)) {
bos.write(buf, 0, count);
}
decompressor.end();
bos.close();
return new String(bos.toByteArray(), UTF8_CHARSET);
} catch (DataFormatException | IOException ignored) {
}
}
return null;
}
示例2: decompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
public static byte[] decompress(byte[] value) throws DataFormatException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);
Inflater decompressor = new Inflater();
try
{
decompressor.setInput(value);
final byte[] buf = new byte[1024];
while (!decompressor.finished())
{
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
} finally
{
decompressor.end();
}
return bos.toByteArray();
}
示例3: inflater
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* 解压缩.
*
* @param inputByte
* byte[]数组类型的数据
* @return 解压缩后的数据
* @throws IOException
*/
public static byte[] inflater(final byte[] inputByte) throws IOException {
int compressedDataLength = 0;
Inflater compresser = new Inflater(false);
compresser.setInput(inputByte, 0, inputByte.length);
ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
byte[] result = new byte[1024];
try {
while (!compresser.finished()) {
compressedDataLength = compresser.inflate(result);
if (compressedDataLength == 0) {
break;
}
o.write(result, 0, compressedDataLength);
}
} catch (Exception ex) {
System.err.println("Data format error!\n");
ex.printStackTrace();
} finally {
o.close();
}
compresser.end();
return o.toByteArray();
}
示例4: decompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
static byte[] decompress(byte[] bytesIn, int offset) throws Exception {
Inflater inflater = new Inflater();
inflater.setInput(bytesIn, offset, bytesIn.length - offset);
ByteArrayOutputStream stream = new ByteArrayOutputStream(bytesIn.length - offset);
byte[] buffer = new byte[1024];
while (!inflater.finished()) {
int count = inflater.inflate(buffer);
stream.write(buffer, 0, count);
}
stream.close();
byte[] bytesOut = stream.toByteArray();
inflater.end();
return bytesOut;
}
示例5: inflater
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* 解压缩.
*
* @param inputByte byte[]数组类型的数据
* @return 解压缩后的数据
* @throws IOException
*/
public static byte[] inflater(final byte[] inputByte) throws IOException {
int compressedDataLength = 0;
Inflater compresser = new Inflater(false);
compresser.setInput(inputByte, 0, inputByte.length);
ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
byte[] result = new byte[1024];
try {
while (!compresser.finished()) {
compressedDataLength = compresser.inflate(result);
if (compressedDataLength == 0) {
break;
}
o.write(result, 0, compressedDataLength);
}
} catch (Exception ex) {
System.err.println("Data format error!\n");
ex.printStackTrace();
} finally {
o.close();
}
compresser.end();
return o.toByteArray();
}
示例6: deflate
import java.util.zip.Inflater; //导入方法依赖的package包/类
/** Descomprime un certificado contenido en la tarjeta CERES.
* @param compressedCertificate Certificado comprimido en ZIP a partir del 9 octeto.
* @return Certificado codificado.
* @throws IOException Cuando se produce un error en la descompresión del certificado. */
private static byte[] deflate(final byte[] compressedCertificate) throws IOException {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final Inflater decompressor = new Inflater();
decompressor.setInput(compressedCertificate, 8, compressedCertificate.length - 8);
final byte[] buf = new byte[1024];
try {
// Descomprimimos los datos
while (!decompressor.finished()) {
final int count = decompressor.inflate(buf);
if (count == 0) {
throw new DataFormatException();
}
buffer.write(buf, 0, count);
}
// Obtenemos los datos descomprimidos
return buffer.toByteArray();
}
catch (final DataFormatException ex) {
throw new IOException("Error al descomprimir el certificado: " + ex, ex); //$NON-NLS-1$
}
}
示例7: inflate
import java.util.zip.Inflater; //导入方法依赖的package包/类
/**
* Inflate the given byte array by {@link #INFLATED_ARRAY_LENGTH}.
*
* @param bytes the bytes
* @return the array as a string with {@code UTF-8} encoding
*/
public static String inflate(final byte[] bytes) {
final Inflater inflater = new Inflater(true);
final byte[] xmlMessageBytes = new byte[INFLATED_ARRAY_LENGTH];
final byte[] extendedBytes = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, extendedBytes, 0, bytes.length);
extendedBytes[bytes.length] = 0;
inflater.setInput(extendedBytes);
try {
final int resultLength = inflater.inflate(xmlMessageBytes);
inflater.end();
if (!inflater.finished()) {
throw new RuntimeException("buffer not large enough.");
}
inflater.end();
return new String(xmlMessageBytes, 0, resultLength, StandardCharsets.UTF_8);
} catch (final DataFormatException e) {
return null;
}
}
示例8: 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));
}
}
示例9: onMessage
import java.util.zip.Inflater; //导入方法依赖的package包/类
@Override
public void onMessage(ByteBuffer message) {
try {
//Thanks to ShadowLordAlpha for code and debugging.
//Get the compressed message and inflate it
StringBuilder builder = new StringBuilder();
Inflater decompresser = new Inflater();
byte[] bytes = message.array();
decompresser.setInput(bytes, 0, bytes.length);
byte[] result = new byte[128];
while (!decompresser.finished()) {
int resultLength = decompresser.inflate(result);
builder.append(new String(result, 0, resultLength, "UTF-8"));
}
decompresser.end();
// send the inflated message to the TextMessage method
onMessage(builder.toString());
} catch (DataFormatException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
示例10: uncompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
public static byte[] uncompress(byte[] input) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Inflater decompressor = new Inflater();
try {
decompressor.setInput(input);
final byte[] buf = new byte[2048];
while (!decompressor.finished()) {
int count = 0;
try {
count = decompressor.inflate(buf);
} catch (DataFormatException e) {
e.printStackTrace();
}
bos.write(buf, 0, count);
}
} finally {
decompressor.end();
}
return bos.toByteArray();
}
示例11: decodeURLBase64DeflateString
import java.util.zip.Inflater; //导入方法依赖的package包/类
private String decodeURLBase64DeflateString(final String input)
throws UnsupportedEncodingException, DataFormatException {
String urlDecoded = URLDecoder.decode(input, "UTF-8");
byte[] base64Decoded = Base64.decodeBase64(urlDecoded);
Inflater decompresser = new Inflater(true);
decompresser.setInput(base64Decoded);
StringBuilder result = new StringBuilder();
while (!decompresser.finished()) {
byte[] outputFraction = new byte[base64Decoded.length];
int resultLength = decompresser.inflate(outputFraction);
result.append(new String(outputFraction, 0, resultLength, "UTF-8"));
}
return result.toString();
}
示例12: deflate
import java.util.zip.Inflater; //导入方法依赖的package包/类
/** Descomprime un certificado contenido en el DNIe.
* @param compressedCertificate Certificado comprimido en ZIP a partir del 9 byte.
* @return Certificado codificado.
* @throws IOException Cuando se produce un error en la descompresion del certificado. */
private static byte[] deflate(final byte[] compressedCertificate) throws IOException {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final Inflater decompressor = new Inflater();
decompressor.setInput(compressedCertificate, 8, compressedCertificate.length - 8);
final byte[] buf = new byte[1024];
try {
// Descomprimimos los datos
while (!decompressor.finished()) {
final int count = decompressor.inflate(buf);
if (count == 0) {
throw new DataFormatException();
}
buffer.write(buf, 0, count);
}
// Obtenemos los datos descomprimidos
return buffer.toByteArray();
}
catch (final DataFormatException ex) {
throw new IOException("Error al descomprimir el certificado: " + ex, ex); //$NON-NLS-1$
}
}
示例13: uncompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
@Override
public byte[] uncompress(byte[] data) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Inflater decompressor = new Inflater();
try {
decompressor.setInput(data);
final byte[] buf = new byte[2048];
while (!decompressor.finished()) {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
} catch (DataFormatException e) {
e.printStackTrace();
} finally {
decompressor.end();
}
return bos.toByteArray();
}
示例14: uncompress
import java.util.zip.Inflater; //导入方法依赖的package包/类
public static byte[] uncompress(final byte[] input) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Inflater decompressor = new Inflater();
try {
decompressor.setInput(input);
final byte[] buf = new byte[2048];
while (!decompressor.finished()) {
int count = 0;
try {
count = decompressor.inflate(buf);
} catch (DataFormatException e) {
e.printStackTrace();
}
bos.write(buf, 0, count);
}
} finally {
decompressor.end();
}
return bos.toByteArray();
}
示例15: 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;
}