Package org.eclipse.aether.spi.io
Class PathProcessorSupport
java.lang.Object
org.eclipse.aether.spi.io.PathProcessorSupport
- All Implemented Interfaces:
PathProcessor
Utility class serving as base of
PathProcessor implementations. 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 ClassesModifier and TypeClassDescriptionstatic interfaceA 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
FieldsModifier and TypeFieldDescriptionprotected static final booleanEscape hatch if atomic move is not desired on system we run on.protected static final booleanLogic borrowed from Commons-Lang3: we really need only this, to decide do we NIO2 file ops or not. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidclassicCopy(Path source, Path target) On Windows we use pre-NIO2 way to copy files, as for some reason it works.longcopy(Path source, Path target, PathProcessor.ProgressListener listener) Copies the specified source file to the given target file.voidMoves the specified source file to the given target file.Creates aPathProcessor.TempFileinstance and backing temporary file on file system.newTempFile(Path file) Creates aPathProcessor.CollocatedTempFileinstance for given file without backing file.booleansetLastModified(Path path, long value) Sets last modified of path in milliseconds, if exists.voidwrite(Path target, InputStream source) Writes the given stream to a file.voidWrites the given data to a file.voidwriteFile(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(Path target, InputStream source) Writes the given stream to a file.voidwriteWithBackup(Path target, 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, waitMethods inherited from interface org.eclipse.aether.spi.io.PathProcessor
copy, copyWithTimestamp, lastModified, size
-
Field Details
-
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
Escape hatch if atomic move is not desired on system we run on.
-
-
Constructor Details
-
PathProcessorSupport
public PathProcessorSupport()
-
-
Method Details
-
setLastModified
Description copied from interface:PathProcessorSets last modified of path in milliseconds, if exists.- Specified by:
setLastModifiedin interfacePathProcessor- Parameters:
path- The path, may benull.- Throws:
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
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:
IOException- If an I/O error occurs.
-
write
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:
IOException- If an I/O error occurs.
-
writeWithBackup
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:
IOException- If an I/O error occurs.
-
writeWithBackup
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:
IOException- If an I/O error occurs.
-
writeFile
public void writeFile(Path target, PathProcessorSupport.FileWriter writer, boolean doBackup) throws 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:
IOException- if at any step IO problem occurs
-
copy
public long copy(Path source, Path target, PathProcessor.ProgressListener listener) throws 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:
IOException- If an I/O error occurs.
-
move
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:
IOException- If an I/O error occurs.
-
newTempFile
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:
IOException
-
newTempFile
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:
IOException
-
classicCopy
On Windows we use pre-NIO2 way to copy files, as for some reason it works. Beat me why.- Throws:
IOException
-