apidocs / com.srv4pos.commons.io / IOUtils

IOUtils

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 $

Constructors

<init>

IOUtils()

Instances should NOT be constructed in standard programming.

Properties

DIR_SEPARATOR

static val DIR_SEPARATOR: Char

The system directory separator character.

DIR_SEPARATOR_UNIX

static val DIR_SEPARATOR_UNIX: Char

The Unix directory separator character.

DIR_SEPARATOR_WINDOWS

static val DIR_SEPARATOR_WINDOWS: Char

The Windows directory separator character.

LINE_SEPARATOR

static val LINE_SEPARATOR: String!

The system line separator string.

LINE_SEPARATOR_UNIX

static val LINE_SEPARATOR_UNIX: String

The Unix line separator string.

LINE_SEPARATOR_WINDOWS

static val LINE_SEPARATOR_WINDOWS: String

The Windows line separator string.

Functions

closeQuietly

open static fun closeQuietly(input: Reader!): Unit

Unconditionally close an Reader.

open static fun closeQuietly(output: Writer!): Unit

Unconditionally close a Writer.

open static fun closeQuietly(input: InputStream!): Unit

Unconditionally close an InputStream.

open static fun closeQuietly(output: OutputStream!): Unit

Unconditionally close an OutputStream.

contentEquals

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.

copy

open static fun copy(input: InputStream!, output: OutputStream!): Int

Copy bytes from an InputStream to an OutputStream.

open static fun copy(input: InputStream!, output: Writer!): Unit

Copy bytes from an InputStream to chars on a Writer using the default character encoding of the platform.

open static fun copy(input: InputStream!, output: Writer!, encoding: String!): Unit

Copy bytes from an InputStream to chars on a Writer using the specified character encoding.

open static fun copy(input: Reader!, output: Writer!): Int

Copy chars from a Reader to a Writer.

open static fun copy(input: Reader!, output: OutputStream!): Unit

Copy chars from a Reader to bytes on an OutputStream using the default character encoding of the platform, and calling flush.

open static fun copy(input: Reader!, output: OutputStream!, encoding: String!): Unit

Copy chars from a Reader to bytes on an OutputStream using the specified character encoding, and calling flush.

copyLarge

open static fun copyLarge(input: InputStream!, output: OutputStream!): Long

Copy bytes from a large (over 2GB) InputStream to an OutputStream.

open static fun copyLarge(input: Reader!, output: Writer!): Long

Copy chars from a large (over 2GB) Reader to a Writer.

lineIterator

open static fun lineIterator(reader: Reader!): LineIterator!

Return an Iterator for the lines in a Reader.

open static fun lineIterator(input: InputStream!, encoding: String!): LineIterator!

Return an Iterator for the lines in an InputStream, using the character encoding specified (or default encoding if null).

readLines

open static fun readLines(input: InputStream!): MutableList<Any?>!

Get the contents of an InputStream as a list of Strings, one entry per line, using the default character encoding of the platform.

open static fun readLines(input: InputStream!, encoding: String!): MutableList<Any?>!

Get the contents of an InputStream as a list of Strings, one entry per line, using the specified character encoding.

open static fun readLines(input: Reader!): MutableList<Any?>!

Get the contents of a Reader as a list of Strings, one entry per line.

toByteArray

open static fun toByteArray(input: InputStream!): ByteArray!

Get the contents of an InputStream as a byte[].

open static fun toByteArray(input: Reader!): ByteArray!

Get the contents of a Reader as a byte[] using the default character encoding of the platform.

open static fun toByteArray(input: Reader!, encoding: String!): ByteArray!

Get the contents of a Reader as a byte[] using the specified character encoding.

toCharArray

open static fun toCharArray(is: InputStream!): CharArray!

Get the contents of an InputStream as a character array using the default character encoding of the platform.

open static fun toCharArray(is: InputStream!, encoding: String!): CharArray!

Get the contents of an InputStream as a character array using the specified character encoding.

open static fun toCharArray(input: Reader!): CharArray!

Get the contents of a Reader as a character array.

toInputStream

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.

toString

open static fun toString(input: InputStream!): String!

Get the contents of an InputStream as a String using the default character encoding of the platform.

open static fun toString(input: InputStream!, encoding: String!): String!

Get the contents of an InputStream as a String using the specified character encoding.

open static fun toString(input: Reader!): String!

Get the contents of a Reader as a String.

write

open static fun write(data: ByteArray!, output: OutputStream!): Unit

Writes bytes from a byte[] to an OutputStream.

open static fun write(data: ByteArray!, output: Writer!): Unit

Writes bytes from a byte[] to chars on a Writer using the default character encoding of the platform.

open static fun write(data: ByteArray!, output: Writer!, encoding: String!): Unit

Writes bytes from a byte[] to chars on a Writer using the specified character encoding.

open static fun write(data: CharArray!, output: Writer!): Unit

Writes chars from a char[] to a Writer using the default character encoding of the platform.

open static fun write(data: CharArray!, output: OutputStream!): Unit

Writes chars from a char[] to bytes on an OutputStream.

open static fun write(data: CharArray!, output: OutputStream!, encoding: String!): Unit

Writes chars from a char[] to bytes on an OutputStream using the specified character encoding.

open static fun write(data: String!, output: Writer!): Unit

Writes chars from a String to a Writer.

open static fun write(data: String!, output: OutputStream!): Unit

Writes chars from a String to bytes on an OutputStream using the default character encoding of the platform.

open static fun write(data: String!, output: OutputStream!, encoding: String!): Unit

Writes chars from a String to bytes on an OutputStream using the specified character encoding.

open static fun write(data: StringBuffer!, output: Writer!): Unit

Writes chars from a StringBuffer to a Writer.

open static fun write(data: StringBuffer!, output: OutputStream!): Unit

Writes chars from a StringBuffer to bytes on an OutputStream using the default character encoding of the platform.

open static fun write(data: StringBuffer!, output: OutputStream!, encoding: String!): Unit

Writes chars from a StringBuffer to bytes on an OutputStream using the specified character encoding.

writeLines

open static fun writeLines(lines: MutableCollection<Any?>!, lineEnding: String!, output: OutputStream!): Unit

Writes the toString() value of each item in a collection to an OutputStream line by line, using the default character encoding of the platform and the specified line ending.

open static fun writeLines(lines: MutableCollection<Any?>!, lineEnding: String!, output: OutputStream!, encoding: String!): Unit

Writes the toString() value of each item in a collection to an OutputStream line by line, using the specified character encoding and the specified line ending.

open static fun writeLines(lines: MutableCollection<Any?>!, lineEnding: String!, writer: Writer!): Unit

Writes the toString() value of each item in a collection to a Writer line by line, using the specified line ending.