Package ch.cern.dirq
Class FileUtils
- java.lang.Object
-
- ch.cern.dirq.FileUtils
-
public final class FileUtils extends java.lang.Object
Convenient file related utilities.
This is a private class to be used only by the directory queue classes. Its API can change at any time without any notice.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.nio.file.attribute.FileAttribute<?>
fileAttributesFromInteger(int perm)
Create NIO file attributes from numerical POSIX permissions.static java.lang.String
fileKey(java.io.File file)
Return a unique string identifying the given file object.static java.lang.String
fileKey(java.lang.String path)
Return a unique string identifying the given path string.static java.lang.String
fileKey(java.nio.file.Path path)
Return a unique string identifying the given path object.private static boolean
isSet(int perm, int bit)
static java.util.Set<java.nio.file.attribute.PosixFilePermission>
posixPermissionsFromInteger(int perm)
Create NIO POSIX file permissions from numerical POSIX permissions.static byte[]
readToByteArray(java.io.File file)
Read all the bytes from a file object.static byte[]
readToByteArray(java.lang.String path)
Read all the bytes from a path string.static byte[]
readToByteArray(java.nio.file.Path path)
Read all the bytes from a path object.static java.lang.String
readToString(java.io.File file)
Read a UTF-8 string from a file object.static java.lang.String
readToString(java.lang.String path)
Read a UTF-8 string from a path string.static java.lang.String
readToString(java.nio.file.Path path)
Read a UTF-8 string from a path object.static boolean
recursiveDelete(java.io.File path)
Recursively delete the given path, stopping on the first error.static void
writeToFile(java.io.File file, byte[] data)
Write bytes to a file object.static void
writeToFile(java.io.File file, java.lang.String data)
Write a UTF-8 string to a file object.static void
writeToFile(java.lang.String path, byte[] data)
Write bytes to a path string.static void
writeToFile(java.lang.String path, java.lang.String data)
Write a UTF-8 string to a path string.static void
writeToFile(java.nio.file.Path path, byte[] data)
Write bytes to a path object.static void
writeToFile(java.nio.file.Path path, java.lang.String data)
Write a UTF-8 string to a path object.
-
-
-
Field Detail
-
S_IRWXU
public static final int S_IRWXU
- See Also:
- Constant Field Values
-
S_IRUSR
public static final int S_IRUSR
- See Also:
- Constant Field Values
-
S_IWUSR
public static final int S_IWUSR
- See Also:
- Constant Field Values
-
S_IXUSR
public static final int S_IXUSR
- See Also:
- Constant Field Values
-
S_IRWXG
public static final int S_IRWXG
- See Also:
- Constant Field Values
-
S_IRGRP
public static final int S_IRGRP
- See Also:
- Constant Field Values
-
S_IWGRP
public static final int S_IWGRP
- See Also:
- Constant Field Values
-
S_IXGRP
public static final int S_IXGRP
- See Also:
- Constant Field Values
-
S_IRWXO
public static final int S_IRWXO
- See Also:
- Constant Field Values
-
S_IROTH
public static final int S_IROTH
- See Also:
- Constant Field Values
-
S_IWOTH
public static final int S_IWOTH
- See Also:
- Constant Field Values
-
S_IXOTH
public static final int S_IXOTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
isSet
private static boolean isSet(int perm, int bit)
-
posixPermissionsFromInteger
public static java.util.Set<java.nio.file.attribute.PosixFilePermission> posixPermissionsFromInteger(int perm)
Create NIO POSIX file permissions from numerical POSIX permissions.
-
fileAttributesFromInteger
public static java.nio.file.attribute.FileAttribute<?> fileAttributesFromInteger(int perm)
Create NIO file attributes from numerical POSIX permissions.
-
fileKey
public static java.lang.String fileKey(java.io.File file) throws java.io.IOException
Return a unique string identifying the given file object.- Throws:
java.io.IOException
-
fileKey
public static java.lang.String fileKey(java.lang.String path) throws java.io.IOException
Return a unique string identifying the given path string.- Throws:
java.io.IOException
-
fileKey
public static java.lang.String fileKey(java.nio.file.Path path) throws java.io.IOException
Return a unique string identifying the given path object.- Throws:
java.io.IOException
-
writeToFile
public static void writeToFile(java.io.File file, java.lang.String data) throws java.io.IOException
Write a UTF-8 string to a file object.- Throws:
java.io.IOException
-
writeToFile
public static void writeToFile(java.lang.String path, java.lang.String data) throws java.io.IOException
Write a UTF-8 string to a path string.- Throws:
java.io.IOException
-
writeToFile
public static void writeToFile(java.nio.file.Path path, java.lang.String data) throws java.io.IOException
Write a UTF-8 string to a path object.- Throws:
java.io.IOException
-
writeToFile
public static void writeToFile(java.io.File file, byte[] data) throws java.io.IOException
Write bytes to a file object.- Throws:
java.io.IOException
-
writeToFile
public static void writeToFile(java.lang.String path, byte[] data) throws java.io.IOException
Write bytes to a path string.- Throws:
java.io.IOException
-
writeToFile
public static void writeToFile(java.nio.file.Path path, byte[] data) throws java.io.IOException
Write bytes to a path object.- Throws:
java.io.IOException
-
readToString
public static java.lang.String readToString(java.io.File file) throws java.io.IOException
Read a UTF-8 string from a file object.- Throws:
java.io.IOException
-
readToString
public static java.lang.String readToString(java.lang.String path) throws java.io.IOException
Read a UTF-8 string from a path string.- Throws:
java.io.IOException
-
readToString
public static java.lang.String readToString(java.nio.file.Path path) throws java.io.IOException
Read a UTF-8 string from a path object.- Throws:
java.io.IOException
-
readToByteArray
public static byte[] readToByteArray(java.io.File file) throws java.io.IOException
Read all the bytes from a file object.- Throws:
java.io.IOException
-
readToByteArray
public static byte[] readToByteArray(java.lang.String path) throws java.io.IOException
Read all the bytes from a path string.- Throws:
java.io.IOException
-
readToByteArray
public static byte[] readToByteArray(java.nio.file.Path path) throws java.io.IOException
Read all the bytes from a path object.- Throws:
java.io.IOException
-
recursiveDelete
public static boolean recursiveDelete(java.io.File path)
Recursively delete the given path, stopping on the first error.
-
-