コード例 #1
0
ファイル: SegmentFileManager.java プロジェクト: imace/zava
 @Override
 public ByteBuffer readPage(File file, long position, ByteBuffer pageBuffer)
     throws IOException, InterruptedException {
   long start = System.currentTimeMillis();
   RandomAccessFile randomAccessFile = randomAccessFile(file);
   try {
     randomAccessFile.seek(position);
     randomAccessFile.readFully(pageBuffer.array(), pageBuffer.arrayOffset(), pageSizeBytes);
     if (Thread.interrupted()) {
       throw new InterruptedException();
     }
     long stop = System.currentTimeMillis();
     if (LOG.isLoggable(Level.FINE)) {
       LOG.log(
           Level.FINE,
           "Read page at {0} of {1}: {2} msec",
           new Object[] {position, file, stop - start});
     }
   } catch (EOFException e) {
     LOG.log(
         Level.SEVERE,
         "Caught EOFException while reading {0}, position {1}",
         new Object[] {file, position});
     LOG.log(Level.SEVERE, "stack", e);
     throw e;
   } finally {
     randomAccessFile.close();
   }
   return pageBuffer;
 }
コード例 #2
0
ファイル: SegmentFileManager.java プロジェクト: imace/zava
 @Override
 public void flush(File file) throws IOException {
   long start = System.currentTimeMillis();
   RandomAccessFile randomAccessFile = randomAccessFile(file);
   try {
     FileChannel channel = randomAccessFile.getChannel();
     channel.force(true);
     if (LOG.isLoggable(Level.FINE)) {
       long stop = System.currentTimeMillis();
       LOG.log(Level.FINE, "Flushed {0}: {1} msec", new Object[] {file, stop - start});
     }
   } finally {
     randomAccessFile.close();
   }
 }
コード例 #3
0
ファイル: SegmentFileManager.java プロジェクト: imace/zava
 @Override
 public void write(File file, long position, ByteBuffer buffer)
     throws IOException, InterruptedException {
   long start = System.currentTimeMillis();
   RandomAccessFile randomAccessFile = randomAccessFile(file);
   try {
     FileChannel channel = randomAccessFile.getChannel();
     channel.position(position);
     channel.write(buffer);
     if (Thread.interrupted()) {
       throw new InterruptedException();
     }
     long stop = System.currentTimeMillis();
     if (LOG.isLoggable(Level.FINE)) {
       LOG.log(
           Level.FINE,
           "Wrote page at {0} of {1}: {2} msec",
           new Object[] {position, file, stop - start});
     }
   } finally {
     randomAccessFile.close();
   }
 }