public class IOUtils
extends java.lang.Object
Created by covers1624 on 14/1/21.
| Constructor and Description |
|---|
IOUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
copy(java.io.InputStream is,
java.io.OutputStream os)
Copies the content of an
InputStream to an OutputStream. |
static byte[] |
getCachedBuffer()
Returns a static per-thread cached 32k buffer for IO operations.
|
static java.nio.file.FileSystem |
getFileSystem(java.net.URI uri)
Attempts to get an already existing
FileSystem. |
static java.nio.file.FileSystem |
getFileSystem(java.net.URI uri,
java.util.Map<java.lang.String,?> env)
Attempts to get or create a
FileSystem for the given uri, with additional arguments for FS creation. |
static java.nio.file.FileSystem |
getJarFileSystem(java.nio.file.Path path,
boolean create)
Creates a new
FileSystem for the given jar path. |
static java.nio.file.FileSystem |
getJarFileSystem(java.net.URI path,
boolean create)
Creates a new
FileSystem for the given uri path. |
static java.nio.file.Path |
makeParents(java.nio.file.Path path)
Creates the parent directories of the given path if they don't exist.
|
static java.util.Set<java.nio.file.attribute.PosixFilePermission> |
parseMode(int mode)
Converts a Posix 'file mode' into a set of
PosixFilePermissions. |
static java.nio.file.FileSystem |
protectClose(java.nio.file.FileSystem fs)
wraps the given
FileSystem protecting it against FileSystem.close() operations. |
static java.io.InputStream |
protectClose(java.io.InputStream is)
wraps the given
InputStream protecting it against InputStream.close() operations. |
static java.io.OutputStream |
protectClose(java.io.OutputStream os)
wraps the given
OutputStream protecting it against OutputStream.close() operations. |
static java.util.List<java.lang.String> |
readAll(byte[] bytes)
Reads the provided array of bytes into a List of UTF-8 Strings.
|
static java.util.List<java.lang.String> |
readAll(byte[] bytes,
java.nio.charset.Charset charset)
Reads the provided array of bytes into a List of Strings
in the given
Charset. |
static java.lang.String |
readAll(java.nio.file.Path path)
Read the entire content of the provided
Path into a
UTF-8 String. |
static java.lang.String |
readAll(java.nio.file.Path path,
java.nio.charset.Charset charset)
Read the entire content of the provided
Path into a
String with the given charset. |
static void |
stripJar(java.nio.file.Path input,
java.nio.file.Path output,
java.util.function.Predicate<java.nio.file.Path> predicate)
Copes every element in a Jar file from the input to the Jar file output, where every
element must match the provided
Predicate. |
static byte[] |
toBytes(java.io.InputStream is)
Reads an
InputStream to a byte array. |
static int |
writeMode(java.util.Set<java.nio.file.attribute.PosixFilePermission> perms)
Writes a set of
PosixFilePermissions to a Posix 'file mode' integer. |
public static byte[] getCachedBuffer()
public static void copy(@WillNotClose
java.io.InputStream is,
@WillNotClose
java.io.OutputStream os)
throws java.io.IOException
InputStream to an OutputStream.is - The InputStream.os - The OutputStream.java.io.IOException - If something is bork.public static byte[] toBytes(@WillNotClose
java.io.InputStream is)
throws java.io.IOException
InputStream to a byte array.is - The InputStream.java.io.IOException - If something is bork.public static java.util.List<java.lang.String> readAll(byte[] bytes)
throws java.io.IOException
bytes - The bytes of the strings.java.io.IOException - Any exception thrown reading the bytes.public static java.util.List<java.lang.String> readAll(byte[] bytes,
java.nio.charset.Charset charset)
throws java.io.IOException
Charset.bytes - The bytes of the strings.java.io.IOException - Any exception thrown reading the bytes.public static java.lang.String readAll(java.nio.file.Path path)
throws java.io.IOException
Path into a
UTF-8 String.path - The path to read.String.java.io.IOException - If there was an error reading the file.public static java.lang.String readAll(java.nio.file.Path path,
java.nio.charset.Charset charset)
throws java.io.IOException
Path into a
String with the given charset.path - The path to read.charset - The Charset.String.java.io.IOException - If there was an error reading the file.public static java.nio.file.Path makeParents(java.nio.file.Path path)
throws java.io.IOException
path - The path.java.io.IOException - If an error occurs creating the directories.public static java.nio.file.FileSystem getJarFileSystem(java.nio.file.Path path,
boolean create)
throws java.io.IOException
FileSystem for the given jar path.
If a FS was not created by this method due to it already existing, this method
will guard the returned FileSystem from being closed via FileSystem.close().
This means it's safe to use try-with-resources when you don't explicitly own the FileSystem.
path - The file to open the jar for.create - If the file system should attempt to be created if it does not exist.FileSystem.java.io.IOException - If the FileSystem could not be created.public static java.nio.file.FileSystem getJarFileSystem(java.net.URI path,
boolean create)
throws java.io.IOException
FileSystem for the given uri path.
If a FS was not created by this method due to it already existing, this method
will guard the returned FileSystem from being closed via FileSystem.close().
This means it's safe to use try-with-resources when you don't explicitly own the FileSystem.
path - The uri to open the jar for.create - If the file system should attempt to be created if it does not exist.FileSystem.java.io.IOException - If the FileSystem could not be created.public static java.nio.file.FileSystem getFileSystem(java.net.URI uri)
throws java.io.IOException
FileSystem.
This method will guard the returned FileSystem from being closed via FileSystem.close().
This means it's safe to use try-with-resources when you don't explicitly own the FileSystem.
uri - The uri to open the jar for.FileSystem.java.io.IOException - If the FileSystem could not be created.public static java.nio.file.FileSystem getFileSystem(java.net.URI uri,
java.util.Map<java.lang.String,?> env)
throws java.io.IOException
FileSystem for the given uri, with additional arguments for FS creation.
If a FS was not created by this method due to it already existing, this method
will guard the returned FileSystem from being closed via FileSystem.close().
This means it's safe to use try-with-resources when you don't explicitly own the FileSystem.
uri - The uri to open the jar for.env - Any additional arguments to provide when creating the FileSystem.FileSystem.java.io.IOException - If the FileSystem could not be created.public static java.nio.file.FileSystem protectClose(java.nio.file.FileSystem fs)
FileSystem protecting it against FileSystem.close() operations.fs - The FileSystem to wrap.FileSystem.public static java.io.InputStream protectClose(java.io.InputStream is)
InputStream protecting it against InputStream.close() operations.is - The InputStream to wrap.InputStream.public static java.io.OutputStream protectClose(java.io.OutputStream os)
OutputStream protecting it against OutputStream.close() operations.os - The OutputStream to wrap.OutputStream.public static void stripJar(java.nio.file.Path input,
java.nio.file.Path output,
java.util.function.Predicate<java.nio.file.Path> predicate)
throws java.io.IOException
Predicate.input - The Input Path. This should exist.output - The Output Path. This should not exists.predicate - The Predicate that each Entry must match.java.io.IOException - If something went wrong during execution.public static java.util.Set<java.nio.file.attribute.PosixFilePermission> parseMode(int mode)
PosixFilePermissions.
Thanks: https://stackoverflow.com/a/54422530/11313544
mode - The file mode.public static int writeMode(java.util.Set<java.nio.file.attribute.PosixFilePermission> perms)
PosixFilePermissions to a Posix 'file mode' integer.perms - The permissions.