org.eclipse.tesla.aether.concurrency
Class LockingFileProcessor

java.lang.Object
  extended by org.eclipse.tesla.aether.concurrency.LockingFileProcessor
All Implemented Interfaces:
org.sonatype.aether.spi.io.FileProcessor, org.sonatype.aether.spi.locator.Service

@Component(role=org.sonatype.aether.spi.io.FileProcessor.class,
           hint="default")
public class LockingFileProcessor
extends Object
implements org.sonatype.aether.spi.io.FileProcessor, org.sonatype.aether.spi.locator.Service

A utility class helping with file-based operations.

Author:
Benjamin Hanzelmann

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.sonatype.aether.spi.io.FileProcessor
org.sonatype.aether.spi.io.FileProcessor.ProgressListener
 
Constructor Summary
LockingFileProcessor()
           
LockingFileProcessor(FileLockManager fileLockManager)
           
 
Method Summary
 long copy(File source, File target, org.sonatype.aether.spi.io.FileProcessor.ProgressListener listener)
          Copy src- to target-file.
 void initService(org.sonatype.aether.spi.locator.ServiceLocator locator)
           
 boolean mkdirs(File directory)
          Thread-safe variant of File.mkdirs().
 void move(File source, File target)
           
 void setFileLockManager(FileLockManager lockManager)
          Sets the LockManager to use.
 LockingFileProcessor setLogger(org.sonatype.aether.spi.log.Logger logger)
          Sets the logger to use for this component.
 void write(File file, String data)
          Write the given data to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LockingFileProcessor

public LockingFileProcessor()

LockingFileProcessor

public LockingFileProcessor(FileLockManager fileLockManager)
Method Detail

setLogger

public LockingFileProcessor setLogger(org.sonatype.aether.spi.log.Logger logger)
Sets the logger to use for this component.

Parameters:
logger - The logger to use, may be null to disable logging.
Returns:
This component for chaining, never null.

setFileLockManager

public void setFileLockManager(FileLockManager lockManager)
Sets the LockManager to use.

Parameters:
lockManager - The LockManager to use, may not be null.

initService

public void initService(org.sonatype.aether.spi.locator.ServiceLocator locator)
Specified by:
initService in interface org.sonatype.aether.spi.locator.Service

mkdirs

public boolean mkdirs(File directory)
Thread-safe variant of File.mkdirs(). Adapted from Java 6.

Specified by:
mkdirs in interface org.sonatype.aether.spi.io.FileProcessor

copy

public long copy(File source,
                 File target,
                 org.sonatype.aether.spi.io.FileProcessor.ProgressListener listener)
          throws IOException
Copy src- to target-file. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.

This method performs R/W-locking on the given files to provide concurrent access to files without data corruption, and will honor FileLocks from an external process.

Specified by:
copy in interface org.sonatype.aether.spi.io.FileProcessor
Parameters:
source - the file to copy from, must not be null.
target - the file to copy to, must not be null.
listener - the listener to notify about the copy progress, may be null.
Returns:
the number of copied bytes.
Throws:
IOException - if an I/O error occurs.

write

public void write(File file,
                  String data)
           throws IOException
Write the given data to a file. UTF-8 is assumed as encoding for the data.

Specified by:
write in interface org.sonatype.aether.spi.io.FileProcessor
Parameters:
file - The file to write to, must not be null. This file will be truncated.
data - The data to write, may be null.
Throws:
IOException - if an I/O error occurs.

move

public void move(File source,
                 File target)
          throws IOException
Specified by:
move in interface org.sonatype.aether.spi.io.FileProcessor
Throws:
IOException


Copyright © 2010-2012. All Rights Reserved.