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


Java Deflater类代码示例

本文整理汇总了Java中java.util.zip.Deflater的典型用法代码示例。如果您正苦于以下问题:Java Deflater类的具体用法?Java Deflater怎么用?Java Deflater使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Deflater类属于java.util.zip包,在下文中一共展示了Deflater类的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: compressForZlib

import java.util.zip.Deflater; //导入依赖的package包/类
/**
 * zlib compress 2 byte
 *
 * @param bytesToCompress
 * @return
 */
public static byte[] compressForZlib(byte[] bytesToCompress) {
    Deflater deflater = new Deflater();
    deflater.setInput(bytesToCompress);
    deflater.finish();

    byte[] bytesCompressed = new byte[Short.MAX_VALUE];

    int numberOfBytesAfterCompression = deflater.deflate(bytesCompressed);

    byte[] returnValues = new byte[numberOfBytesAfterCompression];

    System.arraycopy
            (
                    bytesCompressed,
                    0,
                    returnValues,
                    0,
                    numberOfBytesAfterCompression
            );

    return returnValues;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:ZipHelper.java

示例3: 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:Javen205,项目名称:IJPay,代码行数:27,代码来源:SDKUtil.java

示例4: compress

import java.util.zip.Deflater; //导入依赖的package包/类
public static byte[] compress(final byte[] data) {
  final Deflater deflater = new Deflater();
  deflater.setInput(data);
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
  deflater.finish();
  final byte[] buffer = new byte[1024];
  try {
    while (!deflater.finished()) {
      final int count = deflater.deflate(buffer); // returns the generated
                                                  // code...
      // index
      outputStream.write(buffer, 0, count);
    }
    outputStream.close();
  } catch (final IOException e) {
    log.log(Level.SEVERE, e.getMessage(), e);
  }

  return outputStream.toByteArray();
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:21,代码来源:CompressionUtilities.java

示例5: openFile

import java.util.zip.Deflater; //导入依赖的package包/类
protected void openFile() throws HsqlException {

        try {
            FileAccess           fa  = database.getFileAccess();
            java.io.OutputStream fos = fa.openOutputStreamElement(outFile);

            outDescriptor = fa.getFileSync(fos);
            fileStreamOut = new DeflaterOutputStream(fos,
                    new Deflater(Deflater.DEFAULT_COMPRESSION), bufferSize);
        } catch (IOException e) {
            throw Trace.error(Trace.FILE_IO_ERROR, Trace.Message_Pair,
                              new Object[] {
                e.toString(), outFile
            });
        }
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:17,代码来源:ScriptWriterZipped.java

示例6: 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:howe,项目名称:nutz-pay,代码行数:26,代码来源:SDKUtil.java

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

示例8: openFile

import java.util.zip.Deflater; //导入依赖的package包/类
protected void openFile() {

        try {
            FileAccess           fa  = database.getFileAccess();
            java.io.OutputStream fos = fa.openOutputStreamElement(outFile);

            outDescriptor = fa.getFileSync(fos);
            fileStreamOut = new DeflaterOutputStream(fos,
                    new Deflater(Deflater.DEFAULT_COMPRESSION), bufferSize);
        } catch (IOException e) {
            throw Error.error(ErrorCode.FILE_IO_ERROR,
                              ErrorCode.M_Message_Pair, new Object[] {
                e.toString(), outFile
            });
        }
    }
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:17,代码来源:ScriptWriterZipped.java

示例9: Packer

import java.util.zip.Deflater; //导入依赖的package包/类
public Packer(final File destFile,
              final Signer signer,
              final Boolean inPlace) throws FileNotFoundException {
    this.inPlace = inPlace;
    if (inPlace) { //In codesign.py this is what we use
        this.zipStream = new ZipOutputStream(
                             new DataOutputStream(
                                 new ByteArrayOutputStream(128*1024*1024-1))); //Avoid java bug https://bugs.openjdk.java.net/browse/JDK-8055949 by being able to get to max buffer size of MAX_INT-16
        zipStream.setLevel(Deflater.NO_COMPRESSION);
    } else {
        this.zipStream = new ZipOutputStream(
                             new BufferedOutputStream(
                                 new FileOutputStream(destFile)));
    }
    this.signer = signer;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:Packer.java

示例10: 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

示例11: createEncoder

import java.util.zip.Deflater; //导入依赖的package包/类
@Override
public OneWayCodec createEncoder() throws Exception {
    return new OneWayCodec() {
        private final Deflater deflater = new Deflater(compressionLevel);

        @Override
        public byte[] code(final byte[] data) throws Exception {
            deflater.reset();
            final ByteArrayOutputStream bout = new ByteArrayOutputStream(data.length / 2);
            try (final DeflaterOutputStream out = new DeflaterOutputStream(bout, deflater)) {
                out.write(data);
            }
            return bout.toByteArray();
        }
    };
}
 
开发者ID:szegedi,项目名称:spring-web-jsflow,代码行数:17,代码来源:CompressionCodec.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:MUFCRyan,项目名称:BilibiliClient,代码行数:26,代码来源:BiliDanmukuCompressionTools.java

示例13: 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

示例14: flush

import java.util.zip.Deflater; //导入依赖的package包/类
@Override
public synchronized void flush() throws IOException {
    if (hasLastByte) {
        // - do not allow the gzip header to be flushed on its own
        // - do not do anything if there is no data to send

        // trick the deflater to flush
        /**
         * Now this is tricky: We force the Deflater to flush its data by
         * switching compression level. As yet, a perplexingly simple workaround
         * for
         * http://developer.java.sun.com/developer/bugParade/bugs/4255743.html
         */
        if (!def.finished()) {
            def.setLevel(Deflater.NO_COMPRESSION);
            flushLastByte();
            flagReenableCompression = true;
        }
    }
    out.flush();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:22,代码来源:FlushableGZIPOutputStream.java

示例15: 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


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