69 * bytes are read and <code>0</code> is returned. 70 * @param buf the buffer into which the data is read 71 * @param off the start offset in the destination array <code>b</code> 72 * @param len the maximum number of bytes read 73 * @return the actual number of bytes read, or -1 if the end 74 * of the stream is reached. 75 * @exception NullPointerException If <code>buf</code> is <code>null</code>. 76 * @exception IndexOutOfBoundsException If <code>off</code> is negative, 77 * <code>len</code> is negative, or <code>len</code> is greater than 78 * <code>buf.length - off</code> 79 * @exception IOException if an I/O error has occurred 80 */ 81 public int read(byte[] buf, int off, int len) throws IOException { 82 len = in.read(buf, off, len); 83 if (len != -1) { 84 cksum.update(buf, off, len); 85 } 86 return len; 87 } 88 89 /** 90 * Skips specified number of bytes of input. 91 * @param n the number of bytes to skip 92 * @return the actual number of bytes skipped 93 * @exception IOException if an I/O error has occurred 94 */ 95 public long skip(long n) throws IOException { 96 byte[] buf = new byte[512]; 97 long total = 0; 98 while (total < n) { 99 long len = n - total; 100 len = read(buf, 0, len < buf.length ? (int)len : buf.length); 101 if (len == -1) { 102 return total; 103 } 104 total += len; 105 } 106 return total; 107 } 108 109 /** 110 * Returns the Checksum for this input stream. 111 * @return the Checksum value 112 */ 113 public Checksum getChecksum() { 114 return cksum; 115 } 116 } | 69 * bytes are read and <code>0</code> is returned. 70 * @param buf the buffer into which the data is read 71 * @param off the start offset in the destination array <code>b</code> 72 * @param len the maximum number of bytes read 73 * @return the actual number of bytes read, or -1 if the end 74 * of the stream is reached. 75 * @exception NullPointerException If <code>buf</code> is <code>null</code>. 76 * @exception IndexOutOfBoundsException If <code>off</code> is negative, 77 * <code>len</code> is negative, or <code>len</code> is greater than 78 * <code>buf.length - off</code> 79 * @exception IOException if an I/O error has occurred 80 */ 81 public int read(byte[] buf, int off, int len) throws IOException { 82 len = in.read(buf, off, len); 83 if (len != -1) { 84 cksum.update(buf, off, len); 85 } 86 return len; 87 } 88 89 private byte[] tmpbuf; 90 91 /** 92 * Skips specified number of bytes of input. 93 * @param n the number of bytes to skip 94 * @return the actual number of bytes skipped 95 * @exception IOException if an I/O error has occurred 96 */ 97 public long skip(long n) throws IOException { 98 if (tmpbuf == null) { 99 tmpbuf = new byte[512]; 100 } 101 long total = 0; 102 while (total < n) { 103 long len = n - total; 104 len = read(buf, 0, len < tmpbuf.length ? (int)len : tmpbuf.length); 105 if (len == -1) { 106 return total; 107 } 108 total += len; 109 } 110 return total; 111 } 112 113 /** 114 * Returns the Checksum for this input stream. 115 * @return the Checksum value 116 */ 117 public Checksum getChecksum() { 118 return cksum; 119 } 120 } |