Package org.eclipse.aether.spi.io
Class PathProcessorSupport
- java.lang.Object
-
- org.eclipse.aether.spi.io.PathProcessorSupport
-
- All Implemented Interfaces:
PathProcessor
public class PathProcessorSupport extends java.lang.Object implements PathProcessor
Utility class serving as base ofPathProcessorimplementations. This class can be extended or replaced (as component) when needed. Also, this class is published in Resolver implementation for path processor interface.- Since:
- 2.0.13
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfacePathProcessorSupport.FileWriterA file writer, that accepts aPathto write some content to.-
Nested classes/interfaces inherited from interface org.eclipse.aether.spi.io.PathProcessor
PathProcessor.CollocatedTempFile, PathProcessor.ProgressListener, PathProcessor.TempFile
-
-
Field Summary
Fields Modifier and Type Field Description protected static booleanATOMIC_MOVEEscape hatch if atomic move is not desired on system we run on.protected static booleanIS_WINDOWSLogic borrowed from Commons-Lang3: we really need only this, to decide do we NIO2 file ops or not.
-
Constructor Summary
Constructors Constructor Description PathProcessorSupport()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidclassicCopy(java.nio.file.Path source, java.nio.file.Path target)On Windows we use pre-NIO2 way to copy files, as for some reason it works.longcopy(java.nio.file.Path source, java.nio.file.Path target, PathProcessor.ProgressListener listener)Copies the specified source file to the given target file.voidmove(java.nio.file.Path source, java.nio.file.Path target)Moves the specified source file to the given target file.PathProcessor.TempFilenewTempFile()Creates aPathProcessor.TempFileinstance and backing temporary file on file system.PathProcessor.CollocatedTempFilenewTempFile(java.nio.file.Path file)Creates aPathProcessor.CollocatedTempFileinstance for given file without backing file.booleansetLastModified(java.nio.file.Path path, long value)Sets last modified of path in milliseconds, if exists.voidwrite(java.nio.file.Path target, java.io.InputStream source)Writes the given stream to a file.voidwrite(java.nio.file.Path target, java.lang.String data)Writes the given data to a file.voidwriteFile(java.nio.file.Path target, PathProcessorSupport.FileWriter writer, boolean doBackup)Utility method to write out file to disk in "atomic" manner, with optional backups (".bak") if needed.voidwriteWithBackup(java.nio.file.Path target, java.io.InputStream source)Writes the given stream to a file.voidwriteWithBackup(java.nio.file.Path target, java.lang.String data)Writes the given data to a file.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.aether.spi.io.PathProcessor
copy, copyWithTimestamp, lastModified, size
-
-
-
-
Field Detail
-
IS_WINDOWS
protected static final boolean IS_WINDOWS
Logic borrowed from Commons-Lang3: we really need only this, to decide do we NIO2 file ops or not. For some reason non-NIO2 works better on Windows.
-
ATOMIC_MOVE
protected static final boolean ATOMIC_MOVE
Escape hatch if atomic move is not desired on system we run on.
-
-
Constructor Detail
-
PathProcessorSupport
public PathProcessorSupport()
-
-
Method Detail
-
setLastModified
public boolean setLastModified(java.nio.file.Path path, long value) throws java.io.IOException
Description copied from interface:PathProcessorSets last modified of path in milliseconds, if exists.- Specified by:
setLastModifiedin interfacePathProcessor- Parameters:
path- The path, may benull.- Throws:
java.io.IOException- If an I/O error occurs. Some exceptions/reasons of failure to set mtime may be swallowed, and can be multiple, ranging from "file not found" to cases when FS does not support the setting the mtime.
-
write
public void write(java.nio.file.Path target, java.lang.String data) throws java.io.IOException
Description copied from interface:PathProcessorWrites the given data to a file. UTF-8 is assumed as encoding for the data. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.- Specified by:
writein interfacePathProcessor- Parameters:
target- The file to write to, must not benull. This file will be overwritten.data- The data to write, may benull.- Throws:
java.io.IOException- If an I/O error occurs.
-
write
public void write(java.nio.file.Path target, java.io.InputStream source) throws java.io.IOException
Description copied from interface:PathProcessorWrites the given stream to a file. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.- Specified by:
writein interfacePathProcessor- Parameters:
target- The file to write to, must not benull. This file will be overwritten.source- The stream to write to the file, must not benull.- Throws:
java.io.IOException- If an I/O error occurs.
-
writeWithBackup
public void writeWithBackup(java.nio.file.Path target, java.lang.String data) throws java.io.IOException
Description copied from interface:PathProcessorWrites the given data to a file. UTF-8 is assumed as encoding for the data. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.- Specified by:
writeWithBackupin interfacePathProcessor- Parameters:
target- The file to write to, must not benull. This file will be overwritten.data- The data to write, may benull.- Throws:
java.io.IOException- If an I/O error occurs.
-
writeWithBackup
public void writeWithBackup(java.nio.file.Path target, java.io.InputStream source) throws java.io.IOException
Description copied from interface:PathProcessorWrites the given stream to a file. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.- Specified by:
writeWithBackupin interfacePathProcessor- Parameters:
target- The file to write to, must not benull. This file will be overwritten.source- The stream to write to the file, must not benull.- Throws:
java.io.IOException- If an I/O error occurs.
-
writeFile
public void writeFile(java.nio.file.Path target, PathProcessorSupport.FileWriter writer, boolean doBackup) throws java.io.IOException
Utility method to write out file to disk in "atomic" manner, with optional backups (".bak") if needed. This ensures that no other thread or process will be able to read not fully written files. Finally, this method may create the needed parent directories, if the passed in target parents does not exist.- Parameters:
target- that is the target file (must be an existing or non-existing file, the path must have parent)writer- the writer that will accept aPathto write content todoBackup- iftrue, and target file is about to be overwritten, a ".bak" file with old contents will be created/overwritten- Throws:
java.io.IOException- if at any step IO problem occurs
-
copy
public long copy(java.nio.file.Path source, java.nio.file.Path target, PathProcessor.ProgressListener listener) throws java.io.IOException
Description copied from interface:PathProcessorCopies the specified source file to the given 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.- Specified by:
copyin interfacePathProcessor- Parameters:
source- The file to copy from, must not benull.target- The file to copy to, must not benull.listener- The listener to notify about the copy progress, may benull.- Returns:
- The number of copied bytes.
- Throws:
java.io.IOException- If an I/O error occurs.
-
move
public void move(java.nio.file.Path source, java.nio.file.Path target) throws java.io.IOException
Description copied from interface:PathProcessorMoves the specified source file to the given target file. If the target file already exists, it is overwritten. Creates the necessary directories for the target file. In case of an error, the created directories will be left on the file system.- Specified by:
movein interfacePathProcessor- Parameters:
source- The file to move from, must not benull.target- The file to move to, must not benull.- Throws:
java.io.IOException- If an I/O error occurs.
-
newTempFile
public PathProcessor.TempFile newTempFile() throws java.io.IOException
Description copied from interface:PathProcessorCreates aPathProcessor.TempFileinstance and backing temporary file on file system. It will be located in the default temporary-file directory. Returned instance should be handled in try-with-resource construct and created temp file is removed (if exists) when returned instance is closed.This method uses
Files.createTempFile(String, String, java.nio.file.attribute.FileAttribute[])to create the temporary file on file system.- Specified by:
newTempFilein interfacePathProcessor- Throws:
java.io.IOException
-
newTempFile
public PathProcessor.CollocatedTempFile newTempFile(java.nio.file.Path file) throws java.io.IOException
Description copied from interface:PathProcessorCreates aPathProcessor.CollocatedTempFileinstance for given file without backing file. The path will be located in same directory where given file is, and will reuse its name for generated (randomized) name. Returned instance should be handled in try-with-resource and created temp path is removed (if exists) when returned instance is closed. ThePathProcessor.CollocatedTempFile.move()makes possible to atomically replace passed in file with the processed content written into a file backing thePathProcessor.CollocatedTempFileinstance.The
filenor it's parent directories have to exist. The parent directories are created if needed.This method uses
Path.resolve(String)to create the temporary file path in passed in file parent directory, but it does NOT create backing file on file system.- Specified by:
newTempFilein interfacePathProcessor- Throws:
java.io.IOException
-
classicCopy
protected void classicCopy(java.nio.file.Path source, java.nio.file.Path target) throws java.io.IOException
On Windows we use pre-NIO2 way to copy files, as for some reason it works. Beat me why.- Throws:
java.io.IOException
-
-