Package net.sf.joafip.kvstore.entity

Examples of net.sf.joafip.kvstore.entity.DataBlock


  @Override
  protected void flushImp() throws HeapException {
    try {
      for (Map.Entry<Long, DataBlock> entry : cacheMap.entrySet()) {
        final long position = entry.getKey();
        final DataBlock dataBlock = entry.getValue();
        if (dataBlock.isToWrite()) {
          randomAccessFile.seek(position);
          randomAccessFile.write(dataBlock.getData());
        }
      }
      writeHeader();
      randomAccessFile.flush();
      cacheMap.clear();
View Full Code Here


    throw new HeapException("not implemented");
  }

  private int read(final long position, final int offset, final byte[] data,
      final boolean addToCache) throws FileIOException {
    DataBlock dataBlock = cacheMap.get(position);
    if (dataBlock == null) {
      dataBlock = readInFile(position, addToCache);
    }
    final int result;
    if (dataBlock == null) {
      result = 0;
    } else {
      result = data.length;
      final byte[] recordData = dataBlock.getData();
      System.arraycopy(recordData, offset, data, 0, result);
    }
    return result;
  }
View Full Code Here

    return result;
  }

  private DataBlock readInFile(final long position, final boolean addToCache)
      throws FileIOException {
    final DataBlock dataBlock;
    randomAccessFile.seek(position);
    final int blockLength = header.getBlockLength();
    final byte[] recordData = new byte[blockLength];
    final int read = randomAccessFile.read(recordData);
    if (read == blockLength) {
      dataBlock = new DataBlock(position, false, recordData);
      if (addToCache) {
        cacheMap.put(position, dataBlock);
      }
    } else {
      dataBlock = null;
View Full Code Here

    return dataBlock;
  }

  private void write(final long position, final int offset, final byte[] data)
      throws FileIOException {
    DataBlock dataBlock = cacheMap.get(position);
    if (dataBlock == null) {
      dataBlock = readInFile(position, true);
      if (dataBlock == null) {
        final byte[] recordData = new byte[header.getBlockLength()];
        dataBlock = new DataBlock(position, true, recordData);
        cacheMap.put(position, dataBlock);
      }
    } else {
      dataBlock.setToWrite(true);
    }
    System.arraycopy(data, 0, dataBlock.getData(), offset, data.length);
    final long length = position + header.getBlockLength();
    if (length > header.getDataLength()) {
      header.setDataLength(length);
    }
  }
View Full Code Here

TOP

Related Classes of net.sf.joafip.kvstore.entity.DataBlock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.