public static DataInputBlock getDataInputBlock(SmallDocumentBlock[] blocks, int offset) { int firstBlockIndex = offset >> BLOCK_SHIFT; int firstBlockOffset= offset & BLOCK_MASK; return new DataInputBlock(blocks[firstBlockIndex]._data, firstBlockOffset); }
/** * Reads an <tt>int</tt> which spans the end of <tt>prevBlock</tt> 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); }
@Override public void readFully(byte[] buf, int off, int len) { checkAvaliable(len); int blockAvailable = _currentBlock.available(); if (blockAvailable > len) { _currentBlock.readFully(buf, off, len); _current_offset += len; return; reqSize = remaining; _currentBlock.readFully(buf, writePos, reqSize); remaining -= reqSize; writePos += reqSize; blockAvailable = _currentBlock.available();
@Override public long readLong() { checkAvaliable(SIZE_LONG); int blockAvailable = _currentBlock.available(); long result; if (blockAvailable > SIZE_LONG) { result = _currentBlock.readLongLE(); } else { DataInputBlock nextBlock = getDataInputBlock(_current_offset + blockAvailable); if (blockAvailable == SIZE_LONG) { result = _currentBlock.readLongLE(); } else { result = nextBlock.readLongLE(_currentBlock, blockAvailable); } _currentBlock = nextBlock; } _current_offset += SIZE_LONG; return result; }
@Override public int readInt() { checkAvaliable(SIZE_INT); int blockAvailable = _currentBlock.available(); int result; if (blockAvailable > SIZE_INT) { result = _currentBlock.readIntLE(); } else { DataInputBlock nextBlock = getDataInputBlock(_current_offset + blockAvailable); if (blockAvailable == SIZE_INT) { result = _currentBlock.readIntLE(); } else { result = nextBlock.readIntLE(_currentBlock, blockAvailable); } _currentBlock = nextBlock; } _current_offset += SIZE_INT; return result; }
@Override public int readUShort() { checkAvaliable(SIZE_SHORT); int blockAvailable = _currentBlock.available(); int result; if (blockAvailable > SIZE_SHORT) { result = _currentBlock.readUShortLE(); } else { DataInputBlock nextBlock = getDataInputBlock(_current_offset + blockAvailable); if (blockAvailable == SIZE_SHORT) { result = _currentBlock.readUShortLE(); } else { result = nextBlock.readUShortLE(_currentBlock); } _currentBlock = nextBlock; } _current_offset += SIZE_SHORT; return result; }
@Override public void readFully(byte[] buf, int off, int len) { checkAvaliable(len); int blockAvailable = _currentBlock.available(); if (blockAvailable > len) { _currentBlock.readFully(buf, off, len); _current_offset += len; return; reqSize = remaining; _currentBlock.readFully(buf, writePos, reqSize); remaining -= reqSize; writePos += reqSize; blockAvailable = _currentBlock.available();
@Override public long readLong() { checkAvaliable(SIZE_LONG); int blockAvailable = _currentBlock.available(); long result; if (blockAvailable > SIZE_LONG) { result = _currentBlock.readLongLE(); } else { DataInputBlock nextBlock = getDataInputBlock(_current_offset + blockAvailable); if (blockAvailable == SIZE_LONG) { result = _currentBlock.readLongLE(); } else { result = nextBlock.readLongLE(_currentBlock, blockAvailable); } _currentBlock = nextBlock; } _current_offset += SIZE_LONG; return result; }
@Override public int readInt() { checkAvaliable(SIZE_INT); int blockAvailable = _currentBlock.available(); int result; if (blockAvailable > SIZE_INT) { result = _currentBlock.readIntLE(); } else { DataInputBlock nextBlock = getDataInputBlock(_current_offset + blockAvailable); if (blockAvailable == SIZE_INT) { result = _currentBlock.readIntLE(); } else { result = nextBlock.readIntLE(_currentBlock, blockAvailable); } _currentBlock = nextBlock; } _current_offset += SIZE_INT; return result; }
@Override public int readUShort() { checkAvaliable(SIZE_SHORT); int blockAvailable = _currentBlock.available(); int result; if (blockAvailable > SIZE_SHORT) { result = _currentBlock.readUShortLE(); } else { DataInputBlock nextBlock = getDataInputBlock(_current_offset + blockAvailable); if (blockAvailable == SIZE_SHORT) { result = _currentBlock.readUShortLE(); } else { result = nextBlock.readUShortLE(_currentBlock); } _currentBlock = nextBlock; } _current_offset += SIZE_SHORT; return result; }
public static DataInputBlock getDataInputBlock(SmallDocumentBlock[] blocks, int offset) { int firstBlockIndex = offset >> BLOCK_SHIFT; int firstBlockOffset= offset & BLOCK_MASK; return new DataInputBlock(blocks[firstBlockIndex]._data, firstBlockOffset); }
/** * Reads an <tt>int</tt> which spans the end of <tt>prevBlock</tt> 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); }
public static DataInputBlock getDataInputBlock(DocumentBlock[] blocks, int offset) { if(blocks == null || blocks.length == 0) { return null; } // Key things about the size of the block POIFSBigBlockSize bigBlockSize = blocks[0].bigBlockSize; int BLOCK_SHIFT = bigBlockSize.getHeaderValue(); int BLOCK_SIZE = bigBlockSize.getBigBlockSize(); int BLOCK_MASK = BLOCK_SIZE - 1; // Now do the offset lookup int firstBlockIndex = offset >> BLOCK_SHIFT; int firstBlockOffset= offset & BLOCK_MASK; return new DataInputBlock(blocks[firstBlockIndex]._data, firstBlockOffset); }
/** * Reads a <tt>long</tt> which spans the end of <tt>prevBlock</tt> 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)); }