private void checkHash() throws IOException {
		/*
		 * force a finish of the data stream, we have extra bufferspace in
		 * outbuf to account for the last 22 bytes
		 */
		int n = 0;
		while (n != -1) {
			n = fill();
		}

		if (packetLen != 0)
			throw new IOException("Cannot fully read in last packet");

		hash.update(outBuf, pos, len - 20);

		if (len < 22)
			throw new IOException("Error in stream");

		int lastpos = len + pos - 22;
		if (outBuf[lastpos] != (byte) 0xD3
				|| outBuf[lastpos + 1] != (byte) 0x14)
			throw new IOException("Error in stream");

		byte[] md = hash.digest();
		byte[] md2 = new byte[20];
		System.arraycopy(outBuf, lastpos + 2, md2, 0, 20);

		if (!Arrays.equals(md, md2))
			throw new IOException("Invalid checksum at the end");

		len -= 22;
		hashChecked = true;
	}