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


Java DeflaterOutputStream.write方法代码示例

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


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

示例1: 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:yunhaibin,项目名称:dubbox-hystrix,代码行数:17,代码来源:BenchmarkRunner.java

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

示例3: compress

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
public static byte[] compress(final byte[] src, final int level) {
    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();
        e.printStackTrace();
    } finally {
        try {
            byteArrayOutputStream.close();
        } catch (IOException ignored) {
        }

        defeater.end();
    }

    return result;
}
 
开发者ID:variflight,项目名称:feeyo-redisproxy,代码行数:25,代码来源:Util.java

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

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

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

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

示例8: 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 = SerializeSupport.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 Base64Support.encode(bytesOut.toByteArray(), Base64Support.UNCHUNKED);
    } catch (IOException e) {
        throw new MessageEncodingException("Unable to DEFLATE and Base64 encode SAML message", e);
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:26,代码来源:Pac4jHTTPRedirectDeflateEncoder.java

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

示例10: 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,项目名称:ReqTraq,代码行数:18,代码来源:CKit.java

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

示例12: compress

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
public static byte[] compress(byte[] data) {

        Profiler.enter("time cost on [compress]");

        ByteArrayOutputStream out = new ByteArrayOutputStream(data.length / 4);
        DeflaterOutputStream zipOut = new DeflaterOutputStream(out);
        try {
            zipOut.write(data);
            zipOut.finish();
            zipOut.close();
        } catch (IOException e) {
            LOGGER.error("compress ex", e);
            return Constants.EMPTY_BYTES;
        } finally {
            close(zipOut);
            Profiler.release();
        }
        return out.toByteArray();
    }
 
开发者ID:mpusher,项目名称:mpush,代码行数:20,代码来源:IOUtils.java

示例13: compress

import java.util.zip.DeflaterOutputStream; //导入方法依赖的package包/类
/**
 * Compress the contents of the provided array
 *
 * @param data An uncompressed byte array
 * @see DeflaterOutputStream#write(int b)
 */
public static byte[] compress( byte[] data )
{
    ByteArrayOutputStream out                  = new ByteArrayOutputStream();
    DeflaterOutputStream  deflaterOutputStream = new DeflaterOutputStream( out );
    try
    {
        for ( int i = 0; i < data.length; i++ )
            deflaterOutputStream.write( data[i] );
    }
    catch ( IOException e )
    {
        throw new RecordFormatException( e.toString() );
    }

    return out.toByteArray();
}
 
开发者ID:iOffice1,项目名称:iOffice,代码行数:23,代码来源:EscherBlipWMFRecord.java

示例14: 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:apache,项目名称:rocketmq,代码行数:25,代码来源:UtilAll.java

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


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