This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 5f83d30 Remove obsolete // comments.
5f83d30 is described below
commit 5f83d305cca2de00e723d5dcf65303f73a4d4e35
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Nov 5 10:24:53 2019 -0500
Remove obsolete // comments.
---
src/main/java/org/apache/commons/io/IOUtils.java | 325 ++++++++++-------------
1 file changed, 140 insertions(+), 185 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/IOUtils.java
b/src/main/java/org/apache/commons/io/IOUtils.java
index 2735cc2..56b83f0 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -104,55 +104,53 @@ public class IOUtils {
// 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.
+ * Represents the end-of-file (or stream).
+ * @since 2.5 (made public)
*/
- public static final char DIR_SEPARATOR = File.separatorChar;
+ public static final int EOF = -1;
+
+ /**
+ * The system line separator string.
+ */
+ public static final String LINE_SEPARATOR;
+
/**
* The Unix line separator string.
*/
public static final String LINE_SEPARATOR_UNIX = "\n";
+
/**
* The Windows line separator string.
*/
public static final String LINE_SEPARATOR_WINDOWS = "\r\n";
- /**
- * 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 default buffer size ({@value}) to use in copy methods.
- */
- private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
/**
* 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.
@@ -165,7 +163,15 @@ public class IOUtils {
* 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 class IOUtils {
(BufferedInputStream) inputStream : new
BufferedInputStream(inputStream);
}
- //-----------------------------------------------------------------------
-
/**
* Returns the given InputStream if it is already a {@link
BufferedInputStream}, otherwise creates a
* BufferedInputStream from the given InputStream.
@@ -298,26 +302,6 @@ public class IOUtils {
}
/**
- * 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.
*
* @param conn the connection to close.
@@ -832,9 +816,6 @@ public class IOUtils {
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.
@@ -907,6 +888,54 @@ public class IOUtils {
}
/**
+ * 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 > 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
* platform, and calling flush.
@@ -996,28 +1025,6 @@ public class IOUtils {
}
/**
- * 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 > 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>
* This method buffers the input internally, so there is no need to use a
@@ -1120,9 +1127,6 @@ public class IOUtils {
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.
@@ -1174,32 +1178,6 @@ public class IOUtils {
}
/**
- * 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>
* This method buffers the input internally, so there is no need to use a
@@ -1218,9 +1196,6 @@ public class IOUtils {
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>
@@ -1316,6 +1291,50 @@ public class IOUtils {
}
/**
+ * 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).
* <p>
@@ -1597,9 +1616,6 @@ public class IOUtils {
return buffer;
}
- // resources
- //-----------------------------------------------------------------------
-
/**
* Reads the requested number of bytes or fail if there are not enough
left.
* <p>
@@ -1722,9 +1738,6 @@ public class IOUtils {
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 class IOUtils {
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 class IOUtils {
return resource;
}
- //-----------------------------------------------------------------------
-
/**
* Skips bytes from an input byte stream.
* This implementation guarantees that it will read as many bytes
@@ -1997,8 +2005,6 @@ public class IOUtils {
return toSkip - remain;
}
- //-----------------------------------------------------------------------
-
/**
* Skips the requested number of bytes or fail if there are not enough
left.
* <p>
@@ -2074,9 +2080,6 @@ public class IOUtils {
}
}
- // write byte[]
- //-----------------------------------------------------------------------
-
/**
* Fetches entire contents of an <code>InputStream</code> and represent
* same data as result InputStream.
@@ -2175,9 +2178,6 @@ public class IOUtils {
}
}
- // 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 class IOUtils {
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 class IOUtils {
}
}
- // 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 class IOUtils {
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 class IOUtils {
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 class IOUtils {
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 class IOUtils {
return toString(url, Charset.defaultCharset());
}
- // copy from Reader
- //-----------------------------------------------------------------------
-
/**
* Gets the contents at the given URL.
*
@@ -2889,9 +2871,6 @@ public class IOUtils {
}
}
- // 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 class IOUtils {
}
}
+
/**
* 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 class IOUtils {
write(data, output, Charsets.toCharset(encoding));
}
-
/**
* Writes chars from a <code>String</code> to a <code>Writer</code>.
*
@@ -3306,54 +3285,30 @@ public class IOUtils {
}
/**
- * Instances should NOT be constructed in standard programming.
- */
- public IOUtils() {
- super();
- }
-
- /**
- * 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.
+ * Returns the given Appendable if it is already a {@link Writer},
otherwise creates a Writer wrapper around the
+ * given Appendable.
*
- * @param csq a CharSequence or null
- * @return the CharSequence length -- or 0 if the given CharSequence 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 CharSequence csq) {
- return csq == null ? 0 : csq.length();
+ 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);
}
/**
- * 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();
}
}