/** * Reads a small amount of data from across the boundary between two blocks. * The {@link #_readIndex} of this (the second) block is updated accordingly. * Note- this method (and other code) assumes that the second {@link DataInputBlock} * always is big enough to complete the read without being exhausted. */ private void ReadSpanning(DataInputBlock prevBlock, int prevBlockAvailable, byte[] buf) { Array.Copy(prevBlock._buf, prevBlock._readIndex, buf, 0, prevBlockAvailable); int secondReadLen = buf.Length - prevBlockAvailable; Array.Copy(_buf, 0, buf, prevBlockAvailable, secondReadLen); _readIndex = secondReadLen; }
/** * Reads a <c>short</c> which spans the end of <c>prevBlock</c> and the start of this block. */ public int ReadUshortLE(DataInputBlock prevBlock) { // simple case - will always be one byte in each block int i = prevBlock._buf.Length - 1; int b0 = prevBlock._buf[i++] & 0xFF; int b1 = _buf[_readIndex++] & 0xFF; return((b1 << 8) + (b0 << 0)); }
/** * Reads an <c>int</c> which spans the end of <c>prevBlock</c> and the start of this block. */ public int ReadIntLE(DataInputBlock prevBlock, int prevBlockAvailable) { byte[] buf = new byte[4]; ReadSpanning(prevBlock, prevBlockAvailable, buf); int b0 = buf[0] & 0xFF; int b1 = buf[1] & 0xFF; int b2 = buf[2] & 0xFF; int b3 = buf[3] & 0xFF; return((b3 << 24) + (b2 << 16) + (b1 << 8) + (b0 << 0)); }
/** * Reads a <c>long</c> which spans the end of <c>prevBlock</c> and the start of this block. */ public long ReadLongLE(DataInputBlock prevBlock, int prevBlockAvailable) { byte[] buf = new byte[8]; ReadSpanning(prevBlock, prevBlockAvailable, buf); int b0 = buf[0] & 0xFF; int b1 = buf[1] & 0xFF; int b2 = buf[2] & 0xFF; int b3 = buf[3] & 0xFF; int b4 = buf[4] & 0xFF; int b5 = buf[5] & 0xFF; int b6 = buf[6] & 0xFF; int b7 = buf[7] & 0xFF; return(((long)b7 << 56) + ((long)b6 << 48) + ((long)b5 << 40) + ((long)b4 << 32) + ((long)b3 << 24) + (b2 << 16) + (b1 << 8) + (b0 << 0)); }