Package java.util.zip

Examples of java.util.zip.CheckedOutputStream


  }

  public void writeToFile(Path loc, JobConf job, Checksum crc)
      throws IOException {
    final FileSystem rfs = FileSystem.getLocal(job).getRaw();
    CheckedOutputStream chk = null;
    final FSDataOutputStream out = rfs.create(loc);
    try {
      if (crc != null) {
        crc.reset();
        chk = new CheckedOutputStream(out, crc);
        chk.write(buf.array());
        out.writeLong(chk.getChecksum().getValue());
      } else {
        out.write(buf.array());
      }
    } finally {
      if (chk != null) {
        chk.close();
      } else {
        out.close();
      }
    }
  }
View Full Code Here


            try {
                socket = new Socket(address, syncPort);
                LOG.info("sync connected to " + socket.getInetAddress().getHostAddress() + " port " + socket.getLocalPort());

                final CRC32 crc32 = new CRC32();
                final DataOutput output = new DataOutputStream(new CheckedOutputStream(socket.getOutputStream(), crc32));
                final DataInput input = new DataInputStream(socket.getInputStream());
                output.writeByte(INIT);
                long logId = input.readLong();
                do {
                    final long nextLogId = logId + 1;
View Full Code Here

   *
   * @param filename the path to the file to be compressed
   */
  public static void zipCompress(String filename) throws IOException {
    FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX);
    CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32());
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum));
    out.setComment("Failmon records.");

    BufferedReader in = new BufferedReader(new FileReader(filename));
    out.putNextEntry(new ZipEntry(new File(filename).getName()));
View Full Code Here

    indexFile.createNewFile();
    FSDataOutputStream output = FileSystem.getLocal(conf).getRaw().append(
        new Path(indexFile.getAbsolutePath()));
    Checksum crc = new PureJavaCrc32();
    crc.reset();
    CheckedOutputStream chk = new CheckedOutputStream(output, crc);
    String msg = "Writing new index file. This file will be used only " +
        "for the testing.";
    chk.write(Arrays.copyOf(msg.getBytes(),
        MapTask.MAP_OUTPUT_INDEX_RECORD_LENGTH));
    output.writeLong(chk.getChecksum().getValue());
    output.close();
  }
View Full Code Here

        Arrays.sort(sortedNames);

        Adler32 cksum = new Adler32();
        try {
            DataOutputStream out = new DataOutputStream(
                    new CheckedOutputStream(NULL_OUT, cksum));

            for (String resourceName : sortedNames) {
                long lastMod = collection.getLastModified(resourceName);
                if (lastMod < 1)
                    continue;
View Full Code Here

        origFileExists = destFile.isFile();

        checksum = makeChecksum();
        OutputStream outStream = new FileOutputStream(outFile);
        out = new CheckedOutputStream(outStream, checksum);
    }
View Full Code Here

        progress.beginTask("Creating Archive", files.size());

        OutputStream outputStream = new BufferedOutputStream(
            new FileOutputStream(archive));

        CheckedOutputStream cos = null;

        if (calculateChecksum) {
            outputStream = cos = new CheckedOutputStream(outputStream,
                new Adler32());
        }

        ZipOutputStream zipStream = new ZipOutputStream(outputStream);

        for (IPath path : files) {
            IFile file = project.getFile(path);

            try {
                zipSingleFile(new WrappedIFile(file), path.toPortableString(),
                    zipStream, progress.newChild(1));
            } catch (SarosCancellationException e) {
                cleanup(archive);
                throw e;
            } catch (IllegalArgumentException e) {
                cleanup(archive);
                throw e;
            } catch (IOException e) {
                cleanup(archive);
                throw e;
            }
        }
        zipStream.close();

        // Checksum
        if (calculateChecksum && cos != null) {
            FileZipper.log.debug("Checksum: " + cos.getChecksum().getValue());
        }
        stopWatch.stop();

        log.debug(String.format("Created project archive %s at %s", stopWatch
            .throughput(archive.length()), archive.getAbsolutePath()));
View Full Code Here

     */
    public ZipProcessor(RequestContext ctx) throws IOException {
        _ctx = ctx;
        _zipFile = ctx.getZipFile();
        _fout = new FileOutputStream(_zipFile);
        _cos = new CheckedOutputStream(
                new BufferedOutputStream(_fout), new CRC32());
        _out = new ZipOutputStream(_cos);
    }
View Full Code Here

        assertEquals("entry name", entryName, entry.getName());
        assertTrue("entry can't be read", zip.canReadEntryData(entry));
        assertEquals("method", ZipMethod.IMPLODING.getCode(), entry.getMethod());

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        CheckedOutputStream out = new CheckedOutputStream(bout, new CRC32());
        IOUtils.copy(zip.getInputStream(entry), out);

        out.flush();

        assertEquals("CRC32", entry.getCrc(), out.getChecksum().getValue());
    }
View Full Code Here

        assertEquals("method", ZipMethod.IMPLODING.getCode(), entry.getMethod());

        InputStream bio = new BoundedInputStream(zin, entry.getSize());
       
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        CheckedOutputStream out = new CheckedOutputStream(bout, new CRC32());
        IOUtils.copy(bio, out);

        out.flush();

        assertEquals("CRC32", entry.getCrc(), out.getChecksum().getValue());
    }
View Full Code Here

TOP

Related Classes of java.util.zip.CheckedOutputStream

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.