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


  }

  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

   */
  public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Checksum() {
    // test method java.util.zip.checkedOutputStream.constructor
    try {
      FileOutputStream outFile = new FileOutputStream("chkOut.txt");
      CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
          new CRC32());
      assertEquals("the checkSum value of the constructor is not 0", 0, chkOut
          .getChecksum().getValue());
      outFile.close();
    } catch (IOException e) {
      fail("Unable to find file");
    } catch (SecurityException e) {
View Full Code Here

  public void test_getChecksum() {
    // test method java.util.zip.checkedOutputStream.getChecksum()
    byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
    try {
      FileOutputStream outFile = new FileOutputStream("chkOut.txt");
      CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
          new Adler32());
      chkOut.write(byteArray[4]);
      // ran JDK and found that checkSum value is 7536755
      // System.out.print(chkOut.getChecksum().getValue());

      assertEquals("the checkSum value for writeI is incorrect", 7536755, chkOut
          .getChecksum().getValue());
      chkOut.getChecksum().reset();
      chkOut.write(byteArray, 5, 4);
      // ran JDK and found that checkSum value is 51708133
      // System.out.print(" " +chkOut.getChecksum().getValue());

      assertEquals("the checkSum value for writeBII is incorrect ", 51708133, chkOut
          .getChecksum().getValue());
      outFile.close();
    } catch (IOException e) {
      fail("Unable to find file");
    } catch (SecurityException e) {
View Full Code Here

  public void test_writeI() {
    // test method java.util.zip.checkedOutputStream.writeI()
    byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
    try {
      FileOutputStream outFile = new FileOutputStream("chkOut.txt");
      CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
          new CRC32());
      for (byte element : byteArray) {
        chkOut.write(element);
      }
      assertTrue(
          "the checkSum value is zero, no bytes are written to the output file",
          chkOut.getChecksum().getValue() != 0);
      outFile.close();
    } catch (IOException e) {
      fail("Unable to find file");
    } catch (SecurityException e) {
      fail("File cannot be opened for writing due to security reasons");
View Full Code Here

  public void test_write$BII() {
    // test method java.util.zip.checkOutputStream.writeBII()
    byte byteArray[] = { 1, 2, 3, 'e', 'r', 't', 'g', 3, 6 };
    try {
      FileOutputStream outFile = new FileOutputStream("chkOut.txt");
      CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
          new CRC32());
      chkOut.write(byteArray, 4, 5);
      assertTrue(
          "the checkSum value is zero, no bytes are written to the output file",
          chkOut.getChecksum().getValue() != 0);
      int r = 0;
      try {
        chkOut.write(byteArray, 4, 6);
      } catch (IndexOutOfBoundsException e) {
        r = 1;
      }
      assertEquals("boundary check is not performed", 1, r);
      outFile.close();
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

          jarOut.putNextEntry(jarEntry);
          ByteStreams.copy(is, jarOut);
        } else {
          crc32.reset();
          TransferByteOutputStream os = new TransferByteOutputStream();
          CheckedOutputStream checkedOut = new CheckedOutputStream(os, crc32);
          ByteStreams.copy(is, checkedOut);
          checkedOut.close();

          long size = os.size();
          jarEntry.setMethod(JarEntry.STORED);
          jarEntry.setSize(size);
          jarEntry.setCrc(checkedOut.getChecksum().getValue());
          jarOut.putNextEntry(jarEntry);
          os.transfer(jarOut);
        }
      } finally {
        is.close();
View Full Code Here

  }

  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

    conf.setInt("mapred.tasktracker.indexcache.mb", 1);
    IndexCache cache = new IndexCache(conf);

    Path f = new Path(p, "badindex");
    FSDataOutputStream out = fs.create(f, false);
    CheckedOutputStream iout = new CheckedOutputStream(out, new CRC32());
    DataOutputStream dout = new DataOutputStream(iout);
    for (int i = 0; i < parts; ++i) {
      for (int j = 0; j < MapTask.MAP_OUTPUT_INDEX_RECORD_LENGTH / 8; ++j) {
        if (0 == (i % 3)) {
          dout.writeLong(i);
        } else {
          out.writeLong(i);
        }
      }
    }
    out.writeLong(iout.getChecksum().getValue());
    dout.close();
    try {
      cache.getIndexInformation("badindex", 7, f,
          UserGroupInformation.getCurrentUser().getShortUserName());
      fail("Did not detect bad checksum");
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.