Java Zip File zip(String inputStr)

Here you can find the source of zip(String inputStr)

Description

zip

License

Open Source License

Declaration

public static byte[] zip(String inputStr) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;

import java.util.zip.Deflater;

public class Main {
    public static byte[] zip(String inputStr) {
        byte[] input = null;
        try {/*from w ww . j a v a2s  .  c  o m*/
            input = inputStr.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            // cannot happen, because UTF-8 is always valid
            return null;
        }

        byte[] output = new byte[64 * 1000];
        Deflater compresser = new Deflater();
        compresser.setInput(input);
        compresser.finish();
        int len = compresser.deflate(output);
        compresser.end();

        byte[] shortOut = new byte[len];
        System.arraycopy(output, 0, shortOut, 0, len);

        return shortOut;
    }
}

Related

  1. zip(InputStream is, String dataFileName, File zipFile)
  2. zip(OutputStream outputStream, File targetFile)
  3. zip(String data, String fileName)
  4. zip(String dir, String destFile)
  5. zip(String filesDirToBeZipped, String destFileName, String manifest)
  6. zip(String outputFileName, String inputFileName)
  7. Zip(String path, File file)
  8. zip(String path, String zipFilePath)
  9. zip(String payload)