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


Java GZIPOutputStream.write方法代码示例

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


在下文中一共展示了GZIPOutputStream.write方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, MessageOrBuilder in, List<Object> out)
        throws Exception {
    Message msg = in instanceof Message ? (Message) in : ((Message.Builder) in).build();

    int typeId = register.getTypeId(msg.getClass());
    if (typeId == Integer.MIN_VALUE) {
        throw new IllegalArgumentException("Unrecognisable message type, maybe not registered! ");
    }
    byte[] messageData = msg.toByteArray();

    if (messageData.length <= 0) {
        out.add(ByteBufAllocator.DEFAULT.heapBuffer().writeInt(typeId)
                .writeInt(0));
        return;
    }

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream def = new GZIPOutputStream(bos);
    def.write(messageData);
    def.flush();
    def.close();
    byte[] compressedData = bos.toByteArray();
    out.add(ByteBufAllocator.DEFAULT.heapBuffer().writeInt(typeId).writeInt(compressedData.length)
            .writeBytes(compressedData));
}
 
开发者ID:CloudLandGame,项目名称:CloudLand-Server,代码行数:27,代码来源:IdBasedProtobufEncoder.java

示例2: write

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * Write a tile image to a stream.
 *
 * @param tile the image
 * @param out the stream
 *
 * @throws ImageIOException if the write fails
 */
public static void write(BufferedImage tile, OutputStream out)
                                                         throws IOException {
  ByteBuffer bb;

  // write the header
  bb = ByteBuffer.allocate(18);

  bb.put("VASSAL".getBytes())
    .putInt(tile.getWidth())
    .putInt(tile.getHeight())
    .putInt(tile.getType());

  out.write(bb.array());

  // write the tile data
  final DataBufferInt db = (DataBufferInt) tile.getRaster().getDataBuffer();
  final int[] data = db.getData();

  bb = ByteBuffer.allocate(4*data.length);
  bb.asIntBuffer().put(data);

  final GZIPOutputStream zout = new GZIPOutputStream(out);
  zout.write(bb.array());
  zout.finish();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:34,代码来源:TileUtils.java

示例3: testWriteBinaryData

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * Testing writing binary data whose byte values range from -128 to 128.
 * We create such data by GZIP-ing the string before writing out to the Base64OutputStream.
 * 
 */      
public void testWriteBinaryData() throws IOException
{
  String str = "Base64 Encoding is a popular way to convert the 8bit and the binary to the 7bit for network trans using Socket, and a security method to handle text or file, often used in Authentical Login and Mail Attachment, also stored in text file or database. Most SMTP server will handle the login UserName and Password in this way.";
  String str_encoded = "H4sIAAAAAAAAAD2QQW7DMAwEv7IPCHIK2l4ToLe6CJD2AbREx0JkMpDouvl9KQXokVxylssTVX454F2CxiRXpArCXe9rpoKNHjBFUPnhYrCZ8TYmA0nsxZiESh9p1WuTJi0Qtk3LDVZIKtbauBcNN7ZdXyVUDmtJ9sDCNmtshNmVzDD+NThjSpl30MlYnMARSXBc3UYsBcr40Kt3Gm2glHE0ozAvrrpFropqWp5bndhwDRvJaPTIewxaDZfh6+zHFI+HLeX8f4XHyd3h29VPWrhbnalWT/bEzv4qf9D+DzA2UNlCAQAA";
  
  byte[] bytes = str.getBytes();
  
  StringWriter strwriter = new StringWriter(); 
  BufferedWriter buffwriter = new BufferedWriter(strwriter);
  Base64OutputStream b64_out = new Base64OutputStream(buffwriter);
  
  GZIPOutputStream zip = new GZIPOutputStream(b64_out);
  
  zip.write(bytes, 0, bytes.length);
  zip.finish();
  buffwriter.flush();
  b64_out.close();
  
  assertEquals(str_encoded, strwriter.toString());
  
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:27,代码来源:Base64OutputStreamTest.java

示例4: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * Gzips the given String.
 *
 * @param str The string to gzip.
 * @return The gzipped String.
 * @throws IOException If the compression failed.
 */
private static byte[] compress(final String str) throws IOException {
    if (str == null) {
        return null;
    }
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(outputStream);
    gzip.write(str.getBytes("UTF-8"));
    gzip.close();
    return outputStream.toByteArray();
}
 
开发者ID:WheezyGold7931,项目名称:Anti-Rooktube,代码行数:18,代码来源:Metrics.java

示例5: gzipCompression

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private String gzipCompression(String input) throws Exception {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	GZIPOutputStream gzip = new GZIPOutputStream(out);
	gzip.write(input.getBytes(LOCAL_ENCODING));
	gzip.close();
	String gzipString = out.toString(ISO_ENCODING);
	return new String(Base64.getEncoder().encode(gzipString.getBytes(LOCAL_ENCODING)), LOCAL_ENCODING);
}
 
开发者ID:edgexfoundry,项目名称:export-distro,代码行数:9,代码来源:CompressionTransformer.java

示例6: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * Compresses a given String. It is encoded using ISO-8859-1, So any decompression of the
 * compressed string should also use ISO-8859-1
 * 
 * @param str String to be compressed.
 * @return compressed bytes
 * @throws IOException
 */
public static byte[] compress(String str) throws IOException {
  if (str == null || str.length() == 0) {
    return null;
  }
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  GZIPOutputStream gzip = new GZIPOutputStream(out);
  gzip.write(str.getBytes("UTF-8"));
  gzip.close();
  byte[] outBytes = out.toByteArray();
  return outBytes;
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:BeanUtilFuncs.java

示例7: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static byte[] compress(byte[] data) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    GZIPOutputStream gout = new GZIPOutputStream(bout);
    gout.write(data);
    gout.flush();
    gout.close();
    return bout.toByteArray();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:9,代码来源:GzipInterceptor.java

示例8: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * Use ZipOutputStream to zip text to byte array, then convert
 * byte array to base64 string, so it can be transferred via http request.
 *
 * @param srcTxt the src txt
 * @return the string in UTF-8 format and base64'ed, or null.
 */
public static String compress(final String srcTxt) {
    try {
        final ByteArrayOutputStream rstBao = new ByteArrayOutputStream();
        final GZIPOutputStream zos = new GZIPOutputStream(rstBao);
        zos.write(srcTxt.getBytes());
        IOUtils.closeQuietly(zos);
        final byte[] bytes = rstBao.toByteArray();
        final String base64 = StringUtils.remove(Base64.encodeBase64String(bytes), '\0');
        return new String(StandardCharsets.UTF_8.encode(base64).array(), StandardCharsets.UTF_8);
    } catch (final IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:22,代码来源:CompressionUtils.java

示例9: compressAndBase64Encode

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static String compressAndBase64Encode(String string) {
    try {
        byte[] inBytes = string.getBytes("UTF-8");
        ByteArrayOutputStream baos = new ByteArrayOutputStream((int)(string.length() * 0.7));
        GZIPOutputStream gzos = new GZIPOutputStream(baos);
        gzos.write(inBytes);
        gzos.close();
        byte[] outBytes = baos.toByteArray();
        return Base64.encodeBytes(outBytes);
    }
    catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:16,代码来源:Encoder.java

示例10: inventReportBytes

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * Helper function, which compresses String and converts it to byte array
 * @param inventReport String
 * @return byte[]
 * @throws Exception
 */
private byte[] inventReportBytes(String inventReport) throws Exception {
    ByteArrayOutputStream obj = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(obj);
    gzip.write(inventReport.getBytes("UTF-8"));
    gzip.close();
    return obj.toByteArray();
}
 
开发者ID:awslabs,项目名称:s3-inventory-usage-examples,代码行数:14,代码来源:InventoryReportRetrieverTest.java

示例11: compressAndBase64EncodeToBytes

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
public static byte[] compressAndBase64EncodeToBytes(byte inBytes[]) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream((int)(inBytes.length * .7));
        GZIPOutputStream gzos = new GZIPOutputStream(baos);
        gzos.write(inBytes);
        gzos.close();
        byte[] outBytes = baos.toByteArray();
        return Base64.encodeBytesToBytes(outBytes);
    }
    catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:15,代码来源:Encoder.java

示例12: GzipConcatTest

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
void GzipConcatTest(Configuration conf,
    Class<? extends Decompressor> decomClass) throws IOException {
  Random r = new Random();
  long seed = r.nextLong();
  r.setSeed(seed);
  LOG.info(decomClass + " seed: " + seed);

  final int CONCAT = r.nextInt(4) + 3;
  final int BUFLEN = 128 * 1024;
  DataOutputBuffer dflbuf = new DataOutputBuffer();
  DataOutputBuffer chkbuf = new DataOutputBuffer();
  byte[] b = new byte[BUFLEN];
  for (int i = 0; i < CONCAT; ++i) {
    GZIPOutputStream gzout = new GZIPOutputStream(dflbuf);
    r.nextBytes(b);
    int len = r.nextInt(BUFLEN);
    int off = r.nextInt(BUFLEN - len);
    chkbuf.write(b, off, len);
    gzout.write(b, off, len);
    gzout.close();
  }
  final byte[] chk = Arrays.copyOf(chkbuf.getData(), chkbuf.getLength());

  CompressionCodec codec = ReflectionUtils.newInstance(GzipCodec.class, conf);
  Decompressor decom = codec.createDecompressor();
  assertNotNull(decom);
  assertEquals(decomClass, decom.getClass());
  DataInputBuffer gzbuf = new DataInputBuffer();
  gzbuf.reset(dflbuf.getData(), dflbuf.getLength());
  InputStream gzin = codec.createInputStream(gzbuf, decom);

  dflbuf.reset();
  IOUtils.copyBytes(gzin, dflbuf, 4096);
  final byte[] dflchk = Arrays.copyOf(dflbuf.getData(), dflbuf.getLength());
  assertArrayEquals(chk, dflchk);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:37,代码来源:TestCodec.java


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