/** * Updates the checksum with the argument. * Called when an unsigned byte is available. */ @Override public void update (int b) { byte sb; if (b > 127) { sb = (byte) (b - 256); } else { sb = (byte) b; } update (sb); }
/** * Reads a byte from the subsumed stream, updating * the byte count and the checksums. */ @Override public int read() throws IOException { int ch = subsumedStream.read (); if (ch >= 0) { _nBytes++; if (_cksummer != null) { _cksummer.update (ch); } } return ch; }
/** * Reads some number of bytes from the input stream and * stores them into the buffer array b. The number of * bytes actually read is returned as an integer. * * All bytes read are fed through the checksummer. */ @Override public int read(byte[] b) throws IOException { int len = subsumedStream.read (b); // Careful here -- don't want to add -1 bytes at EOF if (len > 0) { if (_cksummer != null) { _cksummer.update (b); } _nBytes += len; } return len; }
/** * Reads up to len bytes of data from the input stream * into an array of bytes. An attempt is made to read as * many as len bytes, but a smaller number may be read, * possibly zero. The number of bytes actually read is * returned as an integer. * * All bytes read are fed through the checksummer. */ @Override public int read(byte[] b, int off, int len) throws IOException { len = subsumedStream.read (b, off, len); // Careful here -- don't want to add -1 bytes at EOF if (len > 0) { if (_cksummer != null) { _cksummer.update (b, off, len); } _nBytes += len; } return len; }
/** * Calculates the checksums for a module that uses a * random access file. */ protected void calcRAChecksum (Checksummer ckSummer, RandomAccessFile raf) throws IOException { if (ckSummer == null) { return; } raf.seek (0); byte [] buffer = new byte[_je.getBufferSize ()]; int n = -1; try { while ((n = raf.read (buffer)) != -1) { if (n > 0) { ckSummer.update (buffer, 0, n); } } } catch (Exception e) {} }
ckSummer.update(ch);