Class IOUtils
java.lang.Object
com.blackrook.gloop.opengl.struct.IOUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidAttempts to close aCloseableobject.static voidAttempts to close anAutoCloseableobject.static StringRetrieves the ASCII contents of a file.static byte[]Retrieves the binary contents of a file.static byte[]Retrieves the binary contents of a stream until it hits the end of the stream.static byte[]getBinaryContents(InputStream in, int len) Retrieves the binary contents of a stream.static StringgetLine()Reads a line from standard in; throws a RuntimeException if something absolutely serious happens.static Filestatic InputStreamstatic OutputStreamstatic intstatic StringRetrieves the textual contents of a file in the system's current encoding.static StringRetrieves the textual contents of a stream in the system's current encoding.static StringgetTextualContents(InputStream in, String encoding) Retrieves the textual contents of a stream.static InputStreamopenResource(ClassLoader classLoader, String pathString) Opens anInputStreamto a resource using a provided ClassLoader.static InputStreamopenResource(String pathString) Opens anInputStreamto a resource using the current thread'sClassLoader.static BufferedReaderConvenience method fornew BufferedReader(new InputStreamReader(System.in))static BufferedReaderopenTextFile(File file) Convenience method fornew BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.defaultCharset()))static BufferedReaderopenTextFile(File file, Charset encoding) Convenience method fornew BufferedReader(new InputStreamReader(new FileInputStream(file), encoding))static BufferedReaderopenTextFile(String filePath) Convenience method fornew BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)), Charset.defaultCharset()))static BufferedReaderopenTextFile(String filePath, Charset encoding) Convenience method fornew BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)), encoding))static BufferedReaderConvenience method fornew BufferedReader(new InputStreamReader(in, Charset.defaultCharset()))static BufferedReaderopenTextStream(InputStream in, Charset encoding) Convenience method fornew BufferedReader(new InputStreamReader(in, encoding))static intrelay(InputStream in, OutputStream out) Reads from an input stream, reading in a consistent set of data and writing it to the output stream.static intrelay(InputStream in, OutputStream out, int bufferSize) Reads from an input stream, reading in a consistent set of data and writing it to the output stream.static intrelay(InputStream in, OutputStream out, int bufferSize, int maxLength) Reads from an input stream, reading in a consistent set of data and writing it to the output stream.static intReads from an input stream, reading in a consistent set of data and writing it to the output stream.static intReads from an input stream, reading in a consistent set of data and writing it to the output stream.static intReads from an input stream, reading in a consistent set of data and writing it to the output stream.static voidsetRelayBufferSize(int size) Sets the size of the buffer in bytes forrelay(InputStream, OutputStream).
-
Method Details
-
openTextStream
Convenience method fornew BufferedReader(new InputStreamReader(in, Charset.defaultCharset()))- Parameters:
in- the stream to read.- Returns:
- an open buffered reader for the provided stream.
- Throws:
IOException- if an error occurred opening the stream for reading.SecurityException- if you do not have permission for opening the stream.
-
openTextStream
Convenience method fornew BufferedReader(new InputStreamReader(in, encoding))- Parameters:
in- the stream to read.encoding- the text encoding to use.- Returns:
- an open buffered reader for the provided stream.
- Throws:
IOException- if an error occurred opening the stream for reading.SecurityException- if you do not have permission for opening the stream.
-
openTextFile
Convenience method fornew BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.defaultCharset()))- Parameters:
file- the file to open.- Returns:
- an open buffered reader for the provided file.
- Throws:
IOException- if an error occurred opening the file for reading.SecurityException- if you do not have permission for opening the file.
-
openTextFile
Convenience method fornew BufferedReader(new InputStreamReader(new FileInputStream(file), encoding))- Parameters:
file- the file to open.encoding- the text encoding to use.- Returns:
- an open buffered reader for the provided file.
- Throws:
IOException- if an error occurred opening the file for reading.SecurityException- if you do not have permission for opening the file.
-
openTextFile
Convenience method fornew BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)), Charset.defaultCharset()))- Parameters:
filePath- the path of the file to open.- Returns:
- an open buffered reader for the provided path.
- Throws:
IOException- if an error occurred opening the file for reading.SecurityException- if you do not have permission for opening the file.
-
openTextFile
Convenience method fornew BufferedReader(new InputStreamReader(new FileInputStream(new File(filePath)), encoding))- Parameters:
filePath- the path of the file to open.encoding- the text encoding to use.- Returns:
- an open buffered reader for the provided path.
- Throws:
IOException- if an error occurred opening the file for reading.SecurityException- if you do not have permission for opening the file.
-
openSystemIn
Convenience method fornew BufferedReader(new InputStreamReader(System.in))- Returns:
- an open buffered reader for
System.in. - Throws:
IOException- if an error occurred opening Standard IN.SecurityException- if you do not have permission for opening Standard IN.
-
openResource
Opens anInputStreamto a resource using the current thread'sClassLoader.- Parameters:
pathString- the resource pathname.- Returns:
- an open
InputStreamfor reading the resource or null if not found. - See Also:
-
openResource
Opens anInputStreamto a resource using a provided ClassLoader.- Parameters:
classLoader- the providedClassLoaderto use.pathString- the resource pathname.- Returns:
- an open
InputStreamfor reading the resource or null if not found. - See Also:
-
getASCIIContents
Retrieves the ASCII contents of a file.- Parameters:
f- the file to use.- Returns:
- a contiguous string (including newline characters) of the file's contents.
- Throws:
FileNotFoundException- if the file cannot be found.IOException- if the read cannot be done.
-
getTextualContents
Retrieves the textual contents of a file in the system's current encoding.- Parameters:
f- the file to use.- Returns:
- a contiguous string (including newline characters) of the file's contents.
- Throws:
IOException- if the read cannot be done.
-
getTextualContents
Retrieves the textual contents of a stream in the system's current encoding.- Parameters:
in- the input stream to use.- Returns:
- a contiguous string (including newline characters) of the stream's contents.
- Throws:
IOException- if the read cannot be done.
-
getTextualContents
Retrieves the textual contents of a stream.- Parameters:
in- the input stream to use.encoding- name of the encoding type.- Returns:
- a contiguous string (including newline characters) of the stream's contents.
- Throws:
IOException- if the read cannot be done.
-
getBinaryContents
Retrieves the binary contents of a file.- Parameters:
f- the file to use.- Returns:
- an array of the bytes that make up the file.
- Throws:
FileNotFoundException- if the file cannot be found.IOException- if the read cannot be done.
-
getBinaryContents
Retrieves the binary contents of a stream.- Parameters:
in- the input stream to use.len- the amount of bytes to read.- Returns:
- an array of len bytes that make up the stream.
- Throws:
IOException- if the read cannot be done.
-
getBinaryContents
Retrieves the binary contents of a stream until it hits the end of the stream.- Parameters:
in- the input stream to use.- Returns:
- an array of len bytes that make up the data in the stream.
- Throws:
IOException- if the read cannot be done.
-
relay
Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.- Parameters:
in- the input stream to grab data from.out- the output stream to write the data to.- Returns:
- the total amount of bytes relayed.
- Throws:
IOException- if a read or write error occurs.
-
relay
Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.- Parameters:
in- the input stream to grab data from.out- the output stream to write the data to.bufferSize- the buffer size for the I/O. Must be > 0.- Returns:
- the total amount of bytes relayed.
- Throws:
IOException- if a read or write error occurs.
-
relay
public static int relay(InputStream in, OutputStream out, int bufferSize, int maxLength) throws IOException Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.- Parameters:
in- the input stream to grab data from.out- the output stream to write the data to.bufferSize- the buffer size for the I/O. Must be > 0.maxLength- the maximum amount of bytes to relay, or a value < 0 for no max.- Returns:
- the total amount of bytes relayed.
- Throws:
IOException- if a read or write error occurs.
-
relay
Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.- Parameters:
reader- the reader to grab characters from.writer- the writer to write the characters to.- Returns:
- the total amount of characters relayed.
- Throws:
IOException- if a read or write error occurs.
-
relay
Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.- Parameters:
reader- the reader to grab characters from.writer- the writer to write the characters to.bufferSize- the buffer size in characters for the I/O. Must be > 0.- Returns:
- the total amount of characters relayed.
- Throws:
IOException- if a read or write error occurs.
-
relay
public static int relay(Reader reader, Writer writer, int bufferSize, int maxLength) throws IOException Reads from an input stream, reading in a consistent set of data and writing it to the output stream. The read/write is buffered so that it does not bog down the OS's other I/O requests. This method finishes when the end of the source stream is reached. Note that this may block if the input stream is a type of stream that will block if the input stream blocks for additional input. This method is thread-safe.- Parameters:
reader- the reader to grab characters from.writer- the writer to write the characters to.bufferSize- the buffer size in characters for the I/O. Must be > 0.maxLength- the maximum amount of characters to relay, or a value < 0 for no max.- Returns:
- the total amount of characters relayed.
- Throws:
IOException- if a read or write error occurs.
-
setRelayBufferSize
public static void setRelayBufferSize(int size) Sets the size of the buffer in bytes forrelay(InputStream, OutputStream). Although you may not encounter this problem, it would be unwise to set this during a call to relay(). Size cannot be 0 or less.- Parameters:
size- the size of the relay buffer.
-
getRelayBufferSize
public static int getRelayBufferSize()- Returns:
- the size of the relay buffer for
relay(InputStream, OutputStream)in bytes.
-
getLine
Reads a line from standard in; throws a RuntimeException if something absolutely serious happens. Should be used just for convenience.- Returns:
- a single line read from Standard In.
- See Also:
-
getNullOutputStream
- Returns:
- a null output stream, where all writes are accepted and not used.
-
getNullInputStream
- Returns:
- a null input stream, where all reads result in an end-of-stream.
-
getNullFile
- Returns:
- a handle to the null file for this platform.
-
close
-
close
Attempts to close anAutoCloseableobject. If the object is null, this does nothing.- Parameters:
c- the reference to the AutoCloseable object.
-