Java Code Examples for java.util.zip.DeflaterInputStream

Following code examples demonstrate how to use java.util.zip.DeflaterInputStreamfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.util.zip.DeflaterInputStreamand various code implementation of this class.

    public static void main(String[] args)throws Exception {
        logger.debug("let`s do it");
        new BufferedInputStream(new DeflaterInputStream(new FileInputStream("")));

    } 


    public void encode() {
        super.encode();
        body.encode();
        InputStream in = new DeflaterInputStream(new ByteBufInputStream(body));
        OutputStream out = new ByteBufOutputStream(this);
        try {
            int numberOfBytes = (int) ByteStreams.copy(in, out);
            writerIndex(readerIndex() + numberOfBytes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } 

    public static void main(String... args) {
        System.out.println("Hello Deflater and Inflater Streams");

        try {
            DeflaterOutputStream dos = 
                new DeflaterOutputStream(new FileOutputStream(new File(FILENAME)));

            for (int i = 0; i < 100; i++) {
                dos.write("Hello World\n".getBytes());
            }
            dos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            DeflaterInputStream dis = 
                new DeflaterInputStream(new FileInputStream(new File(FILENAME)));

            for (int i = 0; i < 100; i++) {
                System.out.print(dis.read());
            }
            System.out.println("\nStream is read");
            dis.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } 

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to DeflaterInputStream.class!",
                   DeflaterInputStream.class.isAssignableFrom(sut));
    } 

	public void process(Exchange exchange) throws Exception {
		System.out.println("++ In Compression Processor ++");

		InputStream is = exchange.getIn().getBody(InputStream.class);
		DeflaterInputStream CompressStream = new DeflaterInputStream(is);
        exchange.getIn().setBody(CompressStream);

	} 

    public static InputStream marshalGzipped(Object o) throws IOException {
        StringWriter body = new StringWriter();
        JAXB.marshal(o, body);
        return new DeflaterInputStream(new ByteArrayInputStream(body.toString().getBytes()));
    } 

    public static void main(String[] args) {
        try {
            FileInputStream input = new FileInputStream("D:\\input.txt");
            FileOutputStream out = new FileOutputStream("D:\\output.txt");
            
            DeflaterInputStream deflater = new DeflaterInputStream(input);
            
            int readCount;
            byte[] data = new byte[1000];
            while((readCount = deflater.read(data, 0, 1000)) != -1){
                out.write(data, 0, readCount);
            }
            System.out.println(data);
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch(IOException e){
            System.out.println(e.getMessage());
        } 
    } 

    public void squeeze(InputStream in, OutputStream out) throws IOException{
        DeflaterInputStream deflater = new DeflaterInputStream(in);
        int k;
        long count = 0;
        while ((k = deflater.read()) != -1) {
            if (count++ > MAX_BYTES){
                throw new IOException("File is too large to compress");
            }
            out.write((byte) k);
        }
        out.flush();
    } 

    public static void main(String[] args) {
        int buffSize = 1024, compLevel = Deflater.BEST_SPEED;

        BufferedInputStream bis = new BufferedInputStream(buffSize, new DeflaterInputStream(new FileInputStream(), compLevel, true));
    } 

Advertisement
Javadoc
Implements an input stream filter for compressing data in the "deflate" compression format. @since 1

.6 @author David R Tribble (david@tribble.com) @see DeflaterOutputStream @see InflaterOutputStream @see InflaterInputStream

Read More
Advertisement