Package java.util.zip

Examples of java.util.zip.GZIPOutputStream


  public static void compressFile(
      FileInputStream fileInputStream, File outputFile ) throws
      Exception {
   
    BufferedInputStream in = null;
    GZIPOutputStream out = null;
    try {
     
      in = new BufferedInputStream(fileInputStream);
     
      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


                writeStream = new FileOutputStream(writeFile);
                break;

            case TarFileOutputStream.Compression.GZIP_COMPRESSION :
                writeStream =
                    new GZIPOutputStream(new FileOutputStream(writeFile),
                                         writeBuffer.length);
                break;

            default :
                throw new IllegalArgumentException(
View Full Code Here

        Transformer           transformer =
            JDBCSQLXML.getIdentityTransformer();
        StreamResult          result      = new StreamResult();
        ByteArrayOutputStream baos        = new ByteArrayOutputStream();
        GZIPOutputStream      gzos;

        try {
            gzos = new GZIPOutputStream(baos);
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }
        result.setOutputStream(gzos);

        try {
            transformer.transform(source, result);
        } catch (TransformerException ex) {
            throw Exceptions.transformFailed(ex);
        }

        try {
            gzos.close();
        } catch (IOException ex) {
            throw Exceptions.transformFailed(ex);
        }

        byte[] data = baos.toByteArray();
View Full Code Here

    protected OutputStream setBinaryStreamImpl() throws SQLException {

        this.outputStream = new ClosableByteArrayOutputStream();

        try {
            return new GZIPOutputStream(this.outputStream);
        } catch (IOException ex) {
            this.outputStream = null;

            throw Exceptions.resultInstantiation(ex);
        }
View Full Code Here

                    f = deflater = new DeflaterOutputStream(f,
                            new Deflater(Deflater.BEST_SPEED), b.length);
                    break;

                case COMPRESSION_GZIP :
                    f = deflater = new GZIPOutputStream(f, b.length);
                    break;

                case COMPRESSION_NONE :
                    break;
View Full Code Here

  }

  public void compressFile(File outputFile) throws Exception {

    BufferedInputStream in = null;
    GZIPOutputStream out = null;

    try {
      in = new BufferedInputStream(new FileInputStream(this.fleFile));
      out = new GZIPOutputStream(new FileOutputStream(outputFile));
      // TODO �ber Option steuern
      byte buffer[] = new byte[60000];
      int bytesRead;
      while ((bytesRead = in.read(buffer)) != -1) {
        out.write(buffer, 0, bytesRead);
      }
    }
    catch (Exception e) {
      throw new JobSchedulerException("GZip failed", e);
    }
    finally {
      try {
        if (in != null)
          in.close();
        if (out != null)
          out.close();
      }
      catch (Exception e) {
      }
    }
  }
View Full Code Here

  public Object prepareWrite(IRemoteMessage message) {
    Object objectToWrite = message;
   
    ObjectOutputStream oos = null;
    GZIPOutputStream gzos = null;
    try {
      // serialize obj
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      oos = new ObjectOutputStream(baos);
      // oos.reset(); -- not needed here because the oos is
      //                 always a new instance, reseted.
      oos.writeUnshared(message);
      byte[] byteObj = baos.toByteArray();
     
      baos.reset();
     
      // compact the serialization
      gzos = new GZIPOutputStream(baos);
      gzos.write(byteObj);
      gzos.finish();
      byteObj = baos.toByteArray();
     
      objectToWrite = byteObj;
    }
    catch (Exception e) {
      throw new RuntimeException("Can't prepare message", e); //$NON-NLS-1$
    }
    finally {
      if (gzos != null)
        try {
          gzos.close();
        } catch (IOException e) {}
       
      if (oos != null)
        try {
          oos.close();
View Full Code Here

        SignalAbort(String.format("%1$s: file '%2$s' already exist.", conMethodName, nameOfArchiveFile));
      }
      SignalInfo(String.format("%3$s: Zip '%1$s' into Zip-File '%2$s'", fileToArchive.getAbsoluteFile(), fleArchiveFile.getAbsoluteFile(), conMethodName));

      final BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileToArchive));
      final GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(fleArchiveFile));

      try {

        final byte buffer[] = new byte[1024];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) != -1) {
          out.write(buffer, 0, bytesRead);
        }

      } catch (final Exception e) {
        throw e;
      } finally {
        try {
          in.close();
        } catch (final Exception e) {
          throw e;
        }
        try {
          out.close();
        } catch (final Exception e) {
          throw e;
        }
      }
View Full Code Here

  public static final boolean compress(final String sSource, final String sDest, final boolean bDeleteSourceOnSuccess) {
    InputStream is = null;
    OutputStream os = null;

    try {
      os = new GZIPOutputStream(new FileOutputStream(sDest));
      is = new FileInputStream(sSource);

      final byte[] buff = new byte[1024];
      int r;
View Full Code Here

   */
  public static byte[] compress(final byte[] buffer){
    try{
      final ByteArrayOutputStream baos = new ByteArrayOutputStream();
   
      final GZIPOutputStream gzipos = new GZIPOutputStream(baos);
   
      gzipos.write(buffer);
      gzipos.flush();
      gzipos.close();
   
      return baos.toByteArray();
    }
    catch (IOException ioe){
      // ignore, cannot happen
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.