public final class JkPathFile
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
void |
assertExist() |
JkPathFile |
copyReplacingTokens(java.nio.file.Path to,
java.util.Map<java.lang.String,java.lang.String> tokens,
java.nio.charset.Charset charset)
Creates a copy of this file replacing all occurrences of specified map keys by their matching value.
|
JkPathFile |
copyToDir(java.nio.file.Path dir,
java.nio.file.CopyOption... options)
Copies this file to the specified directory.
|
JkPathFile |
createChecksumFiles(java.lang.String... algorithms)
Creates sibling files containing the checksum of this file.
|
JkPathFile |
createIfNotExist()
Creates a file at this location if such file does not exist yet.
|
JkPathFile |
deleteIfExist()
Deletes this file if exists.
|
void |
dos2Unix(java.nio.file.Path target) |
boolean |
exists()
Returns
true if a file already exists at this location. |
JkPathFile |
fetchContentFrom(java.lang.String urlString)
Gets the contents of the specified url, and write it to this file.
|
JkPathFile |
fetchContentFrom(java.net.URL url)
Copies the content of the specified url into this file, replacing the previous content.
|
java.nio.file.Path |
get()
Returns the underlying path.
|
java.lang.String |
getChecksum(java.lang.String algorithm)
Returns an ASCII string representation of the checksum of this file for the specified algorithm.
|
java.lang.String |
getExtension() |
JkPathFile |
move(java.nio.file.Path to,
java.nio.file.CopyOption... options)
Moves this file to the specified file location
|
static JkPathFile |
of(java.nio.file.Path path)
Creates a
JkPathFile instance from the specified path. |
static JkPathFile |
of(java.lang.String path) |
static JkPathFile |
of(java.net.URL url) |
static JkPathFile |
ofTemp(java.lang.String prefix,
java.lang.String extension,
java.nio.file.attribute.FileAttribute... fileAttributes)
Creates a temp file wrapped by a JkPathFile.
|
java.util.List<java.lang.String> |
readAsLines()
Returns the content of this file as a List of strings, where each element represents a line in the file.
|
java.lang.String |
readAsString()
Returns the content of this file as a String encoded in UTF-8
|
JkPathFile |
setPosixExecPermissions() |
JkPathFile |
setPosixExecPermissions(boolean owner,
boolean group,
boolean other)
Adds execute permissions on this file.
|
java.lang.String |
toString() |
JkPathFile |
touch()
Updates the last modified time of the underlying file to the current time.
|
JkPathFile |
write(byte[] bytes,
java.nio.file.OpenOption... options)
Shorthand for
Files.write(Path, byte[], OpenOption...) |
JkPathFile |
write(java.lang.String contentUtf8,
java.nio.file.OpenOption... options)
Writes the specified UTF-8 encoded String to this file.
|
public static JkPathFile of(java.nio.file.Path path)
JkPathFile
instance from the specified path.public static JkPathFile of(java.lang.String path)
of(Path)
public static JkPathFile of(java.net.URL url)
public static JkPathFile ofTemp(java.lang.String prefix, java.lang.String extension, java.nio.file.attribute.FileAttribute... fileAttributes)
public java.nio.file.Path get()
public JkPathFile createIfNotExist()
public JkPathFile copyReplacingTokens(java.nio.file.Path to, java.util.Map<java.lang.String,java.lang.String> tokens, java.nio.charset.Charset charset)
public JkPathFile copyToDir(java.nio.file.Path dir, java.nio.file.CopyOption... options)
public JkPathFile move(java.nio.file.Path to, java.nio.file.CopyOption... options)
to
- The destination file path. This is not the parent directory destination.public JkPathFile fetchContentFrom(java.net.URL url)
public JkPathFile fetchContentFrom(java.lang.String urlString)
fetchContentFrom(URL)
public boolean exists()
true
if a file already exists at this location.public JkPathFile deleteIfExist()
public java.lang.String getChecksum(java.lang.String algorithm)
algorithm
- Hashing algorithm as MD5, SHA-2, ...public JkPathFile write(byte[] bytes, java.nio.file.OpenOption... options)
Files.write(Path, byte[], OpenOption...)
public JkPathFile write(java.lang.String contentUtf8, java.nio.file.OpenOption... options)
public java.lang.String readAsString()
public java.util.List<java.lang.String> readAsLines()
public JkPathFile createChecksumFiles(java.lang.String... algorithms)
public JkPathFile setPosixExecPermissions(boolean owner, boolean group, boolean other)
public JkPathFile setPosixExecPermissions()
public JkPathFile touch()
JkPathFile
instance, allowing method chaining.public void assertExist()
public java.lang.String getExtension()
public void dos2Unix(java.nio.file.Path target)
public java.lang.String toString()
toString
in class java.lang.Object