示例#1
0
 private void flushBuffer(Data buff) {
   buff.checkCapacity(1);
   buff.writeByte((byte) 0);
   buff.fillAligned();
   buff.setInt(0, buff.length() / Constants.FILE_BLOCK_SIZE);
   file.write(buff.getBytes(), 0, buff.length());
 }
示例#2
0
 /**
  * Change the parent page id.
  *
  * @param id the new parent page id
  */
 void setParentPageId(int id) {
   index.getPageStore().logUndo(this, data);
   parentPageId = id;
   if (written) {
     changeCount = index.getPageStore().getChangeCount();
     data.setInt(START_PARENT, parentPageId);
   }
 }
 @Override
 public int addRows(ArrayList<Value[]> rows) {
   if (sort != null) {
     sort.sort(rows);
   }
   Data buff = rowBuff;
   long start = file.getFilePointer();
   ByteArrayOutputStream buffer = new ByteArrayOutputStream();
   int bufferLen = 0;
   for (Value[] row : rows) {
     buff.reset();
     buff.writeInt(0);
     for (int j = 0; j < columnCount; j++) {
       Value v = row[j];
       buff.checkCapacity(buff.getValueLen(v));
       buff.writeValue(v);
     }
     buff.fillAligned();
     int len = buff.length();
     buff.setInt(0, len);
     if (maxBufferSize > 0) {
       buffer.write(buff.getBytes(), 0, len);
       bufferLen += len;
       if (bufferLen > maxBufferSize) {
         byte[] data = buffer.toByteArray();
         buffer.reset();
         file.write(data, 0, data.length);
         bufferLen = 0;
       }
     } else {
       file.write(buff.getBytes(), 0, len);
     }
   }
   if (bufferLen > 0) {
     byte[] data = buffer.toByteArray();
     file.write(data, 0, data.length);
   }
   if (sort != null) {
     ResultDiskTape tape = new ResultDiskTape();
     tape.start = start;
     tape.end = file.getFilePointer();
     tapes.add(tape);
   } else {
     mainTape.end = file.getFilePointer();
   }
   rowCount += rows.size();
   return rowCount;
 }