Java Utililty Methods FileLock

List of utility methods to do FileLock

  1. HOME
  2. Java
  3. F
  4. FileLock

Description

The list of methods to do FileLock are organized into topic(s).

Method

boolean isBlocking(Channel channel)
Indicates if the channel is in blocking mode.
boolean result = true;
if (channel instanceof SelectableChannel) {
 SelectableChannel selectableChannel = (SelectableChannel) channel;
 result = selectableChannel.isBlocking();
return result;
boolean isFileLocked(File file)
Uses Java 1.4's FileLock class to test for a file lock
boolean isLocked = false;
FileOutputStream input = null;
FileLock lock = null;
if (!file.exists()) {
 return false;
try {
 input = new FileOutputStream(file);
...
boolean isFileLocked(File file)
is File Locked
if (!file.exists()) {
 return false;
if (file.isDirectory()) {
 return false;
if (isSymlink(file)) {
 return false;
...
boolean isLocked(File file)
is Locked
if (!file.isFile()) {
 return false;
try {
 RandomAccessFile raf = new RandomAccessFile(file, "rw");
 try {
 FileChannel channel = raf.getChannel();
 FileLock lock = channel.tryLock();
...
boolean isLocked(File file)
is Locked
if (!file.isFile()) {
 return false;
try (FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.CREATE,
 StandardOpenOption.WRITE)) {
 FileLock lock = fc.tryLock();
 if (lock != null) {
 lock.release();
...
FileOutputStream lock(File file)
lock
try {
 FileOutputStream out = new FileOutputStream(file);
 FileLock lock = out.getChannel().tryLock();
 if (lock == null) {
 throw new IllegalStateException("Cannot acquire a lock on file " + file
 + ". Please verify that this file is not used by another process.");
 locks.put(file, lock);
...
FileLock lockFile(File file)
Locks a file for the current JVM.
FileOutputStream input = null;
FileLock lock = null;
try {
 input = new FileOutputStream(file);
 FileChannel fileChannel = input.getChannel();
 lock = fileChannel.tryLock();
 if (lock.isValid())
 return lock;
...
FileLock lockFile(File file, RandomAccessFile raf)
lock File
FileLock fl = null;
FileChannel fc = raf.getChannel();
if (fc != null) {
 try {
 fl = fc.tryLock();
 } catch (OverlappingFileLockException ex) {
 throw new IOException(file.getPath() + ":\nDatei ist gesperrt.\n"
 + "Bitte schlie\u00DFen Sie die Datei in dem Programm,\n"
...
boolean lockFileExists(File file)
lock File Exists
Path lockFilePath = getLockFilePath(file);
return Files.exists(lockFilePath);
SocketChannel openTcpSocket(boolean blocking)
Open and return a socket channel with the specified blocking mode enabled or null if there is an error opening the channel.
try {
 return (SocketChannel) SocketChannel.open().configureBlocking(blocking);
} catch (Exception ex) {
 return null;


AltStyle によって変換されたページ (->オリジナル) /