open class IOUtils
General IO stream manipulation utilities.
This class provides static utility methods for input/output operations.
The byte-to-char methods and char-to-byte methods involve a conversion step. Two methods are provided in each case, one that uses the platform default encoding and the other which allows you to specify an encoding. You are encouraged to always specify an encoding because relying on the platform default can lead to unexpected results, for example when moving from development to production.
All the methods in this class that read a stream are buffered internally. This means that there is no cause to use a BufferedInputStream
or BufferedReader
. The default buffer size of 4K has been shown to be efficient in tests.
Wherever possible, the methods in this class do not flush or close the stream. This is to avoid making non-portable assumptions about the streams' origin and further use. Thus the caller is still responsible for closing streams after use.
Origin of code: Excalibur.
Author
Peter Donald
Author
Jeff Turner
Author
Matthew Hawthorne
Author
Stephen Colebourne
Author
Gareth Davis
Author
Ian Springer
Author
Niall Pemberton
Author
Sandy McArthur
Version
$Id: IOUtils.java 481854 2006-12-03 18:30:07Z scolebourne $
IOUtils()
Instances should NOT be constructed in standard programming. |
static val DIR_SEPARATOR: Char
The system directory separator character. |
|
static val DIR_SEPARATOR_UNIX: Char
The Unix directory separator character. |
|
static val DIR_SEPARATOR_WINDOWS: Char
The Windows directory separator character. |
|
static val LINE_SEPARATOR: String!
The system line separator string. |
|
static val LINE_SEPARATOR_UNIX: String
The Unix line separator string. |
|
static val LINE_SEPARATOR_WINDOWS: String
The Windows line separator string. |
open static fun closeQuietly(input: Reader!): Unit
Unconditionally close an open static fun closeQuietly(output: Writer!): Unit
Unconditionally close a open static fun closeQuietly(input: InputStream!): Unit
Unconditionally close an open static fun closeQuietly(output: OutputStream!): Unit
Unconditionally close an |
|
open static fun contentEquals(input1: InputStream!, input2: InputStream!): Boolean
Compare the contents of two Streams to determine if they are equal or not. open static fun contentEquals(input1: Reader!, input2: Reader!): Boolean
Compare the contents of two Readers to determine if they are equal or not. |
|
open static fun copy(input: InputStream!, output: OutputStream!): Int
Copy bytes from an open static fun copy(input: InputStream!, output: Writer!): Unit
Copy bytes from an open static fun copy(input: InputStream!, output: Writer!, encoding: String!): Unit
Copy bytes from an open static fun copy(input: Reader!, output: Writer!): Int
Copy chars from a open static fun copy(input: Reader!, output: OutputStream!): Unit
Copy chars from a open static fun copy(input: Reader!, output: OutputStream!, encoding: String!): Unit
Copy chars from a |
|
open static fun copyLarge(input: InputStream!, output: OutputStream!): Long
Copy bytes from a large (over 2GB) open static fun copyLarge(input: Reader!, output: Writer!): Long
Copy chars from a large (over 2GB) |
|
open static fun lineIterator(reader: Reader!): LineIterator!
Return an Iterator for the lines in a open static fun lineIterator(input: InputStream!, encoding: String!): LineIterator!
Return an Iterator for the lines in an |
|
open static fun readLines(input: InputStream!): MutableList<Any?>!
Get the contents of an open static fun readLines(input: InputStream!, encoding: String!): MutableList<Any?>!
Get the contents of an open static fun readLines(input: Reader!): MutableList<Any?>!
Get the contents of a |
|
open static fun toByteArray(input: InputStream!): ByteArray!
Get the contents of an open static fun toByteArray(input: Reader!): ByteArray!
Get the contents of a open static fun toByteArray(input: Reader!, encoding: String!): ByteArray!
Get the contents of a |
|
open static fun toCharArray(is: InputStream!): CharArray!
Get the contents of an open static fun toCharArray(is: InputStream!, encoding: String!): CharArray!
Get the contents of an open static fun toCharArray(input: Reader!): CharArray!
Get the contents of a |
|
open static fun toInputStream(input: String!): InputStream!
Convert the specified string to an input stream, encoded as bytes using the default character encoding of the platform. open static fun toInputStream(input: String!, encoding: String!): InputStream!
Convert the specified string to an input stream, encoded as bytes using the specified character encoding. |
|
open static fun toString(input: InputStream!): String!
Get the contents of an open static fun toString(input: InputStream!, encoding: String!): String!
Get the contents of an open static fun toString(input: Reader!): String!
Get the contents of a |
|
open static fun write(data: ByteArray!, output: OutputStream!): Unit
Writes bytes from a open static fun write(data: ByteArray!, output: Writer!): Unit
Writes bytes from a open static fun write(data: ByteArray!, output: Writer!, encoding: String!): Unit
Writes bytes from a open static fun write(data: CharArray!, output: Writer!): Unit
Writes chars from a open static fun write(data: CharArray!, output: OutputStream!): Unit
Writes chars from a open static fun write(data: CharArray!, output: OutputStream!, encoding: String!): Unit
Writes chars from a open static fun write(data: String!, output: Writer!): Unit
Writes chars from a open static fun write(data: String!, output: OutputStream!): Unit
Writes chars from a open static fun write(data: String!, output: OutputStream!, encoding: String!): Unit
Writes chars from a open static fun write(data: StringBuffer!, output: Writer!): Unit
Writes chars from a open static fun write(data: StringBuffer!, output: OutputStream!): Unit
Writes chars from a open static fun write(data: StringBuffer!, output: OutputStream!, encoding: String!): Unit
Writes chars from a |
|
open static fun writeLines(lines: MutableCollection<Any?>!, lineEnding: String!, output: OutputStream!): Unit
Writes the open static fun writeLines(lines: MutableCollection<Any?>!, lineEnding: String!, output: OutputStream!, encoding: String!): Unit
Writes the open static fun writeLines(lines: MutableCollection<Any?>!, lineEnding: String!, writer: Writer!): Unit
Writes the |