Use less cryptic variable names.
MODIFY
src/main/java/org/apache/commons/io/CopyUtils.java
src/main/java/org/apache/commons/io/CopyUtils.java
*/
public CopyUtils() { }
- // ----------------------------------------------------------------
- // byte[] -> OutputStream
- // ----------------------------------------------------------------
-
/**
* Copy bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
* @param input the byte array to read from
* @param output the <code>OutputStream</code> to write to
* @throws IOException In case of an I/O problem
*/
- public static void copy(final byte[] input, final OutputStream output)
- throws IOException {
+ public static void copy(final byte[] input, final OutputStream output) throws IOException {
output.write(input);
}
- // ----------------------------------------------------------------
- // byte[] -> Writer
- // ----------------------------------------------------------------
-
/**
* Copy and convert bytes from a <code>byte[]</code> to chars on a
* <code>Writer</code>.
@@ -150,13 +141,11 @@ public static void copy(final byte[] input, final OutputStream output)
* @deprecated 2.5 use {@link #copy(byte[], Writer, String)} instead
*/
@Deprecated
- public static void copy(final byte[] input, final Writer output)
- throws IOException {
- final ByteArrayInputStream in = new ByteArrayInputStream(input);
- copy(in, output);
+ public static void copy(final byte[] input, final Writer output) throws IOException {
+ final ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
+ copy(inputStream, output);
}
-
/**
* Copy and convert bytes from a <code>byte[]</code> to chars on a
* <code>Writer</code>, using the specified encoding.
@@ -167,20 +156,11 @@ public static void copy(final byte[] input, final Writer output)
* Charset Registry</a> for a list of valid encoding types.
* @throws IOException In case of an I/O problem
*/
- public static void copy(
- final byte[] input,
- final Writer output,
- final String encoding)
- throws IOException {
- final ByteArrayInputStream in = new ByteArrayInputStream(input);
- copy(in, output, encoding);
+ public static void copy(final byte[] input, final Writer output, final String encoding) throws IOException {
+ final ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
+ copy(inputStream, output, encoding);
}
-
- // ----------------------------------------------------------------
- // Core copy methods
- // ----------------------------------------------------------------
-
/**
* Copy bytes from an <code>InputStream</code> to an
* <code>OutputStream</code>.
@@ -189,10 +169,7 @@ public static void copy(
* @return the number of bytes copied
* @throws IOException In case of an I/O problem
*/
- public static int copy(
- final InputStream input,
- final OutputStream output)
- throws IOException {
+ public static int copy(final InputStream input, final OutputStream output) throws IOException {
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int count = 0;
int n = 0;

MODIFY
src/main/java/org/apache/commons/io/FileUtils.java
src/main/java/org/apache/commons/io/FileUtils.java
@@ -264,8 +264,8 @@ public static Checksum checksum(final File file, final Checksum checksum) throws
requireExistsChecked(file, "file");
requireFile(file, "file");
Objects.requireNonNull(checksum, "checksum");
- try (InputStream in = new CheckedInputStream(new FileInputStream(file), checksum)) {
- IOUtils.consume(in);
+ try (InputStream inputStream = new CheckedInputStream(new FileInputStream(file), checksum)) {
+ IOUtils.consume(inputStream);
}
return checksum;
}
@@ -944,8 +944,8 @@ public static void copyFileToDirectory(final File sourceFile, final File destina
* @since 2.0
*/
public static void copyInputStreamToFile(final InputStream source, final File destination) throws IOException {
- try (InputStream in = source) {
- copyToFile(in, destination);
+ try (InputStream inputStream = source) {
+ copyToFile(inputStream, destination);
}
}
@@ -2381,10 +2381,10 @@ public static FileOutputStream openOutputStream(final File file, final boolean a
* @since 1.1
*/
public static byte[] readFileToByteArray(final File file) throws IOException {
- try (InputStream in = openInputStream(file)) {
+ try (InputStream inputStream = openInputStream(file)) {
final long fileLength = file.length();
// file.length() may return 0 for system-dependent entities, treat 0 as unknown length - see IO-453
- return fileLength > 0 ? IOUtils.toByteArray(in, fileLength) : IOUtils.toByteArray(in);
+ return fileLength > 0 ? IOUtils.toByteArray(inputStream, fileLength) : IOUtils.toByteArray(inputStream);
}
}
@@ -2420,8 +2420,8 @@ public static String readFileToString(final File file) throws IOException {
* @since 2.3
*/
public static String readFileToString(final File file, final Charset charsetName) throws IOException {
- try (InputStream in = openInputStream(file)) {
- return IOUtils.toString(in, Charsets.toCharset(charsetName));
+ try (InputStream inputStream = openInputStream(file)) {
+ return IOUtils.toString(inputStream, Charsets.toCharset(charsetName));
}
}
@@ -2475,8 +2475,8 @@ public static String readFileToString(final File file, final String charsetName)
* @since 2.3
*/
public static List<String> readLines(final File file, final Charset charset) throws IOException {
- try (InputStream in = openInputStream(file)) {
- return IOUtils.readLines(in, Charsets.toCharset(charset));
+ try (InputStream inputStream = openInputStream(file)) {
+ return IOUtils.readLines(inputStream, Charsets.toCharset(charset));
}
}

MODIFY
src/main/java/org/apache/commons/io/IOUtils.java
src/main/java/org/apache/commons/io/IOUtils.java
@@ -2450,7 +2450,7 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
- * @param is the <code>InputStream</code> to read from
+ * @param inputStream the <code>InputStream</code> to read from
* @return the requested character array
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
@@ -2458,8 +2458,8 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
* @deprecated 2.5 use {@link #toCharArray(InputStream, Charset)} instead
*/
@Deprecated
- public static char[] toCharArray(final InputStream is) throws IOException {
- return toCharArray(is, Charset.defaultCharset());
+ public static char[] toCharArray(final InputStream inputStream) throws IOException {
+ return toCharArray(inputStream, Charset.defaultCharset());
}
/**
@@ -2469,17 +2469,17 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
- * @param is the <code>InputStream</code> to read from
+ * @param inputStream the <code>InputStream</code> to read from
* @param charset the charset to use, null means platform default
* @return the requested character array
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since 2.3
*/
- public static char[] toCharArray(final InputStream is, final Charset charset)
+ public static char[] toCharArray(final InputStream inputStream, final Charset charset)
throws IOException {
final CharArrayWriter writer = new CharArrayWriter();
- copy(is, writer, charset);
+ copy(inputStream, writer, charset);
return writer.toCharArray();
}
@@ -2493,7 +2493,7 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
- * @param is the <code>InputStream</code> to read from
+ * @param inputStream the <code>InputStream</code> to read from
* @param charsetName the name of the requested charset, null means platform default
* @return the requested character array
* @throws NullPointerException if the input is null
@@ -2503,8 +2503,8 @@ public static BufferedReader toBufferedReader(final Reader reader, final int siz
* encoding is not supported.
* @since 1.1
*/
- public static char[] toCharArray(final InputStream is, final String charsetName) throws IOException {
- return toCharArray(is, Charsets.toCharset(charsetName));
+ public static char[] toCharArray(final InputStream inputStream, final String charsetName) throws IOException {
+ return toCharArray(inputStream, Charsets.toCharset(charsetName));
}
/**

MODIFY
src/main/java/org/apache/commons/io/input/ReaderInputStream.java
src/main/java/org/apache/commons/io/input/ReaderInputStream.java
* sequence as reading from {@code in} (provided that the initial byte sequence is legal
* with respect to the charset encoding):
* <pre>
- * InputStream in = ...
+ * InputStream inputStream = ...
* Charset cs = ...
- * InputStreamReader reader = new InputStreamReader(in, cs);
+ * InputStreamReader reader = new InputStreamReader(inputStream, cs);
* ReaderInputStream in2 = new ReaderInputStream(reader, cs);</pre>
+ *
* {@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,

MODIFY
src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryWindowsTestCase.java
src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryWindowsTestCase.java
@@ -50,7 +50,8 @@ protected boolean setupSymlink(final File res, final File link) throws Exception
final Process proc = Runtime.getRuntime().exec(args.toArray(new String[args.size()]));
final InputStream errorStream = proc.getErrorStream();
final int rc = proc.waitFor();
- System.err.println(IOUtils.toString(errorStream, Charset.defaultCharset()));
+ System.err.print(IOUtils.toString(errorStream, Charset.defaultCharset()));
+ System.err.flush();
return rc == 0;
}

Use less cryptic variable names.