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


Java DeflaterOutputStream类代码示例

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


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

示例1: PRStream

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
/**
 * Creates a new PDF stream object that will replace a stream
 * in a existing PDF file.
 * @param	reader	the reader that holds the existing PDF
 * @param	conts	the new content
 * @param	compressionLevel	the compression level for the content
 * @since	2.1.3 (replacing the existing constructor without param compressionLevel)
 */
public PRStream(PdfReader reader, byte[] conts, int compressionLevel) {
    this.reader = reader;
    this.offset = -1;
    if (Document.compress) {
        try {
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            Deflater deflater = new Deflater(compressionLevel);
            DeflaterOutputStream zip = new DeflaterOutputStream(stream, deflater);
            zip.write(conts);
            zip.close();
            deflater.end();
            bytes = stream.toByteArray();
        }
        catch (IOException ioe) {
            throw new ExceptionConverter(ioe);
        }
        put(PdfName.FILTER, PdfName.FLATEDECODE);
    }
    else
        bytes = conts;
    setLength(bytes.length);
}
 
开发者ID:albfernandez,项目名称:itext2,代码行数:31,代码来源:PRStream.java

示例2: compressString

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
public static String compressString(String s) throws Exception
{
	if(s == null)
	{
		return "";
	}
	
	ByteArrayOutputStream ba = new ByteArrayOutputStream(s.length() * 2 + 20);
	DeflaterOutputStream out = new DeflaterOutputStream(ba);
	byte[] bytes = s.getBytes(CHARSET_UTF8);
	out.write(bytes);
	out.finish();
	out.flush();
	
	byte[] compressed = ba.toByteArray();
	return Hex.toHexString(compressed);
}
 
开发者ID:andy-goryachev,项目名称:FxEditor,代码行数:18,代码来源:CKit.java

示例3: openFile

import java.util.zip.DeflaterOutputStream; //导入依赖的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

示例4: compress

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
static private byte[] compress(byte[] source) throws IOException
    {
//        ByteArrayInputStream in = new ByteArrayInputStream(source);
//        ByteArrayOutputStream bous = new ByteArrayOutputStream();
//        DeflaterOutputStream out =	new DeflaterOutputStream(bous);
//        byte[] buffer = new byte[1024];
//        int len;
//        while((len = in.read(buffer)) > 0) {
//            out.write(buffer, 0, len);
//        }
//        byte[] ret = bous.toByteArray();
//
//        bous.flush();
//        in.close();
//        out.close();
//        return ret;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Deflater deflater = new Deflater(Deflater.DEFLATED);
        DeflaterOutputStream deflaterStream = new DeflaterOutputStream(baos, deflater);
        deflaterStream.write(source);
        deflaterStream.finish();

        return baos.toByteArray();
    }
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:25,代码来源:ProtocolParser20.java

示例5: createEncoder

import java.util.zip.DeflaterOutputStream; //导入依赖的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

示例6: compressDeflate

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
private static byte[] compressDeflate(byte[] data)
{
	try {
		ByteArrayOutputStream bout = new ByteArrayOutputStream(500);
		DeflaterOutputStream compresser = new DeflaterOutputStream(bout);
		compresser.write(data, 0, data.length);
		compresser.finish();
		compresser.flush();
		return bout.toByteArray();
	}
	catch (IOException ex) {
		AssertionError ae = new AssertionError("IOException while writing to ByteArrayOutputStream!");
		ae.initCause(ex);
		throw ae;
	}
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:BenchmarkRunner.java

示例7: zip

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
/**
 * zip.
 * 
 * @param bytes source.
 * @return compressed byte array.
 * @throws IOException.
 */
public static byte[] zip(byte[] bytes) throws IOException
{
	UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
	OutputStream os = new DeflaterOutputStream(bos);
	try
	{
		os.write(bytes);
	}
	finally
	{
		os.close();
		bos.close();
	}
	return bos.toByteArray();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:23,代码来源:Bytes.java

示例8: compress

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
public static byte[] compress(final byte[] src, final int level) throws IOException {
    byte[] result = src;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(src.length);
    java.util.zip.Deflater defeater = new java.util.zip.Deflater(level);
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream, defeater);
    try {
        deflaterOutputStream.write(src);
        deflaterOutputStream.finish();
        deflaterOutputStream.close();
        result = byteArrayOutputStream.toByteArray();
    } catch (IOException e) {
        defeater.end();
        throw e;
    } finally {
        try {
            byteArrayOutputStream.close();
        } catch (IOException ignored) {
        }

        defeater.end();
    }

    return result;
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:25,代码来源:UtilAll.java

示例9: encodeMessage

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
protected static String encodeMessage(final String xmlString) throws IOException {
    byte[] xmlBytes = xmlString.getBytes("UTF-8");
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(
            byteOutputStream);
    deflaterOutputStream.write(xmlBytes, 0, xmlBytes.length);
    deflaterOutputStream.close();

    // next, base64 encode it
    Base64 base64Encoder = new Base64();
    byte[] base64EncodedByteArray = base64Encoder.encode(byteOutputStream
            .toByteArray());
    return new String(base64EncodedByteArray);
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:15,代码来源:GoogleAccountsServiceTests.java

示例10: testNowrap

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
@Test
public void testNowrap() throws IOException {
  // Recompress with nowrap set to false.
  Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, false /* nowrap */);
  ByteArrayOutputStream compressedContentBuffer = new ByteArrayOutputStream();
  DeflaterOutputStream deflateOut = new DeflaterOutputStream(compressedContentBuffer, deflater);
  deflateOut.write(CONTENT);
  deflateOut.finish();
  deflateOut.close();
  deflater.end();
  compressedContent = compressedContentBuffer.toByteArray();
  compressedContentIn = new ByteArrayInputStream(compressedContent);

  // Now expect wrapped content in the uncompressor, and uncompressing should "just work".
  uncompressor.setNowrap(false);
  uncompressor.uncompress(compressedContentIn, uncompressedContentOut);
  assertTrue(Arrays.equals(CONTENT, uncompressedContentOut.toByteArray()));
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:19,代码来源:DeflateUncompressorTest.java

示例11: a

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
public static byte[] a(byte[] bArr) {
    if (bArr == null) {
        return null;
    }
    OutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream);
    try {
        deflaterOutputStream.write(bArr, 0, bArr.length);
        deflaterOutputStream.finish();
        deflaterOutputStream.flush();
        deflaterOutputStream.close();
        return byteArrayOutputStream.toByteArray();
    } catch (Exception e) {
        return null;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:j.java

示例12: deflateAndBase64Encode

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
/**
 * DEFLATE (RFC1951) compresses the given SAML message.
 * 
 * @param message SAML message
 * 
 * @return DEFLATE compressed message
 * 
 * @throws MessageEncodingException thrown if there is a problem compressing the message
 */
protected String deflateAndBase64Encode(SAMLObject message) throws MessageEncodingException {
    log.debug("Deflating and Base64 encoding SAML message");
    try {
        String messageStr = XMLHelper.nodeToString(marshallMessage(message));

        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        Deflater deflater = new Deflater(Deflater.DEFLATED, true);
        DeflaterOutputStream deflaterStream = new DeflaterOutputStream(bytesOut, deflater);
        deflaterStream.write(messageStr.getBytes("UTF-8"));
        deflaterStream.finish();

        return Base64.encodeBytes(bytesOut.toByteArray(), Base64.DONT_BREAK_LINES);
    } catch (IOException e) {
        throw new MessageEncodingException("Unable to DEFLATE and Base64 encode SAML message", e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:HTTPRedirectDeflateEncoder.java

示例13: getBody

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
/**
 * Returns an output stream into which the response body can be written.
 * The stream applies encodings (e.g. compression) according to the sent headers.
 * This method must be called after response headers have been sent
 * that indicate there is a body. Normally, the content should be
 * prepared (not sent) even before the headers are sent, so that any
 * errors during processing can be caught and a proper error response returned -
 * after the headers are sent, it's too late to change the status into an error.
 *
 * @return an output stream into which the response body can be written,
 *         or null if the body should not be written (e.g. it is discarded)
 * @throws IOException if an error occurs
 */
public OutputStream getBody() throws IOException {
    if (encoders[0] != null || discardBody)
        return encoders[0]; // return the existing stream (or null)
    // set up chain of encoding streams according to headers
    List<String> te = Arrays.asList(splitElements(headers.get("Transfer-Encoding"), true));
    List<String> ce = Arrays.asList(splitElements(headers.get("Content-Encoding"), true));
    int i = encoders.length - 1;
    encoders[i] = new FilterOutputStream(out) {
        @Override
        public void close() {} // keep underlying connection stream open for now
        @Override // override the very inefficient default implementation
        public void write(byte[] b, int off, int len) throws IOException { out.write(b, off, len); }
    };
    if (te.contains("chunked"))
        encoders[--i] = new ChunkedOutputStream(encoders[i + 1]);
    if (ce.contains("gzip") || te.contains("gzip"))
        encoders[--i] = new GZIPOutputStream(encoders[i + 1], 4096);
    else if (ce.contains("deflate") || te.contains("deflate"))
        encoders[--i] = new DeflaterOutputStream(encoders[i + 1]);
    encoders[0] = encoders[i];
    encoders[i] = null; // prevent duplicate reference
    return encoders[0]; // returned stream is always first
}
 
开发者ID:Betalord,项目名称:BHBot,代码行数:37,代码来源:HTTPServer.java

示例14: openFile

import java.util.zip.DeflaterOutputStream; //导入依赖的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

示例15: write

import java.util.zip.DeflaterOutputStream; //导入依赖的package包/类
@Override
public void write(RakNetByteBuf out) {
    super.write(out);

    RakNetOutputStream os = new RakNetOutputStream(new BufferedOutputStream(new DeflaterOutputStream(new ByteBufOutputStream(out))));
    RakNetByteBuf payload = RakNetByteBuf.buffer();
    body.write(payload);
    try {
        int bodySize = payload.readableBytes();
        byte[] bytes = new byte[bodySize];
        payload.readBytes(bytes);
        os.writeUnsignedVarInt(bodySize);
        os.write(bytes);
    } catch (Exception ignored) {
    } finally {
        payload.release();
    }
}
 
开发者ID:MagicDroidX,项目名称:RakNetty,代码行数:19,代码来源:GameWrapperPacket.java


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