Package java.util.zip

Examples of java.util.zip.GZIPOutputStream


    public static byte[] gzipString(final String in) {
  try {
      final InputStream  fin  = new ByteArrayInputStream(in.getBytes("UTF8"));
      final ByteArrayOutputStream baos = new ByteArrayOutputStream(in.length() / 3);
      final OutputStream fout = new GZIPOutputStream(baos, 128);
      copy(fout, fin, 1024);
      fin.close();
      fout.close();
      return baos.toByteArray();
  } catch (final IOException e) {
      logger.logWarning("ERROR: IO trouble ",e);
      return null;
  }
View Full Code Here


        // write statistics
        System.out.println("start writing results");
        try {
            OutputStream os = new BufferedOutputStream(new FileOutputStream(outfile));
            if (gz) os = new GZIPOutputStream(os);
            count = 0;
            for (final Map.Entry<String, Integer> e: results.entrySet()) {
                os.write(UTF8.getBytes(e.getKey()));
                os.write(new byte[]{'\t'});
                os.write(UTF8.getBytes(Integer.toString(e.getValue())));
View Full Code Here

        System.out.println("start writing results");
        final File outfile = new File(trunk + ((gz) ? ".gz" : ""));
        long time = System.currentTimeMillis();
        try {
            OutputStream os = new BufferedOutputStream(new FileOutputStream(outfile));
            if (gz) os = new GZIPOutputStream(os);
            int count = 0;
            for (final String h: set) {
                os.write(UTF8.getBytes(h));
                os.write(new byte[]{'\n'});
                count++;
View Full Code Here

                    if (length > 1024) {
                        bos = new BufferOutputStream(length);
                    } else {
                        bos = new BufferOutputStream(1024);
                    }
                    gos = new GZIPOutputStream(bos);
                }

                byte[] plain = DataConverter.toBytes(dataToWrite);   
                gos.write(plain);
                gos.flush();
View Full Code Here

     * @return the compressed byte array
     * @throws IOException if an excption occurs
     */
    public static byte[] compress(byte[] data) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
        GZIPOutputStream out = new GZIPOutputStream(bos);
       
        out.write(data);
        out.close();
        return bos.toByteArray();
    }
View Full Code Here

  public void writeTo(final OutputStream outstream) throws IOException {
    if (outstream == null) {
      throw new IllegalArgumentException("Output stream may not be null");
    }
    GZIPOutputStream gzip = new GZIPOutputStream(outstream);
    wrappedEntity.writeTo(gzip);
    gzip.finish();
  }
View Full Code Here

     * @return the compressed byte array
     * @throws IOException if an excption occurs
     */
  public static byte[] compress(byte[] data) throws IOException {
      ByteArrayOutputStream bos = new ByteArrayOutputStream(data.length);
      GZIPOutputStream out = new GZIPOutputStream(bos);
     
        out.write(data);
        out.close();
        return bos.toByteArray();
    }
View Full Code Here

                if (length > 1024) {
                  bos = new BufferOutputStream(length);
                } else {
                  bos = new BufferOutputStream(1024);
                }
                gos = new GZIPOutputStream(bos);
              }

              byte[] plain = DataConverter.toBytes(dataToWrite);   
              gos.write(plain);
                  gos.flush();
View Full Code Here

   * @throws IOException
   */
  public static byte[] zipStringToBytes(String input) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    BufferedOutputStream bufos = new BufferedOutputStream(
        new GZIPOutputStream(bos));
    bufos.write(input.getBytes("UTF-8"));
    bufos.close();
    byte[] retval = bos.toByteArray();
    bos.close();
    return retval;
View Full Code Here

      File inputFile, File outputFile ) throws
      Exception {
   
   
    BufferedInputStream in = null;
    GZIPOutputStream out = null;
   
    try {
     
      in = new BufferedInputStream( new FileInputStream(inputFile));
     
      out = new GZIPOutputStream( new FileOutputStream(outputFile));
     
      byte buffer[] = new byte[1024];
      int bytesRead;
      while ( (bytesRead = in.read(buffer)) != -1) {
        out.write(buffer, 0, bytesRead);
      }
     
    }  catch (Exception e) {
      throw e;
    } finally {
      try { in.close(); } catch( Exception e) {}
      try { out.close(); } catch( Exception e) {}
    }
  }
View Full Code Here

TOP

Related Classes of java.util.zip.GZIPOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.