sam.io
Class ChecksumCheckerInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--java.util.zip.CheckedInputStream
                    |
                    +--sam.io.ChecksumCheckerInputStream

public class ChecksumCheckerInputStream
extends java.util.zip.CheckedInputStream

Class for automatically matching the Checksum of an InputStream against a predefined value.

This allows for transparent checksum-checking like in:


 CheckedOutputStream output = new CheckOutputStream( new FileOutputStream("foo") );
 ...
 Checksum expectedChecksum = output.getChecksum();
 InputStream input = new ChecksumCheckerInputStream( new FileInputStream("bar"), expectedChecksum);
 ...
 


Nested Class Summary
 class ChecksumCheckerInputStream.MismatchingChecksumException
          Deprecated. Exception thrown whenver checksums do not match
 
Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
ChecksumCheckerInputStream(java.io.InputStream delegee, java.util.zip.CRC32 requiredChecksum)
          Deprecated. Builds a new CheksumCheckerInputStream
 
Method Summary
 void check()
          Deprecated. Checks the computed checksum.
 void close()
          Deprecated. Closes the underlying stream and checks the checksums.
protected  void finalize()
          Deprecated. Makes sure the checksums are checked on exit.
 
Methods inherited from class java.util.zip.CheckedInputStream
getChecksum, read, read, skip
 
Methods inherited from class java.io.FilterInputStream
available, mark, markSupported, read, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChecksumCheckerInputStream

public ChecksumCheckerInputStream(java.io.InputStream delegee,
                                  java.util.zip.CRC32 requiredChecksum)
Deprecated. 
Builds a new CheksumCheckerInputStream

Parameters:
delegee - the underlying input stream
requiredChecksum - the required checksum to compare to

Note that the current implementation is limitated to CRC32 checksums.

Method Detail

check

public void check()
           throws ChecksumCheckerInputStream.MismatchingChecksumException
Deprecated. 
Checks the computed checksum.

Throws:
ChecksumCheckerInputStream.MismatchingChecksumException - if the current checksum does not match the required one.
ChecksumCheckerInputStream.MismatchingChecksumException

close

public void close()
           throws java.io.IOException
Deprecated. 
Closes the underlying stream and checks the checksums.

Overrides:
close in class java.io.FilterInputStream
java.io.IOException
See Also:
check()

finalize

protected void finalize()
                 throws java.io.IOException
Deprecated. 
Makes sure the checksums are checked on exit.

Please understand that throwing a MismatchingChecksumException inside the Garbage Collector's thread might not be so desirable ...

Overrides:
finalize in class java.lang.Object
java.io.IOException