Skip to content

Commit 6aa0076

Browse files
committed
Use final where possible.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1415850 13f79535-47bb-0310-9956-ffa450edef68
1 parent efca165 commit 6aa0076

189 files changed

Lines changed: 3854 additions & 3852 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/ByteOrderMark.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class ByteOrderMark implements Serializable {
6666
* @throws IllegalArgumentException if the bytes are null or zero
6767
* length
6868
*/
69-
public ByteOrderMark(String charsetName, int... bytes) {
69+
public ByteOrderMark(final String charsetName, final int... bytes) {
7070
if (charsetName == null || charsetName.length() == 0) {
7171
throw new IllegalArgumentException("No charsetName specified");
7272
}
@@ -102,7 +102,7 @@ public int length() {
102102
* @param pos The position
103103
* @return The specified byte
104104
*/
105-
public int get(int pos) {
105+
public int get(final int pos) {
106106
return bytes[pos];
107107
}
108108

@@ -112,7 +112,7 @@ public int get(int pos) {
112112
* @return a copy of the BOM's bytes
113113
*/
114114
public byte[] getBytes() {
115-
byte[] copy = new byte[bytes.length];
115+
final byte[] copy = new byte[bytes.length];
116116
for (int i = 0; i < bytes.length; i++) {
117117
copy[i] = (byte)bytes[i];
118118
}
@@ -127,11 +127,11 @@ public byte[] getBytes() {
127127
* false
128128
*/
129129
@Override
130-
public boolean equals(Object obj) {
130+
public boolean equals(final Object obj) {
131131
if (!(obj instanceof ByteOrderMark)) {
132132
return false;
133133
}
134-
ByteOrderMark bom = (ByteOrderMark)obj;
134+
final ByteOrderMark bom = (ByteOrderMark)obj;
135135
if (bytes.length != bom.length()) {
136136
return false;
137137
}
@@ -152,7 +152,7 @@ public boolean equals(Object obj) {
152152
@Override
153153
public int hashCode() {
154154
int hashCode = getClass().hashCode();
155-
for (int b : bytes) {
155+
for (final int b : bytes) {
156156
hashCode += b;
157157
}
158158
return hashCode;
@@ -165,7 +165,7 @@ public int hashCode() {
165165
*/
166166
@Override
167167
public String toString() {
168-
StringBuilder builder = new StringBuilder();
168+
final StringBuilder builder = new StringBuilder();
169169
builder.append(getClass().getSimpleName());
170170
builder.append('[');
171171
builder.append(charsetName);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class Charsets {
7373
*/
7474
public static SortedMap<String, Charset> requiredCharsets() {
7575
// maybe cache?
76-
TreeMap<String, Charset> m = new TreeMap<String, Charset>(String.CASE_INSENSITIVE_ORDER);
76+
final TreeMap<String, Charset> m = new TreeMap<String, Charset>(String.CASE_INSENSITIVE_ORDER);
7777
m.put(ISO_8859_1.name(), ISO_8859_1);
7878
m.put(US_ASCII.name(), US_ASCII);
7979
m.put(UTF_16.name(), UTF_16);
@@ -90,7 +90,7 @@ public static SortedMap<String, Charset> requiredCharsets() {
9090
* A charset or null.
9191
* @return the given Charset or the default Charset if the given Charset is null
9292
*/
93-
public static Charset toCharset(Charset charset) {
93+
public static Charset toCharset(final Charset charset) {
9494
return charset == null ? Charset.defaultCharset() : charset;
9595
}
9696

@@ -103,7 +103,7 @@ public static Charset toCharset(Charset charset) {
103103
* @throws UnsupportedCharsetException
104104
* If the named charset is unavailable
105105
*/
106-
public static Charset toCharset(String charset) {
106+
public static Charset toCharset(final String charset) {
107107
return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
108108
}
109109

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public CopyUtils() { }
131131
* @param output the <code>OutputStream</code> to write to
132132
* @throws IOException In case of an I/O problem
133133
*/
134-
public static void copy(byte[] input, OutputStream output)
134+
public static void copy(final byte[] input, final OutputStream output)
135135
throws IOException {
136136
output.write(input);
137137
}
@@ -148,9 +148,9 @@ public static void copy(byte[] input, OutputStream output)
148148
* @param output the <code>Writer</code> to write to
149149
* @throws IOException In case of an I/O problem
150150
*/
151-
public static void copy(byte[] input, Writer output)
151+
public static void copy(final byte[] input, final Writer output)
152152
throws IOException {
153-
ByteArrayInputStream in = new ByteArrayInputStream(input);
153+
final ByteArrayInputStream in = new ByteArrayInputStream(input);
154154
copy(in, output);
155155
}
156156

@@ -166,11 +166,11 @@ public static void copy(byte[] input, Writer output)
166166
* @throws IOException In case of an I/O problem
167167
*/
168168
public static void copy(
169-
byte[] input,
170-
Writer output,
171-
String encoding)
169+
final byte[] input,
170+
final Writer output,
171+
final String encoding)
172172
throws IOException {
173-
ByteArrayInputStream in = new ByteArrayInputStream(input);
173+
final ByteArrayInputStream in = new ByteArrayInputStream(input);
174174
copy(in, output, encoding);
175175
}
176176

@@ -188,10 +188,10 @@ public static void copy(
188188
* @throws IOException In case of an I/O problem
189189
*/
190190
public static int copy(
191-
InputStream input,
192-
OutputStream output)
191+
final InputStream input,
192+
final OutputStream output)
193193
throws IOException {
194-
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
194+
final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
195195
int count = 0;
196196
int n = 0;
197197
while (-1 != (n = input.read(buffer))) {
@@ -213,10 +213,10 @@ public static int copy(
213213
* @throws IOException In case of an I/O problem
214214
*/
215215
public static int copy(
216-
Reader input,
217-
Writer output)
216+
final Reader input,
217+
final Writer output)
218218
throws IOException {
219-
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
219+
final char[] buffer = new char[DEFAULT_BUFFER_SIZE];
220220
int count = 0;
221221
int n = 0;
222222
while (-1 != (n = input.read(buffer))) {
@@ -239,10 +239,10 @@ public static int copy(
239239
* @throws IOException In case of an I/O problem
240240
*/
241241
public static void copy(
242-
InputStream input,
243-
Writer output)
242+
final InputStream input,
243+
final Writer output)
244244
throws IOException {
245-
InputStreamReader in = new InputStreamReader(input);
245+
final InputStreamReader in = new InputStreamReader(input);
246246
copy(in, output);
247247
}
248248

@@ -257,11 +257,11 @@ public static void copy(
257257
* @throws IOException In case of an I/O problem
258258
*/
259259
public static void copy(
260-
InputStream input,
261-
Writer output,
262-
String encoding)
260+
final InputStream input,
261+
final Writer output,
262+
final String encoding)
263263
throws IOException {
264-
InputStreamReader in = new InputStreamReader(input, encoding);
264+
final InputStreamReader in = new InputStreamReader(input, encoding);
265265
copy(in, output);
266266
}
267267

@@ -278,10 +278,10 @@ public static void copy(
278278
* @throws IOException In case of an I/O problem
279279
*/
280280
public static void copy(
281-
Reader input,
282-
OutputStream output)
281+
final Reader input,
282+
final OutputStream output)
283283
throws IOException {
284-
OutputStreamWriter out = new OutputStreamWriter(output);
284+
final OutputStreamWriter out = new OutputStreamWriter(output);
285285
copy(input, out);
286286
// XXX Unless anyone is planning on rewriting OutputStreamWriter, we
287287
// have to flush here.
@@ -301,11 +301,11 @@ public static void copy(
301301
* @throws IOException In case of an I/O problem
302302
*/
303303
public static void copy(
304-
String input,
305-
OutputStream output)
304+
final String input,
305+
final OutputStream output)
306306
throws IOException {
307-
StringReader in = new StringReader(input);
308-
OutputStreamWriter out = new OutputStreamWriter(output);
307+
final StringReader in = new StringReader(input);
308+
final OutputStreamWriter out = new OutputStreamWriter(output);
309309
copy(in, out);
310310
// XXX Unless anyone is planning on rewriting OutputStreamWriter, we
311311
// have to flush here.
@@ -322,7 +322,7 @@ public static void copy(
322322
* @param output the <code>Writer</code> to write to
323323
* @throws IOException In case of an I/O problem
324324
*/
325-
public static void copy(String input, Writer output)
325+
public static void copy(final String input, final Writer output)
326326
throws IOException {
327327
output.write(input);
328328
}

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ protected DirectoryWalker() {
278278
* @param depthLimit controls how <i>deep</i> the hierarchy is
279279
* navigated to (less than 0 means unlimited)
280280
*/
281-
protected DirectoryWalker(FileFilter filter, int depthLimit) {
281+
protected DirectoryWalker(final FileFilter filter, final int depthLimit) {
282282
this.filter = filter;
283283
this.depthLimit = depthLimit;
284284
}
@@ -297,7 +297,7 @@ protected DirectoryWalker(FileFilter filter, int depthLimit) {
297297
* @param depthLimit controls how <i>deep</i> the hierarchy is
298298
* navigated to (less than 0 means unlimited)
299299
*/
300-
protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter, int depthLimit) {
300+
protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter, final int depthLimit) {
301301
if (directoryFilter == null && fileFilter == null) {
302302
this.filter = null;
303303
} else {
@@ -326,15 +326,15 @@ protected DirectoryWalker(IOFileFilter directoryFilter, IOFileFilter fileFilter,
326326
* @throws NullPointerException if the start directory is null
327327
* @throws IOException if an I/O Error occurs
328328
*/
329-
protected final void walk(File startDirectory, Collection<T> results) throws IOException {
329+
protected final void walk(final File startDirectory, final Collection<T> results) throws IOException {
330330
if (startDirectory == null) {
331331
throw new NullPointerException("Start Directory is null");
332332
}
333333
try {
334334
handleStart(startDirectory, results);
335335
walk(startDirectory, 0, results);
336336
handleEnd(results);
337-
} catch(CancelException cancel) {
337+
} catch(final CancelException cancel) {
338338
handleCancelled(startDirectory, results, cancel);
339339
}
340340
}
@@ -347,19 +347,19 @@ protected final void walk(File startDirectory, Collection<T> results) throws IOE
347347
* @param results the collection of result objects, may be updated
348348
* @throws IOException if an I/O Error occurs
349349
*/
350-
private void walk(File directory, int depth, Collection<T> results) throws IOException {
350+
private void walk(final File directory, final int depth, final Collection<T> results) throws IOException {
351351
checkIfCancelled(directory, depth, results);
352352
if (handleDirectory(directory, depth, results)) {
353353
handleDirectoryStart(directory, depth, results);
354-
int childDepth = depth + 1;
354+
final int childDepth = depth + 1;
355355
if (depthLimit < 0 || childDepth <= depthLimit) {
356356
checkIfCancelled(directory, depth, results);
357357
File[] childFiles = filter == null ? directory.listFiles() : directory.listFiles(filter);
358358
childFiles = filterDirectoryContents(directory, depth, childFiles);
359359
if (childFiles == null) {
360360
handleRestricted(directory, childDepth, results);
361361
} else {
362-
for (File childFile : childFiles) {
362+
for (final File childFile : childFiles) {
363363
if (childFile.isDirectory()) {
364364
walk(childFile, childDepth, results);
365365
} else {
@@ -390,7 +390,7 @@ private void walk(File directory, int depth, Collection<T> results) throws IOExc
390390
* @param results the collection of result objects, may be updated
391391
* @throws IOException if an I/O Error occurs
392392
*/
393-
protected final void checkIfCancelled(File file, int depth, Collection<T> results) throws IOException {
393+
protected final void checkIfCancelled(final File file, final int depth, final Collection<T> results) throws IOException {
394394
if (handleIsCancelled(file, depth, results)) {
395395
throw new CancelException(file, depth);
396396
}
@@ -432,7 +432,7 @@ protected final void checkIfCancelled(File file, int depth, Collection<T> result
432432
* @throws IOException if an I/O Error occurs
433433
*/
434434
protected boolean handleIsCancelled(
435-
File file, int depth, Collection<T> results) throws IOException {
435+
final File file, final int depth, final Collection<T> results) throws IOException {
436436
// do nothing - overridable by subclass
437437
return false; // not cancelled
438438
}
@@ -450,8 +450,8 @@ protected boolean handleIsCancelled(
450450
* containing details at the point of cancellation.
451451
* @throws IOException if an I/O Error occurs
452452
*/
453-
protected void handleCancelled(File startDirectory, Collection<T> results,
454-
CancelException cancel) throws IOException {
453+
protected void handleCancelled(final File startDirectory, final Collection<T> results,
454+
final CancelException cancel) throws IOException {
455455
// re-throw exception - overridable by subclass
456456
throw cancel;
457457
}
@@ -466,7 +466,7 @@ protected void handleCancelled(File startDirectory, Collection<T> results,
466466
* @param results the collection of result objects, may be updated
467467
* @throws IOException if an I/O Error occurs
468468
*/
469-
protected void handleStart(File startDirectory, Collection<T> results) throws IOException {
469+
protected void handleStart(final File startDirectory, final Collection<T> results) throws IOException {
470470
// do nothing - overridable by subclass
471471
}
472472

@@ -485,7 +485,7 @@ protected void handleStart(File startDirectory, Collection<T> results) throws IO
485485
* @return true to process this directory, false to skip this directory
486486
* @throws IOException if an I/O Error occurs
487487
*/
488-
protected boolean handleDirectory(File directory, int depth, Collection<T> results) throws IOException {
488+
protected boolean handleDirectory(final File directory, final int depth, final Collection<T> results) throws IOException {
489489
// do nothing - overridable by subclass
490490
return true; // process directory
491491
}
@@ -500,7 +500,7 @@ protected boolean handleDirectory(File directory, int depth, Collection<T> resul
500500
* @param results the collection of result objects, may be updated
501501
* @throws IOException if an I/O Error occurs
502502
*/
503-
protected void handleDirectoryStart(File directory, int depth, Collection<T> results) throws IOException {
503+
protected void handleDirectoryStart(final File directory, final int depth, final Collection<T> results) throws IOException {
504504
// do nothing - overridable by subclass
505505
}
506506

@@ -516,7 +516,7 @@ protected void handleDirectoryStart(File directory, int depth, Collection<T> res
516516
* @throws IOException if an I/O Error occurs
517517
* @since 2.0
518518
*/
519-
protected File[] filterDirectoryContents(File directory, int depth, File[] files) throws IOException {
519+
protected File[] filterDirectoryContents(final File directory, final int depth, final File[] files) throws IOException {
520520
return files;
521521
}
522522

@@ -530,7 +530,7 @@ protected File[] filterDirectoryContents(File directory, int depth, File[] files
530530
* @param results the collection of result objects, may be updated
531531
* @throws IOException if an I/O Error occurs
532532
*/
533-
protected void handleFile(File file, int depth, Collection<T> results) throws IOException {
533+
protected void handleFile(final File file, final int depth, final Collection<T> results) throws IOException {
534534
// do nothing - overridable by subclass
535535
}
536536

@@ -544,7 +544,7 @@ protected void handleFile(File file, int depth, Collection<T> results) throws IO
544544
* @param results the collection of result objects, may be updated
545545
* @throws IOException if an I/O Error occurs
546546
*/
547-
protected void handleRestricted(File directory, int depth, Collection<T> results) throws IOException {
547+
protected void handleRestricted(final File directory, final int depth, final Collection<T> results) throws IOException {
548548
// do nothing - overridable by subclass
549549
}
550550

@@ -558,7 +558,7 @@ protected void handleRestricted(File directory, int depth, Collection<T> results
558558
* @param results the collection of result objects, may be updated
559559
* @throws IOException if an I/O Error occurs
560560
*/
561-
protected void handleDirectoryEnd(File directory, int depth, Collection<T> results) throws IOException {
561+
protected void handleDirectoryEnd(final File directory, final int depth, final Collection<T> results) throws IOException {
562562
// do nothing - overridable by subclass
563563
}
564564

@@ -570,7 +570,7 @@ protected void handleDirectoryEnd(File directory, int depth, Collection<T> resul
570570
* @param results the collection of result objects, may be updated
571571
* @throws IOException if an I/O Error occurs
572572
*/
573-
protected void handleEnd(Collection<T> results) throws IOException {
573+
protected void handleEnd(final Collection<T> results) throws IOException {
574574
// do nothing - overridable by subclass
575575
}
576576

@@ -596,7 +596,7 @@ public static class CancelException extends IOException {
596596
* @param file the file when the operation was cancelled, may be null
597597
* @param depth the depth when the operation was cancelled, may be null
598598
*/
599-
public CancelException(File file, int depth) {
599+
public CancelException(final File file, final int depth) {
600600
this("Operation Cancelled", file, depth);
601601
}
602602

@@ -609,7 +609,7 @@ public CancelException(File file, int depth) {
609609
* @param file the file when the operation was cancelled
610610
* @param depth the depth when the operation was cancelled
611611
*/
612-
public CancelException(String message, File file, int depth) {
612+
public CancelException(final String message, final File file, final int depth) {
613613
super(message);
614614
this.file = file;
615615
this.depth = depth;

0 commit comments

Comments
 (0)