Skip to content

Commit 9b0f78e

Browse files
committed
Avoid unnecessary boxing and unboxing of int and long values
- Avoid unnecessary boxing and unboxing of long values in FileUtils.sizeOf(File) - Avoid unnecessary boxing and unboxing of int values in UncheckedBufferedReader.read() - Avoid unnecessary boxing and unboxing of int values in UncheckedFilterInputStream.available() and read() - Avoid unnecessary boxing and unboxing of int values in UncheckedFilterReader.read()
1 parent 8e6feab commit 9b0f78e

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

src/changes/changes.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ The <action> type attribute can be add,update,fix,remove.
5858
<action dev="ggregory" type="fix" due-to="Gary Gregory">The Consumer to IOUtils.closeQuietly(Closeable, Consumer) now accepts Exception, not just IOException.</action>
5959
<action dev="ggregory" type="fix" due-to="Gary Gregory">The Consumer to IOUtils.close(Closeable, IOConsumer) now accepts wrapped Exception, not just IOException.</action>
6060
<action dev="ggregory" type="fix" due-to="Gary Gregory">Use Uncheck.getAsBoolean(IOBooleanSupplier) to avoid boxing and unboxing of boolean values.</action>
61+
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid unnecessary boxing and unboxing of long values in FileUtils.sizeOf(File).</action>
62+
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid unnecessary boxing and unboxing of int values in UncheckedBufferedReader.read().</action>
63+
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid unnecessary boxing and unboxing of int values in UncheckedFilterInputStream.available() and read().</action>
64+
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid unnecessary boxing and unboxing of int values in UncheckedFilterReader.read().</action>
6165
<!-- ADD -->
6266
<action dev="ggregory" type="add" issue="IO-860" due-to="Nico Strecker, Gary Gregory">Add ThrottledInputStream.Builder.setMaxBytes(long, ChronoUnit).</action>
6367
<action dev="ggregory" type="add" due-to="Gary Gregory">Add IOIterable.</action>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ private static boolean setTimes(final File sourceFile, final File targetFile) {
29392939
* @since 2.0
29402940
*/
29412941
public static long sizeOf(final File file) {
2942-
return Uncheck.get(() -> PathUtils.sizeOf(file.toPath()));
2942+
return Uncheck.getAsLong(() -> PathUtils.sizeOf(file.toPath()));
29432943
}
29442944

29452945
/**
@@ -2985,7 +2985,7 @@ public static long sizeOfDirectory(final File directory) {
29852985
} catch (final FileNotFoundException e) {
29862986
throw new UncheckedIOException(e);
29872987
}
2988-
return Uncheck.get(() -> PathUtils.sizeOfDirectory(directory.toPath()));
2988+
return Uncheck.getAsLong(() -> PathUtils.sizeOfDirectory(directory.toPath()));
29892989
}
29902990

29912991
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public void mark(final int readAheadLimit) throws UncheckedIOException {
148148
*/
149149
@Override
150150
public int read() throws UncheckedIOException {
151-
return Uncheck.get(super::read);
151+
return Uncheck.getAsInt(super::read);
152152
}
153153

154154
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private UncheckedFilterInputStream(final InputStream inputStream) {
123123
*/
124124
@Override
125125
public int available() throws UncheckedIOException {
126-
return Uncheck.get(super::available);
126+
return Uncheck.getAsInt(super::available);
127127
}
128128

129129
/**
@@ -139,7 +139,7 @@ public void close() throws UncheckedIOException {
139139
*/
140140
@Override
141141
public int read() throws UncheckedIOException {
142-
return Uncheck.get(super::read);
142+
return Uncheck.getAsInt(super::read);
143143
}
144144

145145
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void mark(final int readAheadLimit) throws UncheckedIOException {
140140
*/
141141
@Override
142142
public int read() throws UncheckedIOException {
143-
return Uncheck.get(super::read);
143+
return Uncheck.getAsInt(super::read);
144144
}
145145

146146
/**

src/test/java/org/apache/commons/io/file/FilesUncheckTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public void testNewBufferedWriterPathOpenOptionArray() {
279279

280280
@Test
281281
public void testNewByteChannelPathOpenOptionArray() {
282-
assertEquals(0, Uncheck.get(() -> {
282+
assertEquals(0, Uncheck.getAsLong(() -> {
283283
try (SeekableByteChannel c = FilesUncheck.newByteChannel(FILE_PATH_EMPTY, StandardOpenOption.READ)) {
284284
return c.size();
285285
}
@@ -290,7 +290,7 @@ public void testNewByteChannelPathOpenOptionArray() {
290290
public void testNewByteChannelPathSetOfQextendsOpenOptionFileAttributeOfQArray() {
291291
final Set<OpenOption> options = new HashSet<>();
292292
options.add(StandardOpenOption.READ);
293-
assertEquals(0, Uncheck.get(() -> {
293+
assertEquals(0, Uncheck.getAsLong(() -> {
294294
try (SeekableByteChannel c = FilesUncheck.newByteChannel(FILE_PATH_EMPTY, options, EMPTY_FILE_ATTRIBUTES_ARRAY)) {
295295
return c.size();
296296
}
@@ -326,7 +326,7 @@ public void testNewDirectoryStreamPathString() {
326326

327327
@Test
328328
public void testNewInputStream() {
329-
assertEquals(0, Uncheck.get(() -> {
329+
assertEquals(0, Uncheck.getAsInt(() -> {
330330
try (InputStream in = FilesUncheck.newInputStream(FILE_PATH_EMPTY, StandardOpenOption.READ)) {
331331
return in.available();
332332
}

0 commit comments

Comments
 (0)