本文整理汇总了Java中java.util.zip.Deflater.finished方法的典型用法代码示例。如果您正苦于以下问题:Java Deflater.finished方法的具体用法?Java Deflater.finished怎么用?Java Deflater.finished使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.Deflater
的用法示例。
在下文中一共展示了Deflater.finished方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: zipCompression
import java.util.zip.Deflater; //导入方法依赖的package包/类
private String zipCompression(String data) throws UnsupportedEncodingException, IOException {
Deflater zipDeflater = new Deflater();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
zipDeflater.setInput(getBytes(data));
zipDeflater.finish();
byte[] buffer = new byte[1024];
int count = 0;
while (!zipDeflater.finished()) {
count = zipDeflater.deflate(buffer);
stream.write(buffer, 0, count);
}
return new String(Base64.getEncoder().encode(stream.toByteArray()), LOCAL_ENCODING);
} finally {
stream.close();
zipDeflater.end();
}
}
示例2: compress
import java.util.zip.Deflater; //导入方法依赖的package包/类
static byte[] compress(byte[] bytesIn) {
Deflater deflater = new Deflater();
deflater.setInput(bytesIn);
ByteArrayOutputStream stream = new ByteArrayOutputStream(bytesIn.length);
byte[] buffer = new byte[1024];
deflater.finish();
while (!deflater.finished()) {
int count = deflater.deflate(buffer);
stream.write(buffer, 0, count);
}
try {
stream.close();
} catch (IOException ex) {
return bytesIn;
}
byte[] bytesOut = stream.toByteArray();
deflater.end();
return bytesOut;
}
示例3: dumpFlate
import java.util.zip.Deflater; //导入方法依赖的package包/类
/** Write the entire content into the given file using Flate compression (see RFC1951) then return the number of bytes written. */
public long dumpFlate(RandomAccessFile os) throws IOException {
Deflater zip = new Deflater(Deflater.BEST_COMPRESSION);
byte[] output = new byte[8192];
Iterator<byte[]> it = list.iterator(); // when null, that means we have told the Deflater that no more input would be coming
long ans = 0; // the number of bytes written out so far
while(true) {
if (it!=null && zip.needsInput() && it.hasNext()) {
byte[] in = it.next();
if (in == list.getLast()) { zip.setInput(in, 0, n); it=null; zip.finish(); } else { zip.setInput(in, 0, SIZE); }
}
if (it==null && zip.finished()) break;
int count = zip.deflate(output);
if (count > 0) {
ans = ans + count;
if (ans < 0) throw new IOException("Data too large to be written to the output file.");
os.write(output, 0, count);
}
}
return ans;
}
示例4: deflater
import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
* 压缩.
*
* @param inputByte
* 需要解压缩的byte[]数组
* @return 压缩后的数据
* @throws IOException
*/
public static byte[] deflater(final byte[] inputByte) throws IOException {
int compressedDataLength = 0;
Deflater compresser = new Deflater();
compresser.setInput(inputByte);
compresser.finish();
ByteArrayOutputStream o = new ByteArrayOutputStream(inputByte.length);
byte[] result = new byte[1024];
try {
while (!compresser.finished()) {
compressedDataLength = compresser.deflate(result);
o.write(result, 0, compressedDataLength);
}
} finally {
o.close();
}
compresser.end();
return o.toByteArray();
}
示例5: zlibCompress
import java.util.zip.Deflater; //导入方法依赖的package包/类
public DataStream zlibCompress() {
Deflater compressor = new Deflater();
compressor.setInput(this.get());
this.reset();
this.put(Hex.toByteArray("0178040000")); // size?!
byte[] buf = new byte[1024];
int length = 0;
compressor.finish();
while (!compressor.finished()) {
int count = compressor.deflate(buf);
this.put(buf, 0, count);
length += count;
}
compressor.end();
return this;
}
示例6: compress
import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] compress(byte[] value, int offset, int length, int compressionLevel) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
Deflater compressor = new Deflater();
try {
compressor.setLevel(compressionLevel); // 将当前压缩级别设置为指定值。
compressor.setInput(value, offset, length);
compressor.finish(); // 调用时,指示压缩应当以输入缓冲区的当前内容结尾。
// Compress the data
final byte[] buf = new byte[1024];
while (!compressor.finished()) {
// 如果已到达压缩数据输出流的结尾,则返回 true。
int count = compressor.deflate(buf);
// 使用压缩数据填充指定缓冲区。
bos.write(buf, 0, count);
}
} finally {
compressor.end(); // 关闭解压缩器并放弃所有未处理的输入。
}
return bos.toByteArray();
}
示例7: compress
import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
* 压缩
*
* @param data 待压缩的数据
* @return
*/
public static byte[] compress(byte[] data)
{
Deflater deflater = new Deflater();
deflater.setInput(data);
deflater.finish();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[BUFFER_LENGTH];
while (!deflater.finished())
{
int byteCount = deflater.deflate(buf);
baos.write(buf, 0, byteCount);
}
deflater.end();
byte[] compressedBytes = baos.toByteArray();
return compressedBytes;
}
示例8: compress
import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] compress(byte input[]) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Deflater compressor = new Deflater(1);
try {
compressor.setInput(input);
compressor.finish();
final byte[] buf = new byte[2048];
while (!compressor.finished()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
} finally {
compressor.end();
}
return bos.toByteArray();
}
示例9: getDeflated
import java.util.zip.Deflater; //导入方法依赖的package包/类
protected byte[] getDeflated(String s) {
byte[] content = s.getBytes();
ByteArrayOutputStream output = new ByteArrayOutputStream(content.length);
Deflater deflater = new Deflater();
deflater.setInput(content);
deflater.finish();
byte[] buffer = new byte[1024];
while (!deflater.finished()) {
int count = deflater.deflate(buffer);
output.write(buffer, 0, count);
}
return output.toByteArray();
}
示例10: deflate
import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] deflate(byte[] data, int level) throws Exception {
Deflater deflater = new Deflater(level);
deflater.reset();
deflater.setInput(data);
deflater.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
byte[] buf = new byte[1024];
try {
while (!deflater.finished()) {
int i = deflater.deflate(buf);
bos.write(buf, 0, i);
}
} finally {
deflater.end();
bos.close();
}
return bos.toByteArray();
}
示例11: storeData
import java.util.zip.Deflater; //导入方法依赖的package包/类
private void storeData(ByteBuffer data) {
try {
final byte[] input = data.array();
FileOutputStream fos = new FileOutputStream(file);
final Deflater deflater = new Deflater(Deflater.BEST_SPEED, true);
deflater.setInput(input, data.arrayOffset(), data.remaining());
deflater.finish();
byte[] buf = new byte[1024];
while (!deflater.finished()) {
int byteCount = deflater.deflate(buf);
fos.write(buf, 0, byteCount);
}
deflater.end();
fos.close();
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
示例12: compress
import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] compress(byte[] value, int offset, int length, int compressionLevel)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(length);
Deflater compressor = new Deflater();
try
{
compressor.setLevel(compressionLevel); // 将当前压缩级别设置为指定值。
compressor.setInput(value, offset, length);
compressor.finish(); // 调用时,指示压缩应当以输入缓冲区的当前内容结尾。
// Compress the data
final byte[] buf = new byte[1024];
while (!compressor.finished())
{
// 如果已到达压缩数据输出流的结尾,则返回 true。
int count = compressor.deflate(buf);
// 使用压缩数据填充指定缓冲区。
bos.write(buf, 0, count);
}
} finally
{
compressor.end(); // 关闭解压缩器并放弃所有未处理的输入。
}
return bos.toByteArray();
}
示例13: deflate
import java.util.zip.Deflater; //导入方法依赖的package包/类
public static DeflateResult deflate(ByteBuffer input) {
byte[] inputBuf;
int inputOffset;
int inputLength = input.remaining();
if (input.hasArray()) {
inputBuf = input.array();
inputOffset = input.arrayOffset() + input.position();
input.position(input.limit());
} else {
inputBuf = new byte[inputLength];
inputOffset = 0;
input.get(inputBuf);
}
CRC32 crc32 = new CRC32();
crc32.update(inputBuf, inputOffset, inputLength);
long crc32Value = crc32.getValue();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Deflater deflater = new Deflater(9, true);
deflater.setInput(inputBuf, inputOffset, inputLength);
deflater.finish();
byte[] buf = new byte[65536];
while (!deflater.finished()) {
int chunkSize = deflater.deflate(buf);
out.write(buf, 0, chunkSize);
}
return new DeflateResult(inputLength, crc32Value, out.toByteArray());
}
示例14: deflate
import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] deflate(byte[] data, int level) throws Exception {
Deflater deflater = getDef(level);
if (deflater == null) throw new IllegalArgumentException("No deflate for level " + level + " !");
deflater.reset();
deflater.setInput(data);
deflater.finish();
ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
while (!deflater.finished()) {
int i = deflater.deflate(buf.get());
bos.write(buf.get(), 0, i);
}
//Deflater::end is called the time when the process exits.
return bos.toByteArray();
}
示例15: binaryEncode
import java.util.zip.Deflater; //导入方法依赖的package包/类
private String binaryEncode(String tag) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Deflater deflater = new Deflater();
deflater.setInput(tag.getBytes());
deflater.finish();
byte[] buffer = new byte[1024];
while (!deflater.finished()) {
int count = deflater.deflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
byte compressed[] = outputStream.toByteArray();
return bytesToHex(compressed);
}