コード例 #1
0
  public void writeContinuously(long iPosition, byte[] iData) throws IOException {
    long[] pos = getRelativePosition(iPosition);

    // IT'S PREFERABLE TO FIND SPACE WITHOUT ENLARGE ANY FILES: FIND THE FIRST FILE WITH FREE SPACE
    // TO USE
    OFile file;
    int remainingSize = iData.length;
    long offset = pos[1];

    for (int i = (int) pos[0]; remainingSize > 0; ++i) {
      file = files[i];
      if (remainingSize > file.getFilledUpTo() - offset) {
        if (file.getFilledUpTo() < offset) {
          throw new ODatabaseException("range check! " + file.getFilledUpTo() + " " + offset);
        }
        file.write(
            offset, iData, (int) (file.getFilledUpTo() - offset), iData.length - remainingSize);
        remainingSize -= (file.getFilledUpTo() - offset);
      } else {
        file.write(offset, iData, remainingSize, iData.length - remainingSize);
        remainingSize = 0;
      }
      offset = 0;
    }
  }
コード例 #2
0
  @Override
  public void update() throws OSerializationException {
    try {
      final OFile f = segment.getFile();

      if (!f.isOpen()) return;

      final byte[] buffer = toStream();

      final int len = buffer.length + OBinaryProtocol.SIZE_INT;

      if (len > f.getFileSize()) f.allocateSpace(len - f.getFileSize());

      f.writeInt(0, buffer.length);
      f.write(OBinaryProtocol.SIZE_INT, buffer);
      if (OGlobalConfiguration.STORAGE_CONFIGURATION_SYNC_ON_UPDATE.getValueAsBoolean()) f.synch();

    } catch (Exception e) {
      throw new OSerializationException("Error on update storage configuration", e);
    }
  }