类 IOUtil
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static voidcopy(InputStream is, OutputStream os) Copies the content of anInputStreamto anOutputStream.static voidCopies the content of anReadableByteChannelinto anWritableByteChannel.static voidfill(ReadableByteChannel channel, ByteBuffer buffer) Readsbuffer.remaining()bytes from the channel into the buffer.static byte[]Returns a static per-thread cached 32k buffer for IO operations.static FileSystemgetFileSystem(URI uri) Attempts to get an already existingFileSystem.static FileSystemgetFileSystem(URI uri, Map<String, ?> env) Attempts to get or create aFileSystemfor the given uri, with additional arguments for FS creation.static FileSystemgetJarFileSystem(URI path, boolean create) Creates a newFileSystemfor the given uri path.static FileSystemgetJarFileSystem(Path path, boolean create) Creates a newFileSystemfor the given jar path.static PathmakeParents(Path path) Creates the parent directories of the given path if they don't exist.static Set<PosixFilePermission>parseMode(int mode) Converts a Posix 'file mode' into a set ofPosixFilePermissions.static InputStreamwraps the givenInputStreamprotecting it againstInputStream.close()operations.static OutputStreamwraps the givenOutputStreamprotecting it againstOutputStream.close()operations.static FileSystemwraps the givenFileSystemprotecting it againstFileSystem.close()operations.readAll(byte[] bytes) Reads the provided array of bytes into a List of UTF-8 Strings.Reads the provided array of bytes into a List of Strings in the givenCharset.static Stringstatic Stringstatic voidCopes every element in a Jar file from the input to the Jar file output, where every element must match the providedPredicate.static byte[]toBytes(InputStream is) Reads anInputStreamto a byte array.static intwriteMode(Set<PosixFilePermission> perms) Writes a set ofPosixFilePermissions to a Posix 'file mode' integer.
-
构造器详细资料
-
IOUtil
public IOUtil()
-
-
方法详细资料
-
getCachedBuffer
public static byte[] getCachedBuffer()Returns a static per-thread cached 32k buffer for IO operations.- 返回:
- The buffer.
-
copy
public static void copy(@WillNotClose InputStream is, @WillNotClose OutputStream os) throws IOException Copies the content of anInputStreamto anOutputStream.- 参数:
is- TheInputStream.os- TheOutputStream.- 抛出:
IOException- If something is bork.
-
copy
public static void copy(@WillNotClose ReadableByteChannel rc, @WillNotClose WritableByteChannel wc) throws IOException Copies the content of anReadableByteChannelinto anWritableByteChannel.This method makes use of direct
ByteBufferinstances.- 参数:
rc- TheReadableByteChannelto copy from.wc- TheWritableByteChannelto copy to.- 抛出:
IOException- If an IO Error occurred whilst copying.
-
fill
public static void fill(@WillNotClose ReadableByteChannel channel, ByteBuffer buffer) throws IOException Readsbuffer.remaining()bytes from the channel into the buffer.This method blocks until the requested bytes are read.
If the stream ends prior to the requested number of bytes an
EOFExceptionis thrown.- 参数:
channel- The channel to read from.buffer- The buffer to fill.- 抛出:
IOException
-
toBytes
Reads anInputStreamto a byte array.- 参数:
is- The InputStream.- 返回:
- The bytes.
- 抛出:
IOException- If something is bork.
-
readAll
Reads the provided array of bytes into a List of UTF-8 Strings.- 参数:
bytes- The bytes of the strings.- 返回:
- The lines.
- 抛出:
IOException- Any exception thrown reading the bytes.
-
readAll
Reads the provided array of bytes into a List of Strings in the givenCharset.- 参数:
bytes- The bytes of the strings.- 返回:
- The lines.
- 抛出:
IOException- Any exception thrown reading the bytes.
-
readAll
- 参数:
path- The path to read.- 返回:
- The
String. - 抛出:
IOException- If there was an error reading the file.
-
readAll
- 参数:
path- The path to read.charset- TheCharset.- 返回:
- The
String. - 抛出:
IOException- If there was an error reading the file.
-
makeParents
Creates the parent directories of the given path if they don't exist.- 参数:
path- The path.- 返回:
- The same path.
- 抛出:
IOException- If an error occurs creating the directories.
-
getJarFileSystem
Creates a newFileSystemfor the given jar path.If a FS was not created by this method due to it already existing, this method will guard the returned
FileSystemfrom being closed viaFileSystem.close(). This means it's safe to use try-with-resources when you don't explicitly own theFileSystem.- 参数:
path- The file to open the jar for.create- If the file system should attempt to be created if it does not exist.- 返回:
- The
FileSystem. - 抛出:
IOException- If theFileSystemcould not be created.
-
getJarFileSystem
Creates a newFileSystemfor the given uri path.If a FS was not created by this method due to it already existing, this method will guard the returned
FileSystemfrom being closed viaFileSystem.close(). This means it's safe to use try-with-resources when you don't explicitly own theFileSystem.- 参数:
path- The uri to open the jar for.create- If the file system should attempt to be created if it does not exist.- 返回:
- The
FileSystem. - 抛出:
IOException- If theFileSystemcould not be created.
-
getFileSystem
Attempts to get an already existingFileSystem.This method will guard the returned
FileSystemfrom being closed viaFileSystem.close(). This means it's safe to use try-with-resources when you don't explicitly own theFileSystem.- 参数:
uri- The uri to open the jar for.- 返回:
- The
FileSystem. - 抛出:
IOException- If theFileSystemcould not be created.
-
getFileSystem
Attempts to get or create aFileSystemfor 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
FileSystemfrom being closed viaFileSystem.close(). This means it's safe to use try-with-resources when you don't explicitly own theFileSystem.- 参数:
uri- The uri to open the jar for.env- Any additional arguments to provide when creating theFileSystem.- 返回:
- The
FileSystem. - 抛出:
IOException- If theFileSystemcould not be created.
-
protectClose
wraps the givenFileSystemprotecting it againstFileSystem.close()operations.- 参数:
fs- TheFileSystemto wrap.- 返回:
- The wrapped
FileSystem.
-
protectClose
wraps the givenInputStreamprotecting it againstInputStream.close()operations.- 参数:
is- TheInputStreamto wrap.- 返回:
- The wrapped
InputStream.
-
protectClose
wraps the givenOutputStreamprotecting it againstOutputStream.close()operations.- 参数:
os- TheOutputStreamto wrap.- 返回:
- The wrapped
OutputStream.
-
stripJar
Copes every element in a Jar file from the input to the Jar file output, where every element must match the providedPredicate.- 参数:
input- The Input Path. This should exist.output- The Output Path. This should not exists.predicate- ThePredicatethat each Entry must match.- 抛出:
IOException- If something went wrong during execution.
-
parseMode
Converts a Posix 'file mode' into a set ofPosixFilePermissions.Thanks: https://stackoverflow.com/a/54422530/11313544
- 参数:
mode- The file mode.- 返回:
- The parsed permissions.
-
writeMode
Writes a set ofPosixFilePermissions to a Posix 'file mode' integer.- 参数:
perms- The permissions.- 返回:
- The 'file mode'.
-