Java Zip String zip_Str(String in_str)

Here you can find the source of zip_Str(String in_str)

Description

zi Str

License

Apache License

Declaration

public static byte[] zip_Str(String in_str) 

Method Source Code

//package com.java2s;
/**//from  www  .  j  a v a2s. com
  *  Copyright (c) 2014 http://www.lushapp.wang
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  */

import java.io.*;

import java.util.*;

import java.util.zip.Deflater;

public class Main {

    public static byte[] zip_Str(String in_str) {
        byte[] input = new byte[0];
        try {
            input = in_str.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        ArrayList<Byte> al = new ArrayList<Byte>();

        byte[] output;
        Deflater compresser = new Deflater();
        compresser.setInput(input);
        compresser.finish();
        for (; !compresser.finished();) {
            output = new byte[100];
            compresser.deflate(output);
            for (int i = 0; i < output.length; i++) {
                al.add(new Byte(output[i]));
            }
        }
        output = new byte[al.size()];
        for (int i = 0; i < al.size(); i++) {
            output[i] = (al.get(i)).byteValue();
        }
        return output;
    }
}

Related

  1. generateZip(String kmlContents)
  2. zip(String content)
  3. zip(String content)
  4. zip(String str)
  5. zip(String toCompress)
  6. zipString(String input)
  7. zipString(String str)
  8. zipStringAsFile(String contents, File destZipFile, String internalFilename, String comment)
  9. zipStringToBytes(String input)