List of usage examples for java.util.zip DeflaterOutputStream close
public void close() throws IOException
From source file:FileDeflater.java
public static void main(String[] args) throws Exception { FileInputStream fin = new FileInputStream("a.dat"); FileOutputStream fout = new FileOutputStream("b.dat"); DeflaterOutputStream dos = new DeflaterOutputStream(fout); for (int c = fin.read(); c != -1; c = fin.read()) { dos.write(c);/*w w w . j a v a2 s . c o m*/ } dos.close(); fin.close(); }
From source file:Main.java
public static void main(String[] args) { for (int i = 0; i < args.length; i++) { try {/* w w w .j a v a 2 s. c om*/ FileInputStream fin = new FileInputStream(args[i]); FileOutputStream fout = new FileOutputStream(args[i] + "dfl"); DeflaterOutputStream dos = new DeflaterOutputStream(fout); for (int c = fin.read(); c != -1; c = fin.read()) { dos.write(c); } dos.close(); fin.close(); } catch (IOException ex) { System.err.println(ex); } } }
From source file:MainClass.java
public static void main(String[] args) { for (int i = 0; i < args.length; i++) { try {//w w w . java 2 s.com FileInputStream fin = new FileInputStream(args[i]); FileOutputStream fout = new FileOutputStream(args[i] + DEFLATE_SUFFIX); DeflaterOutputStream dos = new DeflaterOutputStream(fout); for (int c = fin.read(); c != -1; c = fin.read()) { dos.write(c); } dos.close(); fin.close(); } catch (IOException ex) { System.err.println(ex); } } }
From source file:Main.java
public static String compressString(String str, String encoding) { String compressedString = ""; try {//w w w .java 2 s. c o m byte[] input = str.getBytes(encoding); Deflater d = new Deflater(); d.setLevel(Deflater.BEST_COMPRESSION); ByteArrayOutputStream out = new ByteArrayOutputStream(); DeflaterOutputStream dout = new DeflaterOutputStream(out, d); dout.write(input); dout.close(); compressedString = new String(Hex.encodeHex(out.toByteArray())); } catch (Exception e) { e.printStackTrace(); } return compressedString; }
From source file:org.jasig.cas.authentication.principal.GoogleAccountsServiceTests.java
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();// w w w .ja v a 2s . c o m // next, base64 encode it Base64 base64Encoder = new Base64(); byte[] base64EncodedByteArray = base64Encoder.encode(byteOutputStream.toByteArray()); return new String(base64EncodedByteArray); }
From source file:com.integrareti.integraframework.util.RequestUtil.java
/** * Generates an encoded and compressed String from the specified * XML-formatted String. The String is encoded in the following order: * <p>/* w w w . j a v a 2 s. c o m*/ * 1. URL encode <br> * 2. Base64 encode <br> * 3. Deflate <br> * * @param xmlString * XML-formatted String that is to be encoded * @return String containing the encoded contents of the specified XML * String */ public static String encodeMessage(String xmlString) throws IOException, UnsupportedEncodingException { // first DEFLATE compress the document (saml-bindings-2.0, // section 3.4.4.1) 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()); String base64EncodedMessage = new String(base64EncodedByteArray); // finally, URL encode it String urlEncodedMessage = URLEncoder.encode(base64EncodedMessage, "UTF-8"); return urlEncodedMessage; }
From source file:net.paygate.saml.util.RequestUtil.java
/** * Generates an encoded and compressed String from the specified XML-formatted * String. The String is encoded in the following order: * <p>// w w w.j a v a 2 s . c o m * 1. URL encode <br> * 2. Base64 encode <br> * 3. Deflate <br> * * @param xmlString XML-formatted String that is to be encoded * @return String containing the encoded contents of the specified XML String */ public static String encodeMessage(String xmlString) throws IOException, UnsupportedEncodingException { // first DEFLATE compress the document (saml-bindings-2.0, // section 3.4.4.1) 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()); String base64EncodedMessage = new String(base64EncodedByteArray); // finally, URL encode it String urlEncodedMessage = URLEncoder.encode(base64EncodedMessage); return urlEncodedMessage; }
From source file:com.barrybecker4.common.util.Base64Codec.java
/** * take a String and compress it./*from w ww . jav a 2s . c o m*/ * See @decompress for reversing the compression. * @param data a string to compress. * @return compressed string representation. */ public static synchronized String compress(final String data) { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(512); Deflater deflater = new Deflater(); DeflaterOutputStream oStream = new DeflaterOutputStream(byteOut, deflater); try { oStream.write(data.getBytes(CONVERTER_UTF8)); oStream.flush(); oStream.close(); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Unsupported encoding exception :" + e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException("io error :" + e.getMessage(), e); } return new String(Base64.encodeBase64(byteOut.toByteArray())); }
From source file:com.faceye.feature.util.http.DeflateUtils.java
/** * Returns a deflated copy of the input array. *//*from w w w . j a v a2 s. com*/ public static final byte[] deflate(byte[] in) { // compress using DeflaterOutputStream ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO); DeflaterOutputStream outStream = new DeflaterOutputStream(byteOut); try { outStream.write(in); } catch (Exception e) { LOG.error("Error compressing: ", e); } try { outStream.close(); } catch (IOException e) { LOG.error("Error closing: ", e); } return byteOut.toByteArray(); }
From source file:com.iflytek.spider.util.DeflateUtils.java
/** * Returns a deflated copy of the input array. *///from w w w. ja v a2 s . c o m public static final byte[] deflate(byte[] in) { // compress using DeflaterOutputStream ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.length / EXPECTED_COMPRESSION_RATIO); DeflaterOutputStream outStream = new DeflaterOutputStream(byteOut); try { outStream.write(in); } catch (Exception e) { e.printStackTrace(LogUtil.getWarnStream(LOG)); } try { outStream.close(); } catch (IOException e) { e.printStackTrace(LogUtil.getWarnStream(LOG)); } return byteOut.toByteArray(); }