private static void initBuffer(Data buff) { buff.reset(); buff.writeInt(0); }
/** * Copy a String from a reader to an output stream. * * @param source the reader * @param target the output stream */ public static void copyString(Reader source, OutputStream target) throws IOException { char[] buff = new char[Constants.IO_BUFFER_SIZE]; Data d = new Data(null, new byte[3 * Constants.IO_BUFFER_SIZE]); while (true) { int l = source.read(buff); if (l < 0) { break; } d.writeStringWithoutLength(buff, l); target.write(d.data, 0, d.pos); d.reset(); } }
private void writeData() { data.reset(); writeHead(); if (type == Page.TYPE_DATA_OVERFLOW) { data.writeInt(nextPage); } else { data.writeShortInt(size); } }
private void write(Data data) { pageOut.write(data.getBytes(), 0, data.length()); data.reset(); }
/** * Read the page from the disk. */ private void read() { data.reset(); data.readByte(); data.readShortInt(); trunk = data.readInt(); logKey = data.readInt(); }
/** * Read the page from the disk. */ private void read() { data.reset(); data.readByte(); data.readShortInt(); for (int i = 0; i < pageCount; i += 8) { int x = data.readByte() & 255; used.setByte(i, x); } full = false; }
/** * Save the row in the file using a buffer. * * @param buff the buffer * @param file the file * @param log the undo log */ void save(Data buff, FileStore file, UndoLog log) { buff.reset(); append(buff, log); filePos = (int) (file.getFilePointer() / Constants.FILE_BLOCK_SIZE); file.write(buff.getBytes(), 0, buff.length()); row = null; state = STORED; }
private void readVariableHeader() { Data page = createData(); for (int i = 1;; i++) { if (i == 3) { throw DbException.get( ErrorCode.FILE_CORRUPTED_1, fileName); } page.reset(); readPage(i, page); CRC32 crc = new CRC32(); crc.update(page.getBytes(), 4, pageSize - 4); int expected = (int) crc.getValue(); int got = page.readInt(); if (expected == got) { writeCountBase = page.readLong(); logKey = page.readInt(); logFirstTrunkPage = page.readInt(); logFirstDataPage = page.readInt(); break; } } }
private void writeHead() { data.reset(); data.writeByte((byte) (Page.TYPE_BTREE_LEAF | (onlyPosition ? 0 : Page.FLAG_LAST))); data.writeShortInt(0); data.writeInt(parentPageId); data.writeVarInt(index.getId()); data.writeShortInt(entryCount); }
private void writeHead() { data.reset(); data.writeByte((byte) (Page.TYPE_BTREE_NODE | (onlyPosition ? 0 : Page.FLAG_LAST))); data.writeShortInt(0); data.writeInt(parentPageId); data.writeVarInt(index.getId()); data.writeInt(rowCountStored); data.writeShortInt(entryCount); }
/** * Read the page from the disk. */ private void read() { data.reset(); data.readByte(); data.readShortInt(); parent = data.readInt(); logKey = data.readInt(); nextTrunk = data.readInt(); pageCount = data.readShortInt(); pageIds = new int[pageCount]; for (int i = 0; i < pageCount; i++) { pageIds[i] = data.readInt(); } }
private void writeHead() { data.reset(); data.writeByte((byte) Page.TYPE_DATA_NODE); data.writeShortInt(0); if (SysProperties.CHECK2) { if (data.length() != START_PARENT) { DbException.throwInternalError(); } } data.writeInt(parentPageId); data.writeVarInt(index.getId()); data.writeInt(rowCountStored); data.writeShortInt(entryCount); }
private void writeHead() { data.reset(); int type; if (firstOverflowPageId == 0) { type = Page.TYPE_DATA_LEAF | Page.FLAG_LAST; } else { type = Page.TYPE_DATA_LEAF; } data.writeByte((byte) type); data.writeShortInt(0); if (SysProperties.CHECK2) { if (data.length() != START_PARENT) { DbException.throwInternalError(); } } data.writeInt(parentPageId); data.writeVarInt(index.getId()); data.writeVarInt(columnCount); data.writeShortInt(entryCount); }
@Override public void write(byte[] buff, int off, int len) { if (len > 0) { page.reset(); if (compress != null) { if (off != 0 || len != buff.length) { buff = Arrays.copyOfRange(buff, off, off + len); off = 0; } int uncompressed = len; buff = compress.compress(buff, compressionAlgorithm); len = buff.length; page.checkCapacity(2 * Data.LENGTH_INT + len); page.writeInt(len); page.writeInt(uncompressed); page.write(buff, off, len); } else { page.checkCapacity(Data.LENGTH_INT + len); page.writeInt(len); page.write(buff, off, len); } page.fillAligned(); store.write(page.getBytes(), 0, page.length()); } }
/** * Read a row from an input stream. * * @param rowFactory the row factory * @param in the input stream * @param data a temporary buffer * @return the row */ public static Row readRow(RowFactory rowFactory, DataReader in, Data data) throws IOException { long key = in.readVarLong(); int len = in.readVarInt(); data.reset(); data.checkCapacity(len); in.readFully(data.getBytes(), len); int columnCount = data.readVarInt(); Value[] values = new Value[columnCount]; for (int i = 0; i < columnCount; i++) { values[i] = data.readValue(); } Row row = rowFactory.createRow(values, Row.MEMORY_CALCULATE); row.setKey(key); return row; }
/** * Load an undo log record row using a buffer. * * @param buff the buffer * @param file the source file * @param log the log */ void load(Data buff, FileStore file, UndoLog log) { int min = Constants.FILE_BLOCK_SIZE; log.seek(filePos); buff.reset(); file.readFully(buff.getBytes(), 0, min); int len = buff.readInt() * Constants.FILE_BLOCK_SIZE; buff.checkCapacity(len); if (len - min > 0) { file.readFully(buff.getBytes(), min, len - min); } int oldOp = operation; load(buff, log); if (SysProperties.CHECK) { if (operation != oldOp) { DbException.throwInternalError("operation=" + operation + " op=" + oldOp); } } }
/** * Read the page. */ private void read() { data.reset(); type = data.readByte(); data.readShortInt(); parentPageId = data.readInt(); if (type == (Page.TYPE_DATA_OVERFLOW | Page.FLAG_LAST)) { size = data.readShortInt(); nextPage = 0; } else if (type == Page.TYPE_DATA_OVERFLOW) { nextPage = data.readInt(); size = store.getPageSize() - data.length(); } else { throw DbException.get(ErrorCode.FILE_CORRUPTED_1, "page:" + getPos() + " type:" + type); } start = data.length(); }
private void read() { data.reset(); int type = data.readByte(); data.readShortInt(); this.parentPageId = data.readInt(); onlyPosition = (type & Page.FLAG_LAST) == 0; int indexId = data.readVarInt(); if (indexId != index.getId()) { throw DbException.get(ErrorCode.FILE_CORRUPTED_1, "page:" + getPos() + " expected index:" + index.getId() + "got:" + indexId); } entryCount = data.readShortInt(); offsets = new int[entryCount]; rows = new SearchRow[entryCount]; for (int i = 0; i < entryCount; i++) { offsets[i] = data.readShortInt(); } start = data.length(); written = true; writtenData = true; }
private void read() { data.reset(); data.readByte(); data.readShortInt(); this.parentPageId = data.readInt(); int indexId = data.readVarInt(); if (indexId != index.getId()) { throw DbException.get(ErrorCode.FILE_CORRUPTED_1, "page:" + getPos() + " expected index:" + index.getId() + "got:" + indexId); } rowCount = rowCountStored = data.readInt(); entryCount = data.readShortInt(); childPageIds = new int[entryCount + 1]; childPageIds[entryCount] = data.readInt(); keys = Utils.newLongArray(entryCount); for (int i = 0; i < entryCount; i++) { childPageIds[i] = data.readInt(); keys[i] = data.readVarLong(); } length = data.length(); check(); written = true; }
private void read() { data.reset(); int type = data.readByte(); data.readShortInt(); this.parentPageId = data.readInt(); onlyPosition = (type & Page.FLAG_LAST) == 0; int indexId = data.readVarInt(); if (indexId != index.getId()) { throw DbException.get(ErrorCode.FILE_CORRUPTED_1, "page:" + getPos() + " expected index:" + index.getId() + "got:" + indexId); } rowCount = rowCountStored = data.readInt(); entryCount = data.readShortInt(); childPageIds = new int[entryCount + 1]; childPageIds[entryCount] = data.readInt(); rows = entryCount == 0 ? SearchRow.EMPTY_ARRAY : new SearchRow[entryCount]; offsets = Utils.newIntArray(entryCount); for (int i = 0; i < entryCount; i++) { childPageIds[i] = data.readInt(); offsets[i] = data.readShortInt(); } check(); start = data.length(); written = true; }