Package org.h2.util
Class IOUtils
java.lang.Object
org.h2.util.IOUtils
This utility class contains input/output functions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Close an AutoCloseable without throwing an exception.static long
copy
(InputStream in, OutputStream out) Copy all data from the input stream to the output stream.static long
copy
(InputStream in, OutputStream out, long length) Copy all data from the input stream to the output stream.static long
copyAndClose
(InputStream in, OutputStream out) Copy all data from the input stream to the output stream and close both streams.static long
copyAndCloseInput
(InputStream in, OutputStream out) Copy all data from the input stream to the output stream and close the input stream.static long
copyAndCloseInput
(Reader in, Writer out, long length) Copy all data from the reader to the writer and close the reader.static void
Copy a file from one directory to another, or to another file.static Reader
Wrap an input stream in a reader.static Writer
Create a buffered writer to write to an output stream using the UTF-8 format.static InputStream
Create an input stream to read from a string.static Reader
getReader
(InputStream in) Create a reader to read from an input stream using the UTF-8 format.static String
nameSeparatorsToNative
(String path) Converts / and \ name separators in path to native separators.static byte[]
readBytesAndClose
(InputStream in, int length) Read a number of bytes from an input stream and close the stream.static int
readFully
(InputStream in, byte[] buffer, int max) Try to read the given number of bytes to the buffer.static int
Try to read the given number of characters to the buffer.static String
readStringAndClose
(Reader in, int length) Read a number of characters from a reader and close it.static void
skipFully
(InputStream in, long skip) Skip a number of bytes in an input stream.static void
Skip a number of characters in a reader.static void
Trace input or output operations if enabled.
-
Constructor Details
-
IOUtils
private IOUtils()
-
-
Method Details
-
closeSilently
Close an AutoCloseable without throwing an exception.- Parameters:
out
- the AutoCloseable or null
-
skipFully
Skip a number of bytes in an input stream.- Parameters:
in
- the input streamskip
- the number of bytes to skip- Throws:
EOFException
- if the end of file has been reached before all bytes could be skippedIOException
- if an IO exception occurred while skipping
-
skipFully
Skip a number of characters in a reader.- Parameters:
reader
- the readerskip
- the number of characters to skip- Throws:
EOFException
- if the end of file has been reached before all characters could be skippedIOException
- if an IO exception occurred while skipping
-
copyAndClose
Copy all data from the input stream to the output stream and close both streams. Exceptions while closing are ignored.- Parameters:
in
- the input streamout
- the output stream- Returns:
- the number of bytes copied
- Throws:
IOException
- on failure
-
copyAndCloseInput
Copy all data from the input stream to the output stream and close the input stream. Exceptions while closing are ignored.- Parameters:
in
- the input streamout
- the output stream (null if writing is not required)- Returns:
- the number of bytes copied
- Throws:
IOException
- on failure
-
copy
Copy all data from the input stream to the output stream. Both streams are kept open.- Parameters:
in
- the input streamout
- the output stream (null if writing is not required)- Returns:
- the number of bytes copied
- Throws:
IOException
- on failure
-
copy
Copy all data from the input stream to the output stream. Both streams are kept open.- Parameters:
in
- the input streamout
- the output stream (null if writing is not required)length
- the maximum number of bytes to copy- Returns:
- the number of bytes copied
- Throws:
IOException
- on failure
-
copyAndCloseInput
Copy all data from the reader to the writer and close the reader. Exceptions while closing are ignored.- Parameters:
in
- the readerout
- the writer (null if writing is not required)length
- the maximum number of bytes to copy- Returns:
- the number of characters copied
- Throws:
IOException
- on failure
-
readBytesAndClose
Read a number of bytes from an input stream and close the stream.- Parameters:
in
- the input streamlength
- the maximum number of bytes to read, or -1 to read until the end of file- Returns:
- the bytes read
- Throws:
IOException
- on failure
-
readStringAndClose
Read a number of characters from a reader and close it.- Parameters:
in
- the readerlength
- the maximum number of characters to read, or -1 to read until the end of file- Returns:
- the string read
- Throws:
IOException
- on failure
-
readFully
Try to read the given number of bytes to the buffer. This method reads until the maximum number of bytes have been read or until the end of file.- Parameters:
in
- the input streambuffer
- the output buffermax
- the number of bytes to read at most- Returns:
- the number of bytes read, 0 meaning EOF
- Throws:
IOException
- on failure
-
readFully
Try to read the given number of characters to the buffer. This method reads until the maximum number of characters have been read or until the end of file.- Parameters:
in
- the readerbuffer
- the output buffermax
- the number of characters to read at most- Returns:
- the number of characters read, 0 meaning EOF
- Throws:
IOException
- on failure
-
getReader
Create a reader to read from an input stream using the UTF-8 format. If the input stream is null, this method returns null. The InputStreamReader that is used here is not exact, that means it may read some additional bytes when buffering.- Parameters:
in
- the input stream or null- Returns:
- the reader
-
getBufferedWriter
Create a buffered writer to write to an output stream using the UTF-8 format. If the output stream is null, this method returns null.- Parameters:
out
- the output stream or null- Returns:
- the writer
-
getAsciiReader
Wrap an input stream in a reader. The bytes are converted to characters using the US-ASCII character set.- Parameters:
in
- the input stream- Returns:
- the reader
-
trace
Trace input or output operations if enabled.- Parameters:
method
- the method from where this method was calledfileName
- the file nameo
- the object to append to the message
-
getInputStreamFromString
Create an input stream to read from a string. The string is converted to a byte array using UTF-8 encoding. If the string is null, this method returns null.- Parameters:
s
- the string- Returns:
- the input stream
-
copyFiles
Copy a file from one directory to another, or to another file.- Parameters:
original
- the original file namecopy
- the file name of the copy- Throws:
IOException
- on failure
-
nameSeparatorsToNative
Converts / and \ name separators in path to native separators.- Parameters:
path
- path to convert- Returns:
- path with converted separators
-