Package java.util.zip

Examples of java.util.zip.GZIPOutputStream


     * @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


     * @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

                    // check if this file is already compressed, if not, compress now
                    if (!outfile.getName().endsWith(".gz")) {
                        final String gzname = outfile.getName() + ".gz";
                        final File gzfile = new File(outfile.getParentFile(), gzname);
                        try {
                            final OutputStream os = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(gzfile)));
                            FileUtils.copy(new BufferedInputStream(new FileInputStream(outfile)), os);
                            os.close();
                            if (gzfile.exists()) {
                                FileUtils.deletedelete(outfile);
                            }
View Full Code Here

        try {
            os = new BufferedOutputStream(new FileOutputStream(tmp), 4 * 1024 * 1024);
        } catch (final OutOfMemoryError e) {
            os = new FileOutputStream(tmp);
        }
        if (file.getName().endsWith(".gz")) os = new GZIPOutputStream(os);
        int c = 0;
        while (i.hasNext()) {
            os.write(i.next().bytes());
            c++;
        }
View Full Code Here

        // compress a byte array and add a leading magic for the compression
        try {
            //System.out.print("/(" + cdr + ")"); // DEBUG
            final ByteArrayOutputStream baos = new ByteArrayOutputStream(b.length / 5);
            baos.write(gzipMagic);
            final OutputStream os = new GZIPOutputStream(baos, 512);
            os.write(b);
            os.close();
            baos.close();
            return baos.toByteArray();
        } catch (final IOException e) {
            Log.logSevere("Compressor", "", e);
            return null;
View Full Code Here

        return buffer;
    }

    public static byte[] readAndZip(final File source) throws IOException {
        ByteArrayOutputStream byteOut = null;
        GZIPOutputStream zipOut = null;
        try {
            byteOut = new ByteArrayOutputStream((int)(source.length()/2));
            zipOut = new GZIPOutputStream(byteOut);
            copy(source, zipOut);
            zipOut.close();
            return byteOut.toByteArray();
        } finally {
            if (zipOut != null) try { zipOut.close(); } catch (final Exception e) {}
            if (byteOut != null) try { byteOut.close(); } catch (final Exception e) {}
        }
    }
View Full Code Here

            if (fos != null) try {fos.close();} catch (final Exception e) {}
        }
    }

    public static void writeAndGZip(final byte[] source, final OutputStream dest) throws IOException {
        GZIPOutputStream zipOut = null;
        try {
            zipOut = new GZIPOutputStream(dest);
            copy(source, zipOut);
            zipOut.close();
        } finally {
            if (zipOut != null) try { zipOut.close(); } catch (final Exception e) {}
        }
    }
View Full Code Here

        final File tf = new File(file.toString() + ".prt" + (System.currentTimeMillis() % 1000));
        OutputStream os = null;
        if ((format == null) || (format.equals("plain"))) {
            os = new BufferedOutputStream(new FileOutputStream(tf));
        } else if (format.equals("gzip")) {
            os = new GZIPOutputStream(new FileOutputStream(tf));
        } else if (format.equals("zip")) {
            final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file));
            String name = file.getName();
            if (name.endsWith(".zip")) name = name.substring(0, name.length() - 4);
            zos.putNextEntry(new ZipEntry(name + ".txt"));
View Full Code Here

        final File tf = new File(file.toString() + ".prt" + (System.currentTimeMillis() % 1000));
        OutputStream os = null;
        if ((format == null) || (format.equals("plain"))) {
            os = new BufferedOutputStream(new FileOutputStream(tf));
        } else if (format.equals("gzip")) {
            os = new GZIPOutputStream(new FileOutputStream(tf));
        } else if (format.equals("zip")) {
            final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file));
            String name = file.getName();
            if (name.endsWith(".zip")) name = name.substring(0, name.length() - 4);
            zos.putNextEntry(new ZipEntry(name + ".txt"));
View Full Code Here

    private static Log logger = new Log("GZIP");
   
    public static void gzipFile(final String inFile, final String outFile) {
  try {
      final InputStream  fin  = new BufferedInputStream(new FileInputStream(inFile));
      final OutputStream fout = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(outFile), 1024));
      copy(fout, fin, 1024);
      fin.close();
      fout.close();
  } catch (final FileNotFoundException e) {
      logger.logWarning("ERROR: file '" + inFile + "' not found", e);
  } catch (final IOException e) {
            logger.logWarning("ERROR: IO trouble ",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.