Javadoc fixes.
Minor formatting.
Normalize exception message.
* between the current position of the {@link Reader} and that of the {@link ReaderInputStream}.
* This also implies that in general there is no need to wrap the underlying {@link Reader}
* in a {@link java.io.BufferedReader}.
+ * </p>
* <p>
* {@link ReaderInputStream} implements the inverse transformation of {@link java.io.InputStreamReader};
* in the following example, reading from {@code in2} would return the same byte
* sequence as reading from {@code in} (provided that the initial byte sequence is legal
* with respect to the charset encoding):
+ * </p>
* <pre>
* InputStream inputStream = ...
* Charset cs = ...
* InputStreamReader reader = new InputStreamReader(inputStream, cs);
* ReaderInputStream in2 = new ReaderInputStream(reader, cs);</pre>
- *
+ * <p>
* {@link ReaderInputStream} implements the same transformation as {@link java.io.OutputStreamWriter},
* except that the control flow is reversed: both classes transform a character stream
* into a byte stream, but {@link java.io.OutputStreamWriter} pushes data to the underlying stream,
* while {@link ReaderInputStream} pulls it from the underlying stream.
+ * </p>
* <p>
* Note that while there are use cases where there is no alternative to using
* this class, very often the need to use this class is an indication of a flaw
* is as a character stream, i.e. by providing a {@link Reader} instance. An example of a situation
* where this problem may appear is when implementing the {@code javax.activation.DataSource}
* interface from the Java Activation Framework.
+ * </p>
* <p>
* Given the fact that the {@link Reader} class doesn't provide any way to predict whether the next
* read operation will block or not, it is not possible to provide a meaningful
* </p>
*
* @see org.apache.commons.io.output.WriterOutputStream
- *
* @since 2.0
*/
public class ReaderInputStream extends InputStream {
@@ -138,11 +141,13 @@ public ReaderInputStream(final Reader reader, final CharsetEncoder encoder, fina
* @param bufferSize the size of the input buffer in number of characters
*/
public ReaderInputStream(final Reader reader, final Charset charset, final int bufferSize) {
+ // @formatter:off
this(reader,
charset.newEncoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE),
bufferSize);
+ // @formatter:on
}
/**
@@ -230,8 +235,7 @@ private void fillBuffer() throws IOException {
public int read(final byte[] array, int off, int len) throws IOException {
Objects.requireNonNull(array, "array");
if (len < 0 || off < 0 || (off + len) > array.length) {
- throw new IndexOutOfBoundsException("Array Size=" + array.length +
- ", offset=" + off + ", length=" + len);
+ throw new IndexOutOfBoundsException("Array size=" + array.length + ", offset=" + off + ", length=" + len);
}
int read = 0;
if (len == 0) {
