Skip to content

Commit 290d72e

Browse files
committed
Merge branch 'master' into release
2 parents 1a824ec + bbd279f commit 290d72e

4 files changed

Lines changed: 85 additions & 85 deletions

File tree

src/changes/changes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +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>
55+
<action dev="ggregory" type="fix" issue="IO-854" due-to="rproserpio, Bill Orpet, Gary Gregory">ThresholdingOutputStream: a negative threshold should behave like a zero threshold and trigger the event on the first write #609.</action>
5656
<!-- UPDATE -->
5757
<action dev="ggregory" type="update" due-to="Gary Gregory">Bump commons.bytebuddy.version from 1.14.12 to 1.14.13 #605.</action>
5858
<action dev="ggregory" type="update" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-parent from 67 to 69 #608.</action>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ public boolean equals(final Object obj) {
8181
return Objects.equals(path, other.path);
8282
}
8383

84-
@Override
85-
public void forEach(final Consumer<? super Path> action) {
86-
path.forEach(action);
87-
}
88-
8984
/**
9085
* Delegates to {@link Files#exists(Path, LinkOption...)}.
9186
*
@@ -96,6 +91,11 @@ public boolean exists(final LinkOption... options) {
9691
return Files.exists(path, options);
9792
}
9893

94+
@Override
95+
public void forEach(final Consumer<? super Path> action) {
96+
path.forEach(action);
97+
}
98+
9999
/**
100100
* Gets the delegate Path.
101101
*

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,28 +104,6 @@ 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-
129107
/**
130108
* Tests the case where the amount of data is exactly the same as the threshold. The behavior should be the same as
131109
* that for the amount of data being below (i.e. not exceeding) the threshold.
@@ -299,6 +277,28 @@ public void testTempFileError() throws Exception {
299277
assertThrows(NullPointerException.class, () -> new DeferredFileOutputStream(testBytes.length - 5, prefix, suffix, tempDirFile));
300278
}
301279

280+
/**
281+
* Tests the case where the threshold is negative, and therefore the data is always written to disk. The actual data
282+
* written to disk is verified, as is the file itself.
283+
*/
284+
@ParameterizedTest(name = "initialBufferSize = {0}")
285+
@MethodSource("data")
286+
public void testThresholdNegative(final int initialBufferSize) throws IOException {
287+
final File testFile = Files.createTempFile(tempDirPath, "testThresholdNegative", "dat").toFile();
288+
try (DeferredFileOutputStream dfos = DeferredFileOutputStream.builder()
289+
.setThreshold(-1)
290+
.setBufferSize(initialBufferSize)
291+
.setOutputFile(testFile)
292+
.get()) {
293+
dfos.write(testBytes, 0, testBytes.length);
294+
dfos.close();
295+
assertFalse(dfos.isInMemory());
296+
assertNull(dfos.getData());
297+
assertEquals(testFile.length(), dfos.getByteCount());
298+
verifyResultFile(testFile);
299+
}
300+
}
301+
302302
/**
303303
* Tests the case where there are multiple writes beyond the threshold, to ensure that the
304304
* {@code thresholdReached()} method is only called once, as the threshold is crossed for the first time.

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

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -32,63 +32,6 @@
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-
*/
39-
@Test
40-
public void testThresholdLessThanZero() throws IOException {
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());
51-
assertTrue(out.isThresholdExceeded());
52-
}
53-
}
54-
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-
76-
@Test
77-
public void testThresholdZero() throws IOException {
78-
final AtomicBoolean reached = new AtomicBoolean();
79-
try (final ThresholdingOutputStream out = new ThresholdingOutputStream(0) {
80-
@Override
81-
protected void thresholdReached() throws IOException {
82-
reached.set(true);
83-
}
84-
}) {
85-
assertFalse(out.isThresholdExceeded());
86-
out.write(89);
87-
assertTrue(reached.get());
88-
assertTrue(out.isThresholdExceeded());
89-
}
90-
}
91-
9235
@Test
9336
public void testSetByteCount_OutputStream() throws Exception {
9437
final AtomicBoolean reached = new AtomicBoolean();
@@ -189,4 +132,61 @@ public void testThresholdIOConsumerUncheckedException() throws Exception {
189132
assertThrows(IllegalStateException.class, () -> tos.write('a'));
190133
}
191134
}
135+
136+
/**
137+
* Tests the case where the threshold is negative.
138+
* The threshold is not reached until something is written to the stream.
139+
*/
140+
@Test
141+
public void testThresholdLessThanZero() throws IOException {
142+
final AtomicBoolean reached = new AtomicBoolean();
143+
try (final ThresholdingOutputStream out = new ThresholdingOutputStream(-1) {
144+
@Override
145+
protected void thresholdReached() throws IOException {
146+
reached.set(true);
147+
}
148+
}) {
149+
assertFalse(reached.get());
150+
out.write(89);
151+
assertTrue(reached.get());
152+
assertTrue(out.isThresholdExceeded());
153+
}
154+
}
155+
156+
@Test
157+
public void testThresholdZero() throws IOException {
158+
final AtomicBoolean reached = new AtomicBoolean();
159+
try (final ThresholdingOutputStream out = new ThresholdingOutputStream(0) {
160+
@Override
161+
protected void thresholdReached() throws IOException {
162+
reached.set(true);
163+
}
164+
}) {
165+
assertFalse(out.isThresholdExceeded());
166+
out.write(89);
167+
assertTrue(reached.get());
168+
assertTrue(out.isThresholdExceeded());
169+
}
170+
}
171+
172+
/**
173+
* Tests the case where no bytes are written.
174+
* The threshold is not reached until something is written to the stream.
175+
*/
176+
@Test
177+
public void testThresholdZeroWrite() throws IOException {
178+
final AtomicBoolean reached = new AtomicBoolean();
179+
try (final ThresholdingOutputStream out = new ThresholdingOutputStream(7) {
180+
@Override
181+
protected void thresholdReached() throws IOException {
182+
reached.set(true);
183+
}
184+
}) {
185+
assertFalse(out.isThresholdExceeded());
186+
assertFalse(reached.get());
187+
out.write(new byte[0]);
188+
assertFalse(out.isThresholdExceeded());
189+
assertFalse(reached.get());
190+
}
191+
}
192192
}

0 commit comments

Comments
 (0)