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


Java DeflaterOutputStream.close方法代码示例

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


在下文中一共展示了DeflaterOutputStream.close方法的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: 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

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

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

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

示例6: getContentPayload

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
@Override
public byte[] getContentPayload() {
	byte[] payload = new byte[(width+1)*height];
	for(int i = 0; i<height ; i++) {
		int offset = i * (width+1);
		//NO filter on this line
		payload[offset++] = 0;
		for(int j = 0 ; j<width ; j++) {
			payload[offset+j] = (byte)(127);
		}
	}

	Deflater deflater = new Deflater( Deflater.DEFAULT_COMPRESSION );
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream((width+1)*height);

    DeflaterOutputStream compBytes = new DeflaterOutputStream( outBytes, deflater );
    try {
    	compBytes.write(payload);
    	compBytes.close();
    } catch(Exception e) {
    	e.printStackTrace();
    }
    byte[] compPayload = outBytes.toByteArray();

	return compPayload;
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:27,代码来源:IDATChunk.java

示例7: compress

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
public static byte[] compress(byte[] input) throws IOException
{
    // Destination where compressed data will be stored.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    // Create a compressor.
    Deflater deflater = createDeflater();
    DeflaterOutputStream dos = new DeflaterOutputStream(baos, deflater);

    // Compress the data.
    //
    // Some other implementations such as Jetty and Tyrus use
    // Deflater.deflate(byte[], int, int, int) with Deflate.SYNC_FLUSH,
    // but this implementation does not do it intentionally because the
    // method and the constant value are not available before Java 7.
    dos.write(input, 0, input.length);
    dos.close();

    // Release the resources held by the compressor.
    deflater.end();

    // Retrieve the compressed data.
    return baos.toByteArray();
}
 
开发者ID:angcyo,项目名称:RLibrary,代码行数:25,代码来源:DeflateCompressor.java

示例8: getPayload

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
@Override
protected ByteBuf getPayload(ChannelHandlerContext ctx, Batch batch) throws IOException {
    ByteBuf payload = super.getPayload(ctx, batch);

    Deflater deflater = new Deflater();
    ByteBufOutputStream output = new ByteBufOutputStream(ctx.alloc().buffer());
    DeflaterOutputStream outputDeflater = new DeflaterOutputStream(output, deflater);

    byte[] chunk = new byte[payload.readableBytes()];
    payload.readBytes(chunk);
    outputDeflater.write(chunk);
    outputDeflater.close();

    ByteBuf content = ctx.alloc().buffer();
    content.writeByte(batch.getProtocol());
    content.writeByte('C');


    content.writeInt(output.writtenBytes());
    content.writeBytes(output.buffer());

    return content;
}
 
开发者ID:DTStack,项目名称:jlogstash-input-plugin,代码行数:24,代码来源:CompressedBatchEncoder.java

示例9: zipAndWrite

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
private void zipAndWrite(ByteSequence bytes, int record, boolean fixedSize) throws IOException {
  BufferExposingByteArrayOutputStream s = new BufferExposingByteArrayOutputStream();
  DeflaterOutputStream out = new DeflaterOutputStream(s);
  try {
    out.write(bytes.getBytes(), bytes.getOffset(), bytes.getLength());
  }
  finally {
    out.close();
  }

  synchronized (myLock) {
    doWrite(record, fixedSize, s);
    myPendingWriteRequestsSize -= bytes.getLength();
    myPendingWriteRequests.remove(record);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:RefCountingStorage.java

示例10: getContentPayload

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
public byte[] getContentPayload() {
	byte[] payload = new byte[(width+1)*height];
	for(int i = 0; i<height ; i++) {
		int offset = i * (width+1);
		//NO filter on this line
		payload[offset++] = 0;
		for(int j = 0 ; j<width ; j++) {
			payload[offset+j] = (byte)(127);
		}
	}
	
	Deflater deflater = new Deflater( Deflater.DEFAULT_COMPRESSION );
    ByteArrayOutputStream outBytes = new ByteArrayOutputStream((width+1)*height);
            
    DeflaterOutputStream compBytes = new DeflaterOutputStream( outBytes, deflater );
    try {
    	compBytes.write(payload);
    	compBytes.close();
    } catch(Exception e) {
    	e.printStackTrace();
    }
    byte[] compPayload = outBytes.toByteArray();
    		
	return compPayload;
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:26,代码来源:IDATChunk.java

示例11: compress

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
/**
 * Description 压缩某个字节数组
 *
 * @param src
 * @param level
 * @return
 * @throws IOException
 */
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:wxyyxc1992,项目名称:Head-First-Distributed-Infrastructure,代码行数:33,代码来源:ByteArrayUtil.java

示例12: writeZTXT

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
private void writeZTXT() throws IOException {
    if (param.isCompressedTextSet()) {
        String[] text = param.getCompressedText();

        for (int i = 0; i < text.length/2; i++) {
            byte[] keyword = text[2*i].getBytes();
            byte[] value = text[2*i + 1].getBytes();

            ChunkStream cs = new ChunkStream("zTXt");

            cs.write(keyword, 0, Math.min(keyword.length, 79));
            cs.write(0);
            cs.write(0);

            DeflaterOutputStream dos = new DeflaterOutputStream(cs);
            dos.write(value);
            dos.finish();
            dos.close();

            cs.writeToStream(dataOutput);
            cs.close();
        }
    }
}
 
开发者ID:git-moss,项目名称:Push2Display,代码行数:25,代码来源:PNGImageEncoder.java

示例13: deflateViaStream

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
private String deflateViaStream(final String samlRequest) throws IOException {
    final byte[] xmlBytes = samlRequest.getBytes("UTF-8");
    final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    final DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(
            byteOutputStream);
    deflaterOutputStream.write(xmlBytes, 0, xmlBytes.length);
    deflaterOutputStream.close();
    return CompressionUtils.encodeBase64(byteOutputStream.toByteArray());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:10,代码来源:SamlAuthenticationRequestTests.java

示例14: deflateViaStream

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
private static String deflateViaStream(final String samlRequest) throws IOException {
    final byte[] xmlBytes = samlRequest.getBytes(StandardCharsets.UTF_8);
    final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    final DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(
            byteOutputStream);
    deflaterOutputStream.write(xmlBytes, 0, xmlBytes.length);
    deflaterOutputStream.close();
    return EncodingUtils.encodeBase64(byteOutputStream.toByteArray());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:10,代码来源:SamlAuthenticationRequestTests.java

示例15: processDsl

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
private List<String> processDsl() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DeflaterOutputStream dos = new DeflaterOutputStream(bos);
    dos.write(dsl.getBytes(StandardCharsets.UTF_8));
    dos.flush();
    dos.close();
    bos.flush();
    bos.close();
    String encoded = BaseEncoding.base64Url().encode(bos.toByteArray());
    return split(encoded);
}
 
开发者ID:atlascon,项目名称:travny,代码行数:12,代码来源:Codegen.java


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