Skip to content

Commit 1a824ec

Browse files
committed
Merge branch 'master' into release
2 parents 6d36827 + 49611a1 commit 1a824ec

6 files changed

Lines changed: 113 additions & 4 deletions

File tree

RELEASE-NOTES.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,58 @@ file comparators, endian transformation classes, and much more.
1414
Java 8 is required.
1515

1616

17+
Fixed Bugs
18+
----------
19+
20+
o Reimplement FileSystemUtils using NIO. Thanks to Gary Gregory.
21+
o IO-851: FileSystemUtils no longer throws IllegalStateException. Thanks to Sebb, Gary Gregory.
22+
o Avoid possible NullPointerException in FileUtils.listAccumulate(File, IOFileFilter, IOFileFilter, FileVisitOption...). Thanks to Gary Gregory.
23+
o IO-853: BoundedInputStream.reset() not updating count. Thanks to Mike Drob, Gary Gregory.
24+
o ThresholdingOutputStream: a negative threshold should behave like a zero threshold and trigger the event on the first write #609. Thanks to rproserpio, Gary Gregory.
25+
26+
Changes
27+
-------
28+
29+
o Bump commons.bytebuddy.version from 1.14.12 to 1.14.13 #605. Thanks to Gary Gregory.
30+
o Bump org.apache.commons:commons-parent from 67 to 69 #608. Thanks to Gary Gregory, Dependabot.
31+
32+
33+
Commons IO 2.7 and up requires Java 8 or above.
34+
Commons IO 2.6 requires Java 7 or above.
35+
Commons IO 2.3 through 2.5 requires Java 6 or above.
36+
Commons IO 2.2 requires Java 5 or above.
37+
Commons IO 1.4 requires Java 1.3 or above.
38+
39+
Historical list of changes: https://commons.apache.org/proper/commons-io/changes-report.html
40+
41+
For complete information on Apache Commons IO, including instructions on how to submit bug reports,
42+
patches, or suggestions for improvement, see the Apache Commons IO website:
43+
44+
https://commons.apache.org/proper/commons-io/
45+
46+
Download page: https://commons.apache.org/proper/commons-io/download_io.cgi
47+
48+
Have fun!
49+
-Apache Commons Team
50+
51+
------------------------------------------------------------------------------
52+
53+
54+
Apache Commons IO 2.16.1 Release Notes
55+
56+
Introduction
57+
------------
58+
59+
Commons IO is a package of Java utility classes like java.io.
60+
Classes in this package are considered to be so standard and of such high
61+
reuse as to justify existence in java.io.
62+
63+
The Apache Commons IO library contains utility classes, stream implementations, file filters,
64+
file comparators, endian transformation classes, and much more.
65+
66+
Java 8 is required.
67+
68+
1769
Fixed Bugs
1870
----------
1971

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ file comparators, endian transformation classes, and much more.
124124
<maven.compiler.target>1.8</maven.compiler.target>
125125
<commons.componentid>io</commons.componentid>
126126
<commons.module.name>org.apache.commons.io</commons.module.name>
127-
<commons.rc.version>RC1</commons.rc.version>
127+
<commons.rc.version>RC2</commons.rc.version>
128128
<commons.bc.version>2.16.0</commons.bc.version>
129129
<commons.release.version>2.16.1</commons.release.version>
130130
<commons.release.next>2.16.2</commons.release.next>

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The <action> type attribute can be add,update,fix,remove.
5252
<action dev="ggregory" type="fix" issue="IO-851" due-to="Sebb, Gary Gregory">FileSystemUtils no longer throws IllegalStateException.</action>
5353
<action dev="ggregory" type="fix" due-to="Gary Gregory">Avoid possible NullPointerException in FileUtils.listAccumulate(File, IOFileFilter, IOFileFilter, FileVisitOption...).</action>
5454
<action dev="ggregory" type="fix" issue="IO-853" due-to="Mike Drob, Gary Gregory">BoundedInputStream.reset() not updating count.</action>
55+
<action dev="ggregory" type="fix" due-to="rproserpio, Gary Gregory">ThresholdingOutputStream: a negative threshold should behave like a zero threshold and trigger the event on the first write #609.</action>
5556
<!-- UPDATE -->
5657
<action dev="ggregory" type="update" due-to="Gary Gregory">Bump commons.bytebuddy.version from 1.14.12 to 1.14.13 #605.</action>
5758
<action dev="ggregory" type="update" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 67 to 69 #608.</action>

