Page p = null; synchronized (fileHeader) { long pageNum = fileHeader.firstFreePage; if (pageNum != Page.NO_PAGE) {  p = new Page(pageNum); p.read(); fileHeader.firstFreePage = p.header.nextPage; if (fileHeader.firstFreePage == Page.NO_PAGE) fileHeader.setLastFreePage(Page.NO_PAGE); } else {  pageNum = fileHeader.totalCount;   if(pageNum == Integer.MAX_VALUE) { throw new IOException("page limit reached: " + pageNum); } fileHeader.setTotalCount(pageNum + 1); p = new Page(pageNum); p.read(); }   }  p.header.setNextPage(Page.NO_PAGE); p.header.setStatus(UNUSED); fileHeader.setDirty(true);  fileHeader.write(); return p;
return getFreePage(true);
	protected final Page getFreePage() throws IOException {		Page p = null;		synchronized (fileHeader) {			long pageNum = fileHeader.firstFreePage;			if (pageNum != Page.NO_PAGE) {				// Steal a deleted page				p = new Page(pageNum);				p.read();				fileHeader.firstFreePage = p.header.nextPage;				if (fileHeader.firstFreePage == Page.NO_PAGE)					fileHeader.setLastFreePage(Page.NO_PAGE);			} else {				// Grow the file				pageNum = fileHeader.totalCount;//				if(getFile().getName().equals("words.dbx"))//					System.out.println("growing the file: " + fileHeader.totalCount);				if(pageNum == Integer.MAX_VALUE) {					throw new IOException("page limit reached: " + pageNum);				}				fileHeader.setTotalCount(pageNum + 1);				p = new Page(pageNum);				p.read();			}//			if(getFile().getName().equals("dom.dbx"))//				printFreeSpaceList();		}		// Initialize The Page Header (Cleanly)		p.header.setNextPage(Page.NO_PAGE);		p.header.setStatus(UNUSED);		fileHeader.setDirty(true);        // write out the file header        fileHeader.write();		return p;	}