/** * For direct calls from {@link GridLuceneOutputStream}. * * @param ptr Pointer. * @param len Length. * @throws IOException If failed. */ void readBytes(long ptr, int len) throws IOException { while (len > 0) { if (bufPosition >= bufLength) { currBufIdx++; switchCurrentBuffer(true); } int remainInBuf = bufLength - bufPosition; int bytesToCp = len < remainInBuf ? len : remainInBuf; mem.copyMemory(currBuf + bufPosition, ptr, bytesToCp); ptr += bytesToCp; len -= bytesToCp; bufPosition += bytesToCp; } }
/** * @param requestedSize Requested size. * @return Next write pointer. */ private long allocateNextPage(long requestedSize) { int writtenSize = writtenSize(); long newPageSize = nextPageSize(writtenSize + requestedSize); long newPagePtr = mem.allocate(newPageSize); HadoopOffheapBuffer b = out.buffer(); b.set(newPagePtr, newPageSize); if (writtenSize != 0) { mem.copyMemory(writeStart, newPagePtr, writtenSize); b.move(writtenSize); } writeStart = newPagePtr; // At this point old page is not needed, so we release it. Page oldPage = curPage; curPage = new Page(newPagePtr, newPageSize); if (oldPage != null) allPages.add(oldPage); return b.move(requestedSize); }
/** * For direct calls from {@link GridLuceneOutputStream}. * * @param ptr Pointer. * @param len Length. * @throws IOException If failed. */ void readBytes(long ptr, int len) throws IOException { while (len > 0) { if (bufPosition >= bufLength) { currBufIdx++; switchCurrentBuffer(true); } int remainInBuf = bufLength - bufPosition; int bytesToCp = len < remainInBuf ? len : remainInBuf; mem.copyMemory(currBuf + bufPosition, ptr, bytesToCp); ptr += bytesToCp; len -= bytesToCp; bufPosition += bytesToCp; } }