You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/01/17 01:10:55 UTC
[commons-io] branch master updated: Use less cryptic variable names.
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 a5356b4 Use less cryptic variable names.
a5356b4 is described below
commit a5356b490105061d1cca7c153f2881a89a963cc0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jan 16 20:10:50 2021 -0500
Use less cryptic variable names.
---
src/main/java/org/apache/commons/io/CopyUtils.java | 39 +++++-----------------
src/main/java/org/apache/commons/io/FileUtils.java | 20 +++++------
src/main/java/org/apache/commons/io/IOUtils.java | 18 +++++-----
.../apache/commons/io/input/ReaderInputStream.java | 5 +--
.../FileUtilsDeleteDirectoryWindowsTestCase.java | 3 +-
5 files changed, 32 insertions(+), 53 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/CopyUtils.java b/src/main/java/org/apache/commons/io/CopyUtils.java
index c8ef486..0686b1d 100644
--- a/src/main/java/org/apache/commons/io/CopyUtils.java
+++ b/src/main/java/org/apache/commons/io/CopyUtils.java
@@ -121,25 +121,16 @@ public class CopyUtils {
*/
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 class CopyUtils {
* @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 class CopyUtils {
* 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 class CopyUtils {
* @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;
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index 098c14b..82462bd 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -264,8 +264,8 @@ public class FileUtils {
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 class FileUtils {
* @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 class FileUtils {
* @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 class FileUtils {
* @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 class FileUtils {
* @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));
}
}
diff --git a/src/main/java/org/apache/commons/io/IOUtils.java b/src/main/java/org/apache/commons/io/IOUtils.java
index 34b0baf..25bb227 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -2450,7 +2450,7 @@ public class IOUtils {
* 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 class IOUtils {
* @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 class IOUtils {
* 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 class IOUtils {
* 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 class IOUtils {
* 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));
}
/**
diff --git a/src/main/java/org/apache/commons/io/input/ReaderInputStream.java b/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
index 79bc9fe..425cc21 100644
--- a/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
@@ -49,10 +49,11 @@ import java.util.Objects;
* 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,
diff --git a/src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryWindowsTestCase.java b/src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryWindowsTestCase.java
index 1145206..147c430 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryWindowsTestCase.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsDeleteDirectoryWindowsTestCase.java
@@ -50,7 +50,8 @@ public class FileUtilsDeleteDirectoryWindowsTestCase extends FileUtilsDeleteDire
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;
}