本文整理汇总了Java中java.util.zip.Deflater.end方法的典型用法代码示例。如果您正苦于以下问题:Java Deflater.end方法的具体用法?Java Deflater.end怎么用?Java Deflater.end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.zip.Deflater
的用法示例。
在下文中一共展示了Deflater.end方法的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: 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();
}
示例3: 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();
}
return bos.toByteArray();
}
示例4: 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();
}
示例5: 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();
}
示例6: compress
import java.util.zip.Deflater; //导入方法依赖的package包/类
public static byte[] compress(byte[] input) throws IOException
{
// Destination where compressed data will be stored.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Create a compressor.
Deflater deflater = createDeflater();
DeflaterOutputStream dos = new DeflaterOutputStream(baos, deflater);
// Compress the data.
//
// Some other implementations such as Jetty and Tyrus use
// Deflater.deflate(byte[], int, int, int) with Deflate.SYNC_FLUSH,
// but this implementation does not do it intentionally because the
// method and the constant value are not available before Java 7.
dos.write(input, 0, input.length);
dos.close();
// Release the resources held by the compressor.
deflater.end();
// Retrieve the compressed data.
return baos.toByteArray();
}
示例7: compress
import java.util.zip.Deflater; //导入方法依赖的package包/类
@Override
public byte[] compress(byte[] data) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Deflater compressor = new Deflater(1);
try {
compressor.setInput(data);
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();
}
示例8: 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;
}
示例9: write
import java.util.zip.Deflater; //导入方法依赖的package包/类
@Override
public final void write(DataOutput out) throws IOException {
if (compressed == null) {
ByteArrayOutputStream deflated = new ByteArrayOutputStream();
Deflater deflater = new Deflater(Deflater.BEST_SPEED);
DataOutputStream dout =
new DataOutputStream(new DeflaterOutputStream(deflated, deflater));
writeCompressed(dout);
dout.close();
deflater.end();
compressed = deflated.toByteArray();
}
out.writeInt(compressed.length);
out.write(compressed);
}
示例10: getUserSig
import java.util.zip.Deflater; //导入方法依赖的package包/类
@Override
public String getUserSig(String identifier, long expire)throws QCloudException {
try {
Security.addProvider(new BouncyCastleProvider());
Reader reader = new CharArrayReader(imConfig.getPrivateKey().toCharArray());
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
PEMParser parser = new PEMParser(reader);
Object obj = parser.readObject();
parser.close();
PrivateKey privKeyStruct = converter.getPrivateKey((PrivateKeyInfo) obj);
String jsonString = "{"
+ "\"TLS.account_type\":\"" + 0 +"\","
+"\"TLS.identifier\":\"" + identifier +"\","
+"\"TLS.appid_at_3rd\":\"" + 0 +"\","
+"\"TLS.sdk_appid\":\"" + imConfig.getSdkAppId() +"\","
+"\"TLS.expire_after\":\"" + expire +"\","
+"\"TLS.version\": \"201512300000\""
+"}";
String time = String.valueOf(System.currentTimeMillis()/1000);
String SerialString =
"TLS.appid_at_3rd:" + 0 + "\n" +
"TLS.account_type:" + 0 + "\n" +
"TLS.identifier:" + identifier + "\n" +
"TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" +
"TLS.time:" + time + "\n" +
"TLS.expire_after:" + expire +"\n";
//Create Signature by SerialString
Signature signature = Signature.getInstance("SHA256withECDSA", "BC");
signature.initSign(privKeyStruct);
signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
byte[] signatureBytes = signature.sign();
String sigTLS = Base64.encodeBase64String(signatureBytes);
//Add TlsSig to jsonString
JSONObject jsonObject= JSON.parseObject(jsonString);
jsonObject.put("TLS.sig", (Object)sigTLS);
jsonObject.put("TLS.time", (Object)time);
jsonString = jsonObject.toString();
//compression
Deflater compresser = new Deflater();
compresser.setInput(jsonString.getBytes(Charset.forName("UTF-8")));
compresser.finish();
byte [] compressBytes = new byte [512];
int compressBytesLength = compresser.deflate(compressBytes);
compresser.end();
return new String(Base64Url.base64EncodeUrl(Arrays.copyOfRange(compressBytes,0,compressBytesLength)));
}catch (Exception e) {
throw new QCloudException(e);
}
}
示例11: serialize
import java.util.zip.Deflater; //导入方法依赖的package包/类
static byte[] serialize(final FunctionNode fn) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final Deflater deflater = new Deflater(COMPRESSION_LEVEL);
try (final ObjectOutputStream oout = new ObjectOutputStream(new DeflaterOutputStream(out, deflater))) {
oout.writeObject(removeInnerFunctionBodies(fn));
} catch (final IOException e) {
throw new AssertionError("Unexpected exception serializing function", e);
} finally {
deflater.end();
}
return out.toByteArray();
}
示例12: releaseDeflater
import java.util.zip.Deflater; //导入方法依赖的package包/类
private void releaseDeflater(Deflater def) {
synchronized (deflaters) {
if (inflaters.size() < MAX_FLATER) {
def.reset();
deflaters.add(def);
} else {
def.end();
}
}
}
示例13: _zipToBytes
import java.util.zip.Deflater; //导入方法依赖的package包/类
/**
* Returned the zipped version of the viewState
*/
private byte[] _zipToBytes(Object viewState)
{
Deflater compresser = new Deflater(Deflater.BEST_SPEED);
try
{
//Serialize state
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(viewState);
oos.flush();
oos.close();
byte[] ret = baos.toByteArray();
compresser.setInput(ret);
compresser.finish();
baos.reset();
byte[] buf = new byte[ret.length/5];
while (!compresser.finished())
{
int count = compresser.deflate(buf);
baos.write(buf, 0, count);
}
return baos.toByteArray();
}
catch (IOException e)
{
throw new RuntimeException(_LOG.getMessage("ZIP_STATE_FAILED"), e);
}
finally
{
compresser.end();
}
}
示例14: compress
import java.util.zip.Deflater; //导入方法依赖的package包/类
/** Compresses the specified byte range using the
* specified compressionLevel (constants are defined in
* java.util.zip.Deflater). */
public static byte[] compress(byte[] value, int offset, int length, int compressionLevel) {
/* Create an expandable byte array to hold the compressed data.
* You cannot use an array that's the same size as the orginal because
* there is no guarantee that the compressed data will be smaller than
* the uncompressed data. */
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()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
}
} finally {
compressor.end();
}
return bos.toByteArray();
}
示例15: close
import java.util.zip.Deflater; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
beginWrite();
try {
if (!isOpen)
return;
isOpen = false; // set closed
} finally {
endWrite();
}
if (!streams.isEmpty()) { // unlock and close all remaining streams
Set<InputStream> copy = new HashSet<>(streams);
for (InputStream is: copy)
is.close();
}
beginWrite(); // lock and sync
try {
sync();
ch.close(); // close the ch just in case no update
} finally { // and sync dose not close the ch
endWrite();
}
synchronized (inflaters) {
for (Inflater inf : inflaters)
inf.end();
}
synchronized (deflaters) {
for (Deflater def : deflaters)
def.end();
}
IOException ioe = null;
synchronized (tmppaths) {
for (Path p: tmppaths) {
try {
Files.deleteIfExists(p);
} catch (IOException x) {
if (ioe == null)
ioe = x;
else
ioe.addSuppressed(x);
}
}
}
provider.removeFileSystem(zfpath, this);
if (ioe != null)
throw ioe;
}