ph.setDataLength(ph.getDataLength() + chunkLen);
        public void append(ByteArray chunk) throws IOException {            SinglePage nextPage;            BFilePageHeader ph = firstPage.getPageHeader();            // get the last page and fill it            long next = ph.getLastInChain();            DataPage page;            if (next > 0)                page = (DataPage) getDataPage(next, false);            else                page = firstPage;            ph = page.getPageHeader();            int chunkSize = fileHeader.getWorkSize() - ph.getDataLength();            final int chunkLen = chunk.size();            if (chunkLen < chunkSize) chunkSize = chunkLen;            // fill last page            chunk.copyTo(0, page.getData(), ph.getDataLength(), chunkSize);            //System.arraycopy(chunk, 0, page.getData(), ph.getDataLength(),            // chunkSize);            ph.setDataLength(ph.getDataLength() + chunkSize);            page.setDirty(true);            // write the remaining chunks to new pages            int remaining = chunkLen - chunkSize;            int current = chunkSize;            chunkSize = fileHeader.getWorkSize();            if (remaining > 0) {                // walk through chain of pages                while (remaining > 0) {                    // add a new page to the chain                    nextPage = (SinglePage) createDataPage();                    nextPage.setData(new byte[fileHeader.getWorkSize()]);                    page.getPageHeader().setNextInChain(nextPage.getPageNum());                    page.setDirty(true);                    //page.write();                    dataCache.add(page);                    page = nextPage;                    if (remaining < chunkSize) chunkSize = remaining;                    // copy next chunk of data to the page                    chunk.copyTo(current, page.getData(), 0, chunkSize);                    //System.arraycopy(chunk, current, page.getData(), 0,                    // chunkSize);                    page.setDirty(true);                    if (page != firstPage)                            page.getPageHeader().setDataLength(chunkSize);                    remaining = remaining - chunkSize;                    current += chunkSize;                }            }            ph = firstPage.getPageHeader();            if (page != firstPage) {                // add link to last page                dataCache.add(page);                ph.setLastInChain(page.getPageNum());                ph.setDataLength(ph.getDataLength() + chunkLen);            } else                ph.setLastInChain(0L);            // adjust length field in first page            ByteConversion.intToByte(                    firstPage.getPageHeader().getDataLength() - 6, firstPage                            .getData(), 2);            firstPage.setDirty(true);            // keep the first page in cache            dataCache.add(firstPage, 2);        }