Skip to content

Commit 56f2a75

Browse files
committed
Consistently use the final modifier with local variables.
1 parent 36940b6 commit 56f2a75

51 files changed

Lines changed: 165 additions & 165 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ public static void copyToDirectory(final Iterable<File> srcs, final File destDir
15951595
if (srcs == null) {
15961596
throw new NullPointerException("Sources must not be null");
15971597
}
1598-
for (File src : srcs) {
1598+
for (final File src : srcs) {
15991599
copyFileToDirectory(src, destDir);
16001600
}
16011601
}
@@ -1766,11 +1766,11 @@ private static File[] verifiedListFiles(final File directory) throws IOException
17661766
* @throws NullPointerException if the file is {@code null}
17671767
*/
17681768
public static boolean waitFor(final File file, final int seconds) {
1769-
long finishAt = System.currentTimeMillis() + (seconds * 1000L);
1769+
final long finishAt = System.currentTimeMillis() + (seconds * 1000L);
17701770
boolean wasInterrupted = false;
17711771
try {
17721772
while (!file.exists()) {
1773-
long remaining = finishAt - System.currentTimeMillis();
1773+
final long remaining = finishAt - System.currentTimeMillis();
17741774
if (remaining < 0){
17751775
return false;
17761776
}
@@ -1849,7 +1849,7 @@ public static String readFileToString(final File file) throws IOException {
18491849
*/
18501850
public static byte[] readFileToByteArray(final File file) throws IOException {
18511851
try (InputStream in = openInputStream(file)) {
1852-
long fileLength = file.length();
1852+
final long fileLength = file.length();
18531853
// file.length() may return 0 for system-dependent entities, treat 0 as unknown length - see IO-453
18541854
return fileLength > 0 ? IOUtils.toByteArray(in, fileLength) : IOUtils.toByteArray(in);
18551855
}

src/main/java/org/apache/commons/io/FilenameUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ public static String getPrefix(final String filename) {
772772
failIfNullBytePresent(filename + UNIX_SEPARATOR);
773773
return filename + UNIX_SEPARATOR;
774774
}
775-
String path = filename.substring(0, len);
775+
final String path = filename.substring(0, len);
776776
failIfNullBytePresent(path);
777777
return path;
778778
}
@@ -852,7 +852,7 @@ private static String doGetPath(final String filename, final int separatorAdd) {
852852
if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
853853
return "";
854854
}
855-
String path = filename.substring(prefix, endIndex);
855+
final String path = filename.substring(prefix, endIndex);
856856
failIfNullBytePresent(path);
857857
return path;
858858
}
@@ -983,7 +983,7 @@ public static String getName(final String filename) {
983983
* @param path the path to check
984984
*/
985985
private static void failIfNullBytePresent(final String path) {
986-
int len = path.length();
986+
final int len = path.length();
987987
for (int i = 0; i < len; i++) {
988988
if (path.charAt(i) == 0) {
989989
throw new IllegalArgumentException("Null byte present in file/path name. There are no " +

src/main/java/org/apache/commons/io/IOCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public enum IOCase implements Serializable {
7777
* @throws IllegalArgumentException if the name is invalid
7878
*/
7979
public static IOCase forName(final String name) {
80-
for (IOCase ioCase : IOCase.values())
80+
for (final IOCase ioCase : IOCase.values())
8181
{
8282
if (ioCase.getName().equals(name))
8383
{

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,7 @@ public static void writeChunked(final byte[] data, final OutputStream output)
17061706
int bytes = data.length;
17071707
int offset = 0;
17081708
while (bytes > 0) {
1709-
int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
1709+
final int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
17101710
output.write(data, offset, chunk);
17111711
bytes -= chunk;
17121712
offset += chunk;
@@ -1813,7 +1813,7 @@ public static void writeChunked(final char[] data, final Writer output) throws I
18131813
int bytes = data.length;
18141814
int offset = 0;
18151815
while (bytes > 0) {
1816-
int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
1816+
final int chunk = Math.min(bytes, DEFAULT_BUFFER_SIZE);
18171817
output.write(data, offset, chunk);
18181818
bytes -= chunk;
18191819
offset += chunk;

src/main/java/org/apache/commons/io/ThreadMonitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void run() {
122122
* @throws InterruptedException if interrupted
123123
*/
124124
private static void sleep(final long ms) throws InterruptedException {
125-
long finishAt = System.currentTimeMillis() + ms;
125+
final long finishAt = System.currentTimeMillis() + ms;
126126
long remaining = ms;
127127
do {
128128
Thread.sleep(remaining);

src/main/java/org/apache/commons/io/input/BOMInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public BOMInputStream(final InputStream delegate, final boolean include, final B
169169
throw new IllegalArgumentException("No BOMs specified");
170170
}
171171
this.include = include;
172-
List<ByteOrderMark> list = Arrays.asList(boms);
172+
final List<ByteOrderMark> list = Arrays.asList(boms);
173173
// Sort the BOMs to match the longest BOM first because some BOMs have the same starting two bytes.
174174
Collections.sort(list, ByteOrderMarkLengthComparator);
175175
this.boms = list;

src/main/java/org/apache/commons/io/input/ClassLoaderObjectInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected Class<?> resolveClass(final ObjectStreamClass objectStreamClass)
6666

6767
try {
6868
return Class.forName(objectStreamClass.getName(), false, classLoader);
69-
} catch (ClassNotFoundException cnfe) {
69+
} catch (final ClassNotFoundException cnfe) {
7070
// delegate to super class loader which can resolve primitives
7171
return super.resolveClass(objectStreamClass);
7272
}

src/main/java/org/apache/commons/io/input/ObservableInputStream.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public int read() throws IOException {
116116
IOException ioe = null;
117117
try {
118118
result = super.read();
119-
} catch (IOException pException) {
119+
} catch (final IOException pException) {
120120
ioe = pException;
121121
}
122122
if (ioe != null) {
@@ -135,7 +135,7 @@ public int read(final byte[] pBuffer) throws IOException {
135135
IOException ioe = null;
136136
try {
137137
result = super.read(pBuffer);
138-
} catch (IOException pException) {
138+
} catch (final IOException pException) {
139139
ioe = pException;
140140
}
141141
if (ioe != null) {
@@ -154,7 +154,7 @@ public int read(final byte[] pBuffer, final int pOffset, final int pLength) thro
154154
IOException ioe = null;
155155
try {
156156
result = super.read(pBuffer, pOffset, pLength);
157-
} catch (IOException pException) {
157+
} catch (final IOException pException) {
158158
ioe = pException;
159159
}
160160
if (ioe != null) {
@@ -176,7 +176,7 @@ public int read(final byte[] pBuffer, final int pOffset, final int pLength) thro
176176
* passed down.
177177
*/
178178
protected void noteDataBytes(final byte[] pBuffer, final int pOffset, final int pLength) throws IOException {
179-
for (Observer observer : getObservers()) {
179+
for (final Observer observer : getObservers()) {
180180
observer.data(pBuffer, pOffset, pLength);
181181
}
182182
}
@@ -186,7 +186,7 @@ protected void noteDataBytes(final byte[] pBuffer, final int pOffset, final int
186186
* passed down.
187187
*/
188188
protected void noteFinished() throws IOException {
189-
for (Observer observer : getObservers()) {
189+
for (final Observer observer : getObservers()) {
190190
observer.finished();
191191
}
192192
}
@@ -198,7 +198,7 @@ protected void noteFinished() throws IOException {
198198
* passed down.
199199
*/
200200
protected void noteDataByte(final int pDataByte) throws IOException {
201-
for (Observer observer : getObservers()) {
201+
for (final Observer observer : getObservers()) {
202202
observer.data(pDataByte);
203203
}
204204
}
@@ -211,7 +211,7 @@ protected void noteDataByte(final int pDataByte) throws IOException {
211211
* argument.
212212
*/
213213
protected void noteError(final IOException pException) throws IOException {
214-
for (Observer observer : getObservers()) {
214+
for (final Observer observer : getObservers()) {
215215
observer.error(pException);
216216
}
217217
}
@@ -221,7 +221,7 @@ protected void noteError(final IOException pException) throws IOException {
221221
* passed down.
222222
*/
223223
protected void noteClosed() throws IOException {
224-
for (Observer observer : getObservers()) {
224+
for (final Observer observer : getObservers()) {
225225
observer.closed();
226226
}
227227
}
@@ -238,7 +238,7 @@ public void close() throws IOException {
238238
IOException ioe = null;
239239
try {
240240
super.close();
241-
} catch (IOException e) {
241+
} catch (final IOException e) {
242242
ioe = e;
243243
}
244244
if (ioe == null) {

src/main/java/org/apache/commons/io/input/Tailer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public void run() {
439439
// Finish scanning the old file and then we'll start with the new one
440440
try {
441441
readLines(save);
442-
} catch (IOException ioe) {
442+
} catch (final IOException ioe) {
443443
listener.handle(ioe);
444444
}
445445
position = 0;

src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ private int readWithUpdate() throws IOException {
6969
*/
7070
@Override
7171
public int read() throws IOException {
72-
boolean previousWasSlashR = slashRSeen;
72+
final boolean previousWasSlashR = slashRSeen;
7373
if ( eofSeen ) {
7474
return eofGame(previousWasSlashR);
7575
}
7676
else {
77-
int target = readWithUpdate();
77+
final int target = readWithUpdate();
7878
if ( eofSeen ) {
7979
return eofGame(previousWasSlashR);
8080
}

0 commit comments

Comments
 (0)