public long insertAfter(long address, byte[] value) { RecordPos rec = findValuePosition(address); if (rec == null) { LOG.warn("page not found"); return -1;
public long insertAfter(Value key, byte[] value) { try { final long p = findValue(key); if(p == KEY_NOT_FOUND) return -1; return insertAfter(p, value); } catch (BTreeException e) { LOG.warn("key not found", e); } catch (IOException e) { LOG.warn("IO error", e);
	public long insertAfter(long address, byte[] value) {		RecordPos rec = findValuePosition(address);		if (rec == null) {			LOG.warn("page not found");			return -1;		}		short l = ByteConversion.byteToShort(rec.page.data, rec.offset);		rec.offset = rec.offset + l + 2;		int dataLen = rec.page.getPageHeader().getDataLength();		// insert in the middle of the page?		if (rec.offset < dataLen) {			if (dataLen + value.length + 4 < fileHeader.getWorkSize()) {				int end = rec.offset + value.length + 4;				System.arraycopy(					rec.page.data,					rec.offset,					rec.page.data,					end,					dataLen - rec.offset);				rec.page.len = dataLen + value.length + 4;				rec.page.getPageHeader().setDataLength(rec.page.len);			} else {				// split the page				DOMPage splitPage = new DOMPage();				splitPage.len = dataLen - rec.offset;				System.arraycopy(					rec.page.data,					rec.offset,					splitPage.data,					0,					splitPage.len);				splitPage.getPageHeader().setDataLength(splitPage.len);				splitPage.getPageHeader().setNextDataPage(					rec.page.getPageHeader().getNextDataPage());				splitPage.getPageHeader().setPrevDataPage(					rec.page.getPageNum());				splitPage.getPageHeader().setNextTID(					rec.page.getPageHeader().getNextTID());				splitPage.getPageHeader().setRecordCount(					getRecordCount(splitPage));				splitPage.setDirty(true);				buffer.add(splitPage);				DOMPage nextPage =					getCurrentPage(splitPage.getPageHeader().getNextDataPage());				nextPage.getPageHeader().setPrevDataPage(					splitPage.getPageNum());				nextPage.setDirty(true);				buffer.add(nextPage);				rec.page.getPageHeader().setNextDataPage(					splitPage.getPageNum());				rec.page.len = rec.offset + value.length + 4;				rec.page.getPageHeader().setDataLength(rec.page.len);				rec.page.getPageHeader().setRecordCount(					getRecordCount(rec.page));				dataLen = rec.offset;			}		} else if (dataLen + value.length + 4 > fileHeader.getWorkSize()) {			// append at the end of the page			// does value fit into page?			DOMPage newPage = new DOMPage();			newPage.getPageHeader().setNextDataPage(				rec.page.getPageHeader().getNextDataPage());			rec.page.getPageHeader().setNextDataPage(newPage.getPageNum());			rec.page.setDirty(true);			buffer.add(rec.page);			rec.page = newPage;			rec.offset = 0;			rec.page.len = value.length + 4;			rec.page.getPageHeader().setDataLength(rec.page.len);		} else {			rec.page.len = dataLen + value.length + 4;			rec.page.getPageHeader().setDataLength(rec.page.len);		}		// write the data		short tid = rec.page.getPageHeader().getNextTID();		ByteConversion.shortToByte((short) tid, rec.page.data, rec.offset);		rec.offset += 2;		ByteConversion.shortToByte(			(short) value.length,			rec.page.data,			rec.offset);		rec.offset += 2;		System.arraycopy(value, 0, rec.page.data, rec.offset, value.length);		rec.offset += value.length;		rec.page.getPageHeader().incRecordCount();		rec.page.setDirty(true);		buffer.add(rec.page);		return createPointer((int) rec.page.getPageNum(), tid);	}