home *** CD-ROM | disk | FTP | other *** search
/ Freesoft 1997 May / Freesoft_1997-05_cd.bin / recenz / PROGRAM / JAVADRAW / iavadraw301_inst.exe / data.z / CheckedInputStream.java < prev    next >
Text File  |  1997-05-20  |  2KB  |  60 lines

  1. /*
  2.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. import java.io.FilterInputStream;
  18. import java.io.InputStream;
  19. import java.io.IOException;
  20.  
  21. public
  22. class CheckedInputStream extends FilterInputStream {
  23.     private Checksum cksum;
  24.  
  25.     public CheckedInputStream(InputStream in, Checksum cksum) {
  26.         super(in);
  27.         this.cksum = cksum;
  28.     }
  29.  
  30.     public int read() throws IOException {
  31.         int b = in.read();
  32.         if (b != -1) {
  33.             cksum.update(b);
  34.         }
  35.         return b;
  36.     }
  37.  
  38.     public int read(byte[] b) throws IOException {
  39.         int len;
  40.         len = in.read(b, 0, b.length);
  41.         if (len != -1) {
  42.             cksum.update(b, 0, b.length);
  43.         }
  44.         return len;
  45.     }
  46.  
  47.     public int read(byte[] b, int off, int len) throws IOException {
  48.         len = in.read(b, off, len);
  49.         if (len != -1) {
  50.             cksum.update(b, off, len);
  51.         }
  52.         return len;
  53.     }
  54.  
  55.     public Checksum getChecksum() {
  56.         return cksum;
  57.     }
  58. }
  59.  
  60.