1 4 package com.tc.io; 5 6 import java.io.IOException ; 7 import java.nio.channels.FileChannel ; 8 import java.nio.channels.FileLock ; 9 import java.nio.channels.OverlappingFileLockException ; 10 11 public class TCFileChannelImpl implements TCFileChannel { 12 13 private final FileChannel channel; 14 15 public TCFileChannelImpl(FileChannel channel) { 16 this.channel = channel; 17 } 18 19 public TCFileLock lock() throws IOException , OverlappingFileLockException { 20 return new TCFileLockImpl(channel.lock()); 21 } 22 23 public void close() throws IOException { 24 channel.close(); 25 } 26 27 public TCFileLock tryLock() throws IOException , OverlappingFileLockException { 28 FileLock lock = channel.tryLock(); 29 if (lock != null) { return new TCFileLockImpl(lock); } 30 return null; 31 } 32 33 } 34 | Popular Tags |