Remove obsolete // comments.
MODIFY
src/main/java/org/apache/commons/io/IOUtils.java
src/main/java/org/apache/commons/io/IOUtils.java
// or return one of them.
/**
- * Represents the end-of-file (or stream).
- * @since 2.5 (made public)
+ * The default buffer size ({@value}) to use in copy methods.
*/
- public static final int EOF = -1;
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+ /**
+ * The system directory separator character.
+ */
+ public static final char DIR_SEPARATOR = File.separatorChar;
/**
* The Unix directory separator character.
*/
public static final char DIR_SEPARATOR_UNIX = '/';
+
/**
* The Windows directory separator character.
*/
public static final char DIR_SEPARATOR_WINDOWS = '\\';
+
/**
- * The system directory separator character.
- */
- public static final char DIR_SEPARATOR = File.separatorChar;
- /**
- * The Unix line separator string.
- */
- public static final String LINE_SEPARATOR_UNIX = "\n";
- /**
- * The Windows line separator string.
+ * Represents the end-of-file (or stream).
+ * @since 2.5 (made public)
*/
- public static final String LINE_SEPARATOR_WINDOWS = "\r\n";
+ public static final int EOF = -1;
+
/**
* The system line separator string.
*/
public static final String LINE_SEPARATOR;
- static {
- // avoid security issues
- try (final StringBuilderWriter buf = new StringBuilderWriter(4);
- final PrintWriter out = new PrintWriter(buf)) {
- out.println();
- LINE_SEPARATOR = buf.toString();
- }
- }
+ /**
+ * The Unix line separator string.
+ */
+ public static final String LINE_SEPARATOR_UNIX = "\n";
/**
- * The default buffer size ({@value}) to use in copy methods.
+ * The Windows line separator string.
*/
- private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+ public static final String LINE_SEPARATOR_WINDOWS = "\r\n";
/**
* The default buffer size to use for the skip() methods.
*/
private static final int SKIP_BUFFER_SIZE = 2048;
+ private static byte[] SKIP_BYTE_BUFFER;
+
// Allocated in the relevant skip method if necessary.
/*
* These buffers are static and are shared between threads.
* did not create a smaller one)
*/
private static char[] SKIP_CHAR_BUFFER;
- private static byte[] SKIP_BYTE_BUFFER;
+
+ static {
+ // avoid security issues
+ try (final StringBuilderWriter buf = new StringBuilderWriter(4);
+ final PrintWriter out = new PrintWriter(buf)) {
+ out.println();
+ LINE_SEPARATOR = buf.toString();
+ }
+ }
/**
* Returns the given InputStream if it is already a {@link BufferedInputStream}, otherwise creates a
@@ -185,8 +191,6 @@ public static BufferedInputStream buffer(final InputStream inputStream) {
(BufferedInputStream) inputStream : new BufferedInputStream(inputStream);
}
- //-----------------------------------------------------------------------
-
/**
* Returns the given InputStream if it is already a {@link BufferedInputStream}, otherwise creates a
* BufferedInputStream from the given InputStream.
@@ -297,26 +301,6 @@ public static BufferedWriter buffer(final Writer writer, final int size) {
return writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer, size);
}
- /**
- * Returns the given Appendable if it is already a {@link Writer}, otherwise creates a Writer wrapper around the
- * given Appendable.
- *
- * @param appendable the Appendable to wrap or return (not null)
- * @return the given Appendable or a Writer wrapper around the given Appendable
- * @throws NullPointerException if the input parameter is null
- * @since 2.7
- */
- public static Writer writer(final Appendable appendable) {
- Objects.requireNonNull(appendable, "appendable");
- if (appendable instanceof Writer) {
- return (Writer) appendable;
- }
- if (appendable instanceof StringBuilder) {
- return new StringBuilderWriter((StringBuilder) appendable);
- }
- return new AppendableWriter<>(appendable);
- }
-
/**
* Closes a URLConnection.
*
@@ -832,9 +816,6 @@ public static long copy(final InputStream input, final OutputStream output, fina
return copyLarge(input, output, new byte[bufferSize]);
}
- // read toByteArray
- //-----------------------------------------------------------------------
-
/**
* Copies bytes from an <code>InputStream</code> to chars on a
* <code>Writer</code> using the default character encoding of the platform.
@@ -906,6 +887,54 @@ public static void copy(final InputStream input, final Writer output, final Stri
copy(input, output, Charsets.toCharset(inputEncoding));
}
+ /**
+ * Copies chars from a <code>Reader</code> to a <code>Appendable</code>.
+ * <p>
+ * This method buffers the input internally, so there is no need to use a
+ * <code>BufferedReader</code>.
+ * <p>
+ * Large streams (over 2GB) will return a chars copied value of
+ * <code>-1</code> after the copy has completed since the correct
+ * number of chars cannot be returned as an int. For large streams
+ * use the <code>copyLarge(Reader, Writer)</code> method.
+ *
+ * @param input the <code>Reader</code> to read from
+ * @param output the <code>Appendable</code> to write to
+ * @return the number of characters copied, or -1 if &gt; Integer.MAX_VALUE
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.7
+ */
+ public static long copy(final Reader input, final Appendable output) throws IOException {
+ return copy(input, output, CharBuffer.allocate(DEFAULT_BUFFER_SIZE));
+ }
+
+ /**
+ * Copies chars from a <code>Reader</code> to an <code>Appendable</code>.
+ * <p>
+ * This method uses the provided buffer, so there is no need to use a
+ * <code>BufferedReader</code>.
+ * </p>
+ *
+ * @param input the <code>Reader</code> to read from
+ * @param output the <code>Appendable</code> to write to
+ * @param buffer the buffer to be used for the copy
+ * @return the number of characters copied
+ * @throws NullPointerException if the input or output is null
+ * @throws IOException if an I/O error occurs
+ * @since 2.7
+ */
+ public static long copy(final Reader input, final Appendable output, final CharBuffer buffer) throws IOException {
+ long count = 0;
+ int n;
+ while (EOF != (n = input.read(buffer))) {
+ buffer.flip();
+ output.append(buffer, 0, n);
+ count += n;
+ }
+ return count;
+ }
+
/**
* Copies chars from a <code>Reader</code> to bytes on an
* <code>OutputStream</code> using the default character encoding of the
@@ -995,28 +1024,6 @@ public static void copy(final Reader input, final OutputStream output, final Str
copy(input, output, Charsets.toCharset(outputEncoding));
}
- /**
- * Copies chars from a <code>Reader</code> to a <code>Appendable</code>.
- * <p>
- * This method buffers the input internally, so there is no need to use a
- * <code>BufferedReader</code>.
- * <p>
- * Large streams (over 2GB) will return a chars copied value of
- * <code>-1</code> after the copy has completed since the correct
- * number of chars cannot be returned as an int. For large streams
- * use the <code>copyLarge(Reader, Writer)</code> method.
- *
- * @param input the <code>Reader</code> to read from
- * @param output the <code>Appendable</code> to write to
- * @return the number of characters copied, or -1 if &gt; Integer.MAX_VALUE
- * @throws NullPointerException if the input or output is null
- * @throws IOException if an I/O error occurs
- * @since 2.7
- */
- public static long copy(final Reader input, final Appendable output) throws IOException {
- return copy(input, output, CharBuffer.allocate(DEFAULT_BUFFER_SIZE));
- }
-
/**
* Copies chars from a <code>Reader</code> to a <code>Writer</code>.
* <p>
@@ -1120,9 +1127,6 @@ public static long copyLarge(final InputStream input, final OutputStream output,
return copyLarge(input, output, inputOffset, length, new byte[DEFAULT_BUFFER_SIZE]);
}
- // read char[]
- //-----------------------------------------------------------------------
-
/**
* Copies some or all bytes from a large (over 2GB) <code>InputStream</code> to an
* <code>OutputStream</code>, optionally skipping input bytes.
@@ -1173,32 +1177,6 @@ public static long copyLarge(final InputStream input, final OutputStream output,
return totalRead;
}
- /**
- * Copies chars from a <code>Reader</code> to an <code>Appendable</code>.
- * <p>
- * This method uses the provided buffer, so there is no need to use a
- * <code>BufferedReader</code>.
- * </p>
- *
- * @param input the <code>Reader</code> to read from
- * @param output the <code>Appendable</code> to write to
- * @param buffer the buffer to be used for the copy
- * @return the number of characters copied
- * @throws NullPointerException if the input or output is null
- * @throws IOException if an I/O error occurs
- * @since 2.7
- */
- public static long copy(final Reader input, final Appendable output, final CharBuffer buffer) throws IOException {
- long count = 0;
- int n;
- while (EOF != (n = input.read(buffer))) {
- buffer.flip();
- output.append(buffer, 0, n);
- count += n;
- }
- return count;
- }
-
/**
* Copies chars from a large (over 2GB) <code>Reader</code> to a <code>Writer</code>.
* <p>
@@ -1218,9 +1196,6 @@ public static long copyLarge(final Reader input, final Writer output) throws IOE
return copyLarge(input, output, new char[DEFAULT_BUFFER_SIZE]);
}
- // read toString
- //-----------------------------------------------------------------------
-
/**
* Copies chars from a large (over 2GB) <code>Reader</code> to a <code>Writer</code>.
* <p>
@@ -1315,6 +1290,50 @@ public static long copyLarge(final Reader input, final Writer output, final long
return totalRead;
}
+ /**
+ * Returns the length of the given array in a null-safe manner.
+ *
+ * @param array an array or null
+ * @return the array length -- or 0 if the given array is null.
+ * @since 2.7
+ */
+ public static int length(final byte[] array) {
+ return array == null ? 0 : array.length;
+ }
+
+ /**
+ * Returns the length of the given array in a null-safe manner.
+ *
+ * @param array an array or null
+ * @return the array length -- or 0 if the given array is null.
+ * @since 2.7
+ */
+ public static int length(final char[] array) {
+ return array == null ? 0 : array.length;
+ }
+
+ /**
+ * Returns the length of the given CharSequence in a null-safe manner.
+ *
+ * @param csq a CharSequence or null
+ * @return the CharSequence length -- or 0 if the given CharSequence is null.
+ * @since 2.7
+ */
+ public static int length(final CharSequence csq) {
+ return csq == null ? 0 : csq.length();
+ }
+
+ /**
+ * Returns the length of the given array in a null-safe manner.
+ *
+ * @param array an array or null
+ * @return the array length -- or 0 if the given array is null.
+ * @since 2.7
+ */
+ public static int length(final Object[] array) {
+ return array == null ? 0 : array.length;
+ }
+
/**
* Returns an Iterator for the lines in an <code>InputStream</code>, using
* the character encoding specified (or default encoding if null).
@@ -1597,9 +1616,6 @@ public static void readFully(final InputStream input, final byte[] buffer, final
return buffer;
}
- // resources
- //-----------------------------------------------------------------------
-
/**
* Reads the requested number of bytes or fail if there are not enough left.
* <p>
@@ -1722,9 +1738,6 @@ public static void readFully(final Reader input, final char[] buffer, final int
return readLines(input, Charsets.toCharset(encoding));
}
- // readLines
- //-----------------------------------------------------------------------
-
/**
* Gets the contents of a <code>Reader</code> as a list of Strings,
* one entry per line.
@@ -1806,9 +1819,6 @@ public static String resourceToString(final String name, final Charset encoding)
return resourceToString(name, encoding, null);
}
- // lineIterator
- //-----------------------------------------------------------------------
-
/**
* Gets the contents of a classpath resource as a String using the
* specified character encoding.
@@ -1875,8 +1885,6 @@ public static URL resourceToURL(final String name, final ClassLoader classLoader
return resource;
}
- //-----------------------------------------------------------------------
-
/**
* Skips bytes from an input byte stream.
* This implementation guarantees that it will read as many bytes
@@ -1997,8 +2005,6 @@ public static long skip(final Reader input, final long toSkip) throws IOExceptio
return toSkip - remain;
}
- //-----------------------------------------------------------------------
-
/**
* Skips the requested number of bytes or fail if there are not enough left.
* <p>
@@ -2074,9 +2080,6 @@ public static void skipFully(final Reader input, final long toSkip) throws IOExc
}
}
- // write byte[]
- //-----------------------------------------------------------------------
-
/**
* Fetches entire contents of an <code>InputStream</code> and represent
* same data as result InputStream.
@@ -2175,9 +2178,6 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
}
}
- // write char[]
- //-----------------------------------------------------------------------
-
/**
* Gets the contents of an <code>InputStream</code> as a <code>byte[]</code>.
* Use this method instead of <code>toByteArray(InputStream)</code>
@@ -2305,9 +2305,6 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
return toByteArray(input, Charsets.toCharset(encoding));
}
- // write CharSequence
- //-----------------------------------------------------------------------
-
/**
* Gets the contents of a <code>String</code> as a <code>byte[]</code>
* using the default character encoding of the platform.
@@ -2372,9 +2369,6 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
}
}
- // write String
- //-----------------------------------------------------------------------
-
/**
* Gets the contents of an <code>InputStream</code> as a character array
* using the default character encoding of the platform.
@@ -2457,9 +2451,6 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
return sw.toCharArray();
}
- // write StringBuffer
- //-----------------------------------------------------------------------
-
/**
* Converts the specified CharSequence to an input stream, encoded as bytes
* using the default character encoding of the platform.
@@ -2507,9 +2498,6 @@ public static InputStream toInputStream(final CharSequence input, final String e
return toInputStream(input, Charsets.toCharset(encoding));
}
- // writeLines
- //-----------------------------------------------------------------------
-
/**
* Converts the specified string to an input stream, encoded as bytes
* using the default character encoding of the platform.
@@ -2574,9 +2562,6 @@ public static String toString(final byte[] input) throws IOException {
return new String(input, Charset.defaultCharset());
}
- // copy from InputStream
- //-----------------------------------------------------------------------
-
/**
* Gets the contents of a <code>byte[]</code> as a String
* using the specified character encoding.
@@ -2733,9 +2718,6 @@ public static String toString(final URL url) throws IOException {
return toString(url, Charset.defaultCharset());
}
- // copy from Reader
- //-----------------------------------------------------------------------
-
/**
* Gets the contents at the given URL.
*
@@ -2889,9 +2871,6 @@ public static void write(final char[] data, final OutputStream output, final Cha
}
}
- // content equals
- //-----------------------------------------------------------------------
-
/**
* Writes chars from a <code>char[]</code> to bytes on an
* <code>OutputStream</code> using the specified character encoding.
@@ -3011,6 +2990,7 @@ public static void write(final CharSequence data, final Writer output) throws IO
}
}
+
/**
* Writes chars from a <code>String</code> to bytes on an
* <code>OutputStream</code> using the default character encoding of the
@@ -3073,7 +3053,6 @@ public static void write(final String data, final OutputStream output, final Str
write(data, output, Charsets.toCharset(encoding));
}
-
/**
* Writes chars from a <code>String</code> to a <code>Writer</code>.
*
@@ -3306,54 +3285,30 @@ public static void writeLines(final Collection<?> lines, String lineEnding,
}
/**
- * Instances should NOT be constructed in standard programming.
- */
- public IOUtils() {
- super();
- }
-
- /**
- * Returns the length of the given array in a null-safe manner.
+ * Returns the given Appendable if it is already a {@link Writer}, otherwise creates a Writer wrapper around the
+ * given Appendable.
*
- * @param array an array or null
- * @return the array length -- or 0 if the given array is null.
+ * @param appendable the Appendable to wrap or return (not null)
+ * @return the given Appendable or a Writer wrapper around the given Appendable
+ * @throws NullPointerException if the input parameter is null
* @since 2.7
*/
- public static int length(final byte[] array) {
- return array == null ? 0 : array.length;
+ public static Writer writer(final Appendable appendable) {
+ Objects.requireNonNull(appendable, "appendable");
+ if (appendable instanceof Writer) {
+ return (Writer) appendable;
}
-
- /**
- * Returns the length of the given array in a null-safe manner.
- *
- * @param array an array or null
- * @return the array length -- or 0 if the given array is null.
- * @since 2.7
- */
- public static int length(final char[] array) {
- return array == null ? 0 : array.length;
+ if (appendable instanceof StringBuilder) {
+ return new StringBuilderWriter((StringBuilder) appendable);
}
-
- /**
- * Returns the length of the given CharSequence in a null-safe manner.
- *
- * @param csq a CharSequence or null
- * @return the CharSequence length -- or 0 if the given CharSequence is null.
- * @since 2.7
- */
- public static int length(final CharSequence csq) {
- return csq == null ? 0 : csq.length();
+ return new AppendableWriter<>(appendable);
}
/**
- * Returns the length of the given array in a null-safe manner.
- *
- * @param array an array or null
- * @return the array length -- or 0 if the given array is null.
- * @since 2.7
+ * Instances should NOT be constructed in standard programming.
*/
- public static int length(final Object[] array) {
- return array == null ? 0 : array.length;
+ public IOUtils() {
+ super();
}
}

Remove obsolete // comments.