home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-13 | 1.7 KB | 60 lines |
- /*
- * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
- import java.io.FilterInputStream;
- import java.io.InputStream;
- import java.io.IOException;
-
- public
- class CheckedInputStream extends FilterInputStream {
- private Checksum cksum;
-
- public CheckedInputStream(InputStream in, Checksum cksum) {
- super(in);
- this.cksum = cksum;
- }
-
- public int read() throws IOException {
- int b = in.read();
- if (b != -1) {
- cksum.update(b);
- }
- return b;
- }
-
- public int read(byte[] b) throws IOException {
- int len;
- len = in.read(b, 0, b.length);
- if (len != -1) {
- cksum.update(b, 0, b.length);
- }
- return len;
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- len = in.read(b, off, len);
- if (len != -1) {
- cksum.update(b, off, len);
- }
- return len;
- }
-
- public Checksum getChecksum() {
- return cksum;
- }
- }
-
-