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


Java GZIPOutputStream.flush方法代码示例

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


在下文中一共展示了GZIPOutputStream.flush方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
@Override
public byte[] compress( final byte[] data , final int start , final int length ) throws IOException{
  ByteArrayOutputStream bOut = new ByteArrayOutputStream();
  GZIPOutputStream out = new GZIPOutputStream( bOut );

  out.write( data , start , length );
  out.flush();
  out.finish();
  byte[] compressByte = bOut.toByteArray();
  byte[] retVal = new byte[ Integer.BYTES + compressByte.length ];
  ByteBuffer wrapBuffer = ByteBuffer.wrap( retVal );
  wrapBuffer.putInt( length );
  wrapBuffer.put( compressByte );

  bOut.close();
  out.close();

  return retVal;
}
 
开发者ID:yahoojapan,项目名称:multiple-dimension-spread,代码行数:20,代码来源:GzipCompressor.java

示例3: i

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
private String i(String str) {
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(str.getBytes());
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    String str2 = null;
    try {
        GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        byte[] bArr = new byte[1024];
        while (true) {
            int read = byteArrayInputStream.read(bArr, 0, 1024);
            if (read == -1) {
                break;
            }
            gZIPOutputStream.write(bArr, 0, read);
        }
        gZIPOutputStream.flush();
        gZIPOutputStream.close();
        byte[] toByteArray = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.flush();
        byteArrayOutputStream.close();
        byteArrayInputStream.close();
        str2 = Base64.encodeToString(toByteArray, 2);
    } catch (Throwable e) {
        Ln.e(e);
    }
    return str2;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:27,代码来源:a.java

示例4: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * 数据压缩
 *
 * @param is
 * @param os
 * @throws Exception
 */
public static void compress(InputStream is, OutputStream os)
        throws Exception {

    GZIPOutputStream gos = new GZIPOutputStream(os);

    int count;
    byte data[] = new byte[BUFFER];
    while ((count = is.read(data, 0, BUFFER)) != -1) {
        gos.write(data, 0, count);
    }

    gos.finish();

    gos.flush();
    gos.close();
}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:24,代码来源:GZipUtils.java

示例5: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * Compress.
 *
 * @param str the str
 * @return the byte[]
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static byte[] compress(final String str) throws IOException {
	if ((str == null) || (str.length() == 0)) {
		return null;
	}
	ByteArrayOutputStream obj = new ByteArrayOutputStream();
	GZIPOutputStream gzip = new GZIPOutputStream(obj);
	gzip.write(str.getBytes("UTF-8"));
	gzip.flush();
	gzip.close();
	return obj.toByteArray();
}
 
开发者ID:NEMPH,项目名称:nem-apps-lib,代码行数:19,代码来源:GzipUtils.java

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

示例7: compress

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
/**
 * 数据压缩
 * @param is
 * @param os
 * @throws Exception
 */
public static void compress(InputStream is, OutputStream os) throws Exception {
	GZIPOutputStream gos = new GZIPOutputStream(os);
	int count;
	byte data[] = new byte[BUFFER];
	while ((count = is.read(data, 0, BUFFER)) != -1) {
		gos.write(data, 0, count);
	}
	gos.finish();
	gos.flush();
	gos.close();
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:18,代码来源:GZipUtils.java

示例8: 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:how2j,项目名称:lazycat,代码行数:9,代码来源:GzipInterceptor.java

示例9: run

import java.util.zip.GZIPOutputStream; //导入方法依赖的package包/类
@Override
public void run() {
    for (;;) {
        if (mic.available() >= SoundPacket.defaultDataLenght) { //we got enough data to send
            byte[] buff = new byte[SoundPacket.defaultDataLenght];
            while (mic.available() >= SoundPacket.defaultDataLenght) { //flush old data from mic to reduce lag, and read most recent data
                mic.read(buff, 0, buff.length); //read from microphone
            }
            try {
                //this part is used to decide whether to send or not the packet. if volume is too low, an empty packet will be sent and the remote client will play some comfort noise
                long tot = 0;
                for (int i = 0; i < buff.length; i++) {
                    buff[i] *= amplification;
                    tot += Math.abs(buff[i]);
                }
                tot *= 2.5;
                tot /= buff.length;
                //create and send packet
                Message m = null;
                if (tot == 0) {//send empty packet
                    m = new Message(-1, -1, new SoundPacket(null));
                } else { //send data
                    //compress the sound packet with GZIP
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    GZIPOutputStream go = new GZIPOutputStream(baos);
                    go.write(buff);
                    go.flush();
                    go.close();
                    baos.flush();
                    baos.close();
                    m = new Message(-1, -1, new SoundPacket(baos.toByteArray()));  //create message for server, will generate chId and timestamp from this computer's IP and this socket's port 
                }
                toServer.writeObject(m); //send message
            } catch (IOException ex) { //connection error
                stop();
            }
        } else {
            Utils.sleep(10); //sleep to avoid busy wait
        }
    }
}
 
开发者ID:lucas-dolsan,项目名称:tcc-rpg,代码行数:42,代码来源:MicThread.java


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