Skip to content

Commit 5b2cf0d

Browse files
committed
[IO-405] Handle zero and negative thresholds #587
Simplify
1 parent a5cbb2f commit 5b2cf0d

3 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ The <action> type attribute can be add,update,fix,remove.
106106
<action dev="ggregory" type="fix" issue="IO-845" due-to="Elliotte Rusty Harold">Test links to targets outside the source directory #571.</action>
107107
<action dev="ggregory" type="fix" due-to="Elliotte Rusty Harold">Focus Javadoc on current version rather than past versions #573, #574.</action>
108108
<action dev="ggregory" type="fix" issue="IO-469" due-to="Grigory Fadeev, Kristian Rosenvold, Elliotte Rusty Harold">"Self-suppression not permitted" while using BrokenOutput and BrokenInput streams with try-with-resources.</action>
109+
<action dev="ggregory" type="fix" issue="IO-405" due-to="Elliotte Rusty Harold">Handle zero and negative thresholds #587.</action>
109110
<!-- Add -->
110111
<action dev="ggregory" type="add" due-to="Gary Gregory">Add and use PathUtils.getFileName(Path, Function&lt;Path, R&gt;).</action>
111112
<action dev="ggregory" type="add" due-to="Gary Gregory">Add and use PathUtils.getFileNameString().</action>

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ public ThresholdingOutputStream(final int threshold, final IOConsumer<Thresholdi
9292
this.threshold = threshold;
9393
this.thresholdConsumer = thresholdConsumer == null ? IOConsumer.noop() : thresholdConsumer;
9494
this.outputStreamGetter = outputStreamGetter == null ? NOOP_OS_GETTER : outputStreamGetter;
95-
if (threshold < 0) {
96-
thresholdExceeded = true;
97-
}
95+
this.thresholdExceeded = threshold < 0;
9896
}
9997

10098
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected void thresholdReached() throws IOException {
5757

5858
@Test
5959
public void testSetByteCount_OutputStream() throws Exception {
60-
final AtomicBoolean reached = new AtomicBoolean(false);
60+
final AtomicBoolean reached = new AtomicBoolean();
6161
try (ThresholdingOutputStream tos = new ThresholdingOutputStream(3) {
6262
{
6363
setByteCount(2);
@@ -82,7 +82,7 @@ protected void thresholdReached() throws IOException {
8282

8383
@Test
8484
public void testSetByteCount_Stream() throws Exception {
85-
final AtomicBoolean reached = new AtomicBoolean(false);
85+
final AtomicBoolean reached = new AtomicBoolean();
8686
try (ThresholdingOutputStream tos = new ThresholdingOutputStream(3) {
8787
{
8888
setByteCount(2);

0 commit comments

Comments
 (0)