/** * read data from the internal stores * * @param buffer the buffer to write to * @param offset the offset into our storage to read from This method is currently (Oct 2008) only * used by test code. Perhaps it can be deleted */ void read(byte[] buffer, int offset) { int len = buffer.length; DataInputBlock currentBlock = getDataInputBlock(offset); int blockAvailable = currentBlock.available(); if (blockAvailable > len) { currentBlock.readFully(buffer, 0, len); return; } // else read big amount in chunks int remaining = len; int writePos = 0; int currentOffset = offset; while (remaining > 0) { boolean blockIsExpiring = remaining >= blockAvailable; int reqSize; if (blockIsExpiring) { reqSize = blockAvailable; } else { reqSize = remaining; } currentBlock.readFully(buffer, writePos, reqSize); remaining -= reqSize; writePos += reqSize; currentOffset += reqSize; if (blockIsExpiring) { if (currentOffset == _size) { if (remaining > 0) { throw new IllegalStateException("reached end of document stream unexpectedly"); } currentBlock = null; break; } currentBlock = getDataInputBlock(currentOffset); blockAvailable = currentBlock.available(); } } }
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; } // else read big amount in chunks int remaining = len; int writePos = off; while (remaining > 0) { boolean blockIsExpiring = remaining >= blockAvailable; int reqSize; if (blockIsExpiring) { reqSize = blockAvailable; } else { reqSize = remaining; } _currentBlock.readFully(buf, writePos, reqSize); remaining -= reqSize; writePos += reqSize; _current_offset += reqSize; if (blockIsExpiring) { if (_current_offset == _document_size) { if (remaining > 0) { throw new IllegalStateException("reached end of document stream unexpectedly"); } _currentBlock = null; break; } _currentBlock = getDataInputBlock(_current_offset); blockAvailable = _currentBlock.available(); } } }