Package java.util.zip

Examples of java.util.zip.CheckedInputStream


*/
public class MultiFileChecksumHelper
{
    public static long getChecksum(File[] files)
    {
        CheckedInputStream cis = null;
        FileInputStream is = null;
        Checksum checksum = new Adler32();
        byte[] tempBuf = new byte[128];
       
        for ( int i = 0; i < files.length && files[i] != null && files[i].exists() && files[i].isFile(); i++ )
        {
            try
            {
                is = new FileInputStream(files[i]);
                cis = new CheckedInputStream(is, checksum);
                while (cis.read(tempBuf) >= 0) {}               
            }
            catch (Exception e)
            {
                throw new RuntimeException(e);
            }
            finally
            {
                if (cis != null)
                {
                    try
                    {
                        cis.close();
                    }
                    catch (IOException ioe) {}
                    cis = null;
                }
                if (is != null)
View Full Code Here


      final int size = partitions * MAP_OUTPUT_INDEX_RECORD_LENGTH;

      buf = ByteBuffer.allocate(size);
      if (crc != null) {
        crc.reset();
        CheckedInputStream chk = new CheckedInputStream(in, crc);
        IOUtils.readFully(chk, buf.array(), 0, size);
        if (chk.getChecksum().getValue() != in.readLong()) {
          throw new ChecksumException("Checksum error reading spill index: " +
                                indexFileName, -1);
        }
      } else {
        IOUtils.readFully(in, buf.array(), 0, size);
View Full Code Here

   * @tests java.util.zip.CheckedInputStream#CheckedInputStream(java.io.InputStream,
   *        java.util.zip.Checksum)
   */
  public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Checksum() throws Exception {
        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
        assertEquals("constructor of checkedInputStream has failed", 0, checkIn.getChecksum()
                .getValue());
        checkInput.close();
    }
View Full Code Here

        byte outBuf[] = new byte[100];
        // testing getChecksum for an empty file
        FileOutputStream outEmp = new FileOutputStream("empty.txt");
        outEmp.close();
        InputStream inEmp = new FileInputStream("empty.txt");
        CheckedInputStream checkEmpty = new CheckedInputStream(inEmp, new CRC32());
        while (checkEmpty.read() >= 0) {
        }
        assertEquals("the checkSum value of an empty file is not zero", 0, checkEmpty
                .getChecksum().getValue());
        inEmp.close();

        // testing getChecksum for the file checkInput
        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
        while (checkIn.read() >= 0) {
        }
        // ran JDK and found that the checkSum value of this is 2036203193
        // System.out.print(" " + checkIn.getChecksum().getValue());
        assertEquals("the checksum value is incorrect", 2036203193, checkIn.getChecksum()
                .getValue());
        checkInput.close();
        // testing getChecksum for file checkInput
        checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn2 = new CheckedInputStream(checkInput, new CRC32());
        checkIn2.read(outBuf, 0, 10);
        // ran JDK and found that the checkSum value of this is 2235765342
        // System.out.print(" " + checkIn2.getChecksum().getValue());
        assertEquals("the checksum value is incorrect", 2235765342L, checkIn2.getChecksum()
                .getValue());
        checkInput.close();
    }
View Full Code Here

   * @tests java.util.zip.CheckedInputStream#skip(long)
   */
  public void test_skipJ() throws Exception {
        // testing that the return by skip is valid
        InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
        long skipValue = 5;
        assertEquals("the value returned by skip(n) is not the same as its parameter",
                skipValue, checkIn.skip(skipValue));
        checkIn.skip(skipValue);
        // ran JDK and found the checkSum value is 2235765342
        // System.out.print(checkIn.getChecksum().getValue());
        assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum()
                .getValue());
        assertEquals(0, checkIn.skip(0));
        checkInput.close();
    }
View Full Code Here

    public void test_read() throws Exception {
        // testing that the return by skip is valid
        InputStream checkInput = Support_Resources
                .getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput,
                new CRC32());
        checkIn.read();
        checkIn.close();
        try {
            checkIn.read();
            fail("IOException expected.");
        } catch (IOException ee) {
            // expected
        }
        checkInput.close();
View Full Code Here

    public void test_read$byteII() throws Exception {
        // testing that the return by skip is valid
        InputStream checkInput = Support_Resources
                .getStream("hyts_checkInput.txt");
        CheckedInputStream checkIn = new CheckedInputStream(checkInput,
                new CRC32());
        byte buff[] = new byte[50];
        checkIn.read(buff, 10, 5);
        checkIn.close();
        try {
            checkIn.read(buff, 10, 5);
            fail("IOException expected.");
        } catch (IOException ee) {
            // expected
        }
        checkInput.close();
View Full Code Here

        this.checksum = null;
      }

      if (this.checksum != null) {
        this.in = new DataInputStream(
            new CheckedInputStream(in, this.checksum));
      } else {
        this.in = in;
      }
      this.limiter = limiter;
      this.cache = new OpInstanceCache();
View Full Code Here

        if( !containsSiblingCods )
            return;

        FileInputStream fis = new FileInputStream( codFile );
        CheckedInputStream checksum = new CheckedInputStream( fis, new Adler32() );
        ZipInputStream zis = new ZipInputStream( new BufferedInputStream( checksum ) );

        ZipEntry entry;
        BufferedOutputStream dest = null;
        final int BUFFER_SIZE = 1024;
View Full Code Here

    public void validate() throws ValidationException, PackageException {
        File f = new File(_archiveFile);
        try {
            FileInputStream fis = new FileInputStream(f);
            CheckedInputStream checksum = new CheckedInputStream(fis, new Adler32());
            ZipInputStream zis = new ZipInputStream(new BufferedInputStream(
                    checksum));
               
            // Parse each zip file
            ZipEntry entry;
View Full Code Here

TOP

Related Classes of java.util.zip.CheckedInputStream

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.