src/main/java/org/apache/commons/io/output/ThresholdingOutputStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public ThresholdingOutputStream(final int threshold) {
8181

8282
/**
8383
* Constructs an instance of this class which will trigger an event at the specified threshold.
84+
* A negative threshold has no meaning and will be treated as 0
8485
*
8586
* @param threshold The number of bytes at which to trigger an event.
8687
* @param thresholdConsumer Accepts reaching the threshold.
@@ -89,10 +90,9 @@ public ThresholdingOutputStream(final int threshold) {
8990
*/
9091
public ThresholdingOutputStream(final int threshold, final IOConsumer<ThresholdingOutputStream> thresholdConsumer,
9192
final IOFunction<ThresholdingOutputStream, OutputStream> outputStreamGetter) {
92-
this.threshold = threshold;
93+
this.threshold = threshold < 0 ? 0 : threshold;
9394
this.thresholdConsumer = thresholdConsumer == null ? IOConsumer.noop() : thresholdConsumer;
9495
this.outputStreamGetter = outputStreamGetter == null ? NOOP_OS_GETTER : outputStreamGetter;
95-
this.thresholdExceeded = threshold < 0;
9696
}
9797

9898
/**

src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ public void testAboveThresholdGetInputStream(final int initialBufferSize, final
104104
}
105105
}
106106

107+
/**
108+
* Tests the case where the threshold is negative, and therefore the data is always written to disk. The actual data
109+
* written to disk is verified, as is the file itself.
110+
*/
111+
@ParameterizedTest(name = "initialBufferSize = {0}")
112+
@MethodSource("data")
113+
public void testThresholdNegative(final int initialBufferSize) throws IOException {
114+
final File testFile = Files.createTempFile(tempDirPath, "testThresholdNegative", "dat").toFile();
115+
try (DeferredFileOutputStream dfos = DeferredFileOutputStream.builder()
116+
.setThreshold(-1)
117+
.setBufferSize(initialBufferSize)
118+
.setOutputFile(testFile)
119+
.get()) {
120+
dfos.write(testBytes, 0, testBytes.length);
121+
dfos.close();
122+
assertFalse(dfos.isInMemory());
123+
assertNull(dfos.getData());
124+
assertEquals(testFile.length(), dfos.getByteCount());
125+
verifyResultFile(testFile);
126+
}
127+
}
128+
107129
/**
108130
* Tests the case where the amount of data is exactly the same as the threshold. The behavior should be the same as
109131
* that for the amount of data being below (i.e. not exceeding) the threshold.

src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,47 @@
3232
*/
3333
public class ThresholdingOutputStreamTest {
3434

35+
/**
36+
* Tests the case where the threshold is negative.
37+
* The threshold is not reached until something is written to the stream.
38+
*/
3539
@Test
3640
public void testThresholdLessThanZero() throws IOException {
37-
try (final ThresholdingOutputStream out = new ThresholdingOutputStream(-1)) {
41+
final AtomicBoolean reached = new AtomicBoolean();
42+
try (final ThresholdingOutputStream out = new ThresholdingOutputStream(-1) {
43+
@Override
44+
protected void thresholdReached() throws IOException {
45+
reached.set(true);
46+
}
47+
}) {
48+
assertFalse(reached.get());
49+
out.write(89);
50+
assertTrue(reached.get());
3851
assertTrue(out.isThresholdExceeded());
3952
}
4053
}
4154

55+
/**
56+
* Tests the case where no bytes are written.
57+
* The threshold is not reached until something is written to the stream.
58+
*/
59+
@Test
60+
public void testThresholdZeroWrite() throws IOException {
61+
final AtomicBoolean reached = new AtomicBoolean();
62+
try (final ThresholdingOutputStream out = new ThresholdingOutputStream(7) {
63+
@Override
64+
protected void thresholdReached() throws IOException {
65+
reached.set(true);
66+
}
67+
}) {
68+
assertFalse(out.isThresholdExceeded());
69+
assertFalse(reached.get());
70+
out.write(new byte[0]);
71+
assertFalse(out.isThresholdExceeded());
72+
assertFalse(reached.get());
73+
}
74+
}
75+
4276
@Test
4377
public void testThresholdZero() throws IOException {
4478
final AtomicBoolean reached = new AtomicBoolean();

0 commit comments

Comments
 (0)