当前位置: 首页>>代码示例>>Java>>正文


Java Deflater.finished方法代码示例

本文整理汇总了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();
	}
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:19,代码来源:CompressionTransformer.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ZipPlugin.java

示例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;
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:22,代码来源:ByteBuffer.java

示例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();
}
 
开发者ID:superkoh,项目名称:k-framework,代码行数:27,代码来源:SecureUtil.java

示例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;
}
 
开发者ID:Tarik02,项目名称:cr-private-server,代码行数:21,代码来源:DataStream.java

示例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();
  }
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:26,代码来源:BiliDanmukuCompressionTools.java

示例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;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:26,代码来源:ZLibUtils.java

示例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();
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:17,代码来源:LogUtils.java

示例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();
}
 
开发者ID:mercadolibre,项目名称:java-restclient,代码行数:17,代码来源:RestClientTestBase.java

示例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();
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:19,代码来源:Zlib.java

示例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);
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:22,代码来源:Slice.java

示例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();
}
 
开发者ID:WeDevelopTeam,项目名称:HeroVideo-master,代码行数:30,代码来源:BiliDanmukuCompressionTools.java

示例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());
}
 
开发者ID:nukc,项目名称:ApkMultiChannelPlugin,代码行数:28,代码来源:ZipUtils.java

示例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();
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:15,代码来源:Zlib.java

示例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);
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:15,代码来源:RegistrationManager.java


注:本文中的java.util.zip.Deflater.finished方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。