public class FileOps
extends java.lang.Object
| Constructor and Description |
|---|
FileOps() |
| Modifier and Type | Method and Description |
|---|---|
static Nat |
byteLength(java.nio.file.Path file)
Queries the size of the given file.
|
static void |
copy(java.nio.file.Path source,
java.nio.file.Path destination)
Copies the source file to the destination path, overriding it if it
exists already.
|
static void |
delete(java.nio.file.Path file)
Deletes the specified file if it exists; does nothing otherwise.
|
static void |
ensureDirectory(java.nio.file.Path p)
Calls
Files.createDirectories() re-throwing any exception without wrapping. |
static void |
filter(java.nio.file.Path from,
java.nio.file.Path to,
StreamFilter f)
Uses a filter to read data from a source file and write a new destination
file.
|
static java.util.stream.Stream<java.nio.file.Path> |
listChildFiles(java.nio.file.Path dir)
Collects all the regular files directly under the specified directory.
|
static void |
rewrite(java.nio.file.Path target,
StreamFilter f)
Uses a filter to rewrite the content of the specified file.
|
static long |
transfer(java.nio.file.Path from,
Nat howManyBytes,
java.io.OutputStream to)
Efficiently copies an initial segment of a file into a target stream.
|
static void |
writeNew(java.nio.file.Path file,
util.lambda.ConsumerE<java.io.OutputStream> writer)
Creates a new file and has the given consumer write its contents.
|
public static void delete(java.nio.file.Path file)
file - path to the file to delete.java.lang.NullPointerException - if the argument is null.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException):
IOException if an I/O error occurs.
public static void copy(java.nio.file.Path source,
java.nio.file.Path destination)
source - path to the file to copy.destination - path to the copied file.java.lang.NullPointerException - if any argument is null.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException):
IOException if an I/O error occurs.
public static long transfer(java.nio.file.Path from,
Nat howManyBytes,
java.io.OutputStream to)
throws java.io.IOException
from - path to the file from which to get the data.howManyBytes - number of bytes to take, starting at the beginning
of the file.to - where to copy the data.java.lang.NullPointerException - if any argument is null.java.io.IOException - if an I/O error occurs.public static Nat byteLength(java.nio.file.Path file)
file - the file to query.java.lang.NullPointerException - if the argument is null.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException):
IOException if an I/O error occurs.
public static java.util.stream.Stream<java.nio.file.Path> listChildFiles(java.nio.file.Path dir)
dir - the target directory.java.lang.NullPointerException - if the argument is null.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException):
IOException if an I/O error occurs.
public static void ensureDirectory(java.nio.file.Path p)
Files.createDirectories() re-throwing any exception without wrapping.p - the path containing the directories to create.java.lang.NullPointerException - if the argument is null.public static void writeNew(java.nio.file.Path file,
util.lambda.ConsumerE<java.io.OutputStream> writer)
file - path to the file to create and write.writer - writes the file contents.java.lang.NullPointerException - if any argument is null.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException):
IOException if an I/O error occurs.
public static void rewrite(java.nio.file.Path target,
StreamFilter f)
target - the file to rewrite.f - the filter to use.java.lang.NullPointerException - if any argument is null.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException):
Exception if an I/O or any other kind of error occurs.
public static void filter(java.nio.file.Path from,
java.nio.file.Path to,
StreamFilter f)
from - the source file.to - the destination file.f - the filter to use.java.lang.NullPointerException - if any argument is null.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException):
Exception if an I/O or any other kind of error occurs.