pages.add(firstPage, 3);
dataCache.add(firstPage, 3);
		public void write() throws IOException {			if (data == null)				return;			int chunkSize = fileHeader.getWorkSize();			int remaining = data.length;			int current = 0;			long next = 0L;			byte[] chunk;			SinglePage page = firstPage;			page.getPageHeader().setDataLength(remaining);			SinglePage nextPage;			// walk through chain of pages			while (remaining > 0) {				if (remaining < chunkSize)					chunkSize = remaining;				// copy next chunk of data to the page				System.arraycopy(data, current, page.getData(), 0, chunkSize);				if (page != firstPage)					page.getPageHeader().setDataLength(chunkSize);				page.setDirty(true);				remaining -= chunkSize;				current += chunkSize;				next = page.getPageHeader().getNextInChain();				if (remaining > 0) {					if (next > 0) {						// load next page in chain						nextPage = (SinglePage) getDataPage(next);						if(pages != null)							pages.add(page);						page = nextPage;					} else {						// add a new page to the chain						nextPage = (SinglePage) createDataPage();						nextPage.setData(new byte[fileHeader.getWorkSize()]);						nextPage.getPageHeader().setNextInChain(0L);						page.getPageHeader().setNextInChain(nextPage.getPageNum());						if(pages != null)							pages.add(page);						page = nextPage;					}				} else {					page.getPageHeader().setNextInChain(0L);					if (page != firstPage) {						page.setDirty(true);						if(pages != null)							pages.add(page);						firstPage.getPageHeader().setLastInChain(page.getPageNum());					} else						firstPage.getPageHeader().setLastInChain(0L);					firstPage.setDirty(true);					pages.add(firstPage, 3);				}			}			if (next > 0) {				// there are more pages in the chain:				// remove them				while (next > 0) {					nextPage = (SinglePage) getDataPage(next);					next = nextPage.getPageHeader().getNextInChain();					nextPage.setDirty(true);					nextPage.delete();					if(pages != null)						pages.remove(nextPage);				}			}		}