Skip to content

Commit 2f18e22

Browse files
committed
Sort members
1 parent df09ef8 commit 2f18e22

8 files changed

Lines changed: 124 additions & 124 deletions

File tree

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,20 @@ public static void readFully(final Reader reader, final char[] buffer, final int
21622162
}
21632163
}
21642164

2165+
/**
2166+
* Gets the contents of a {@link CharSequence} as a list of Strings, one entry per line.
2167+
*
2168+
* @param csq the {@link CharSequence} to read, not null
2169+
* @return the list of Strings, never null
2170+
* @throws UncheckedIOException if an I/O error occurs
2171+
* @since 2.18.0
2172+
*/
2173+
public static List<String> readLines(final CharSequence csq) throws UncheckedIOException {
2174+
try (CharSequenceReader reader = new CharSequenceReader(csq)) {
2175+
return readLines(reader);
2176+
}
2177+
}
2178+
21652179
/**
21662180
* Gets the contents of an {@link InputStream} as a list of Strings,
21672181
* one entry per line, using the default character encoding of the platform.
@@ -2244,20 +2258,6 @@ public static List<String> readLines(final Reader reader) throws UncheckedIOExce
22442258
return toBufferedReader(reader).lines().collect(Collectors.toList());
22452259
}
22462260

2247-
/**
2248-
* Gets the contents of a {@link CharSequence} as a list of Strings, one entry per line.
2249-
*
2250-
* @param csq the {@link CharSequence} to read, not null
2251-
* @return the list of Strings, never null
2252-
* @throws UncheckedIOException if an I/O error occurs
2253-
* @since 2.18.0
2254-
*/
2255-
public static List<String> readLines(final CharSequence csq) throws UncheckedIOException {
2256-
try (CharSequenceReader reader = new CharSequenceReader(csq)) {
2257-
return readLines(reader);
2258-
}
2259-
}
2260-
22612261
/**
22622262
* Gets the contents of a resource as a byte array.
22632263
* <p>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public static Builder builder() {
9797
return new Builder();
9898
}
9999

100+
private AutoCloseInputStream(final Builder builder) throws IOException {
101+
super(builder);
102+
}
103+
100104
/**
101105
* Constructs an automatically closing proxy for the given input stream.
102106
*
@@ -109,10 +113,6 @@ public AutoCloseInputStream(final InputStream in) {
109113
super(ClosedInputStream.ifNull(in));
110114
}
111115

112-
private AutoCloseInputStream(final Builder builder) throws IOException {
113-
super(builder);
114-
}
115-
116116
/**
117117
* Automatically closes the stream if the end of stream was reached.
118118
*

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ public BufferedFileChannelInputStream(final File file, final int bufferSize) thr
157157
this(file.toPath(), bufferSize);
158158
}
159159

160+
private BufferedFileChannelInputStream(final FileChannel fileChannel, final int bufferSize) {
161+
this.fileChannel = Objects.requireNonNull(fileChannel, "path");
162+
byteBuffer = ByteBuffer.allocateDirect(bufferSize);
163+
byteBuffer.flip();
164+
}
165+
160166
/**
161167
* Constructs a new instance for the given Path.
162168
*
@@ -183,12 +189,6 @@ public BufferedFileChannelInputStream(final Path path, final int bufferSize) thr
183189
this(FileChannel.open(path, StandardOpenOption.READ), bufferSize);
184190
}
185191

186-
private BufferedFileChannelInputStream(final FileChannel fileChannel, final int bufferSize) {
187-
this.fileChannel = Objects.requireNonNull(fileChannel, "path");
188-
byteBuffer = ByteBuffer.allocateDirect(bufferSize);
189-
byteBuffer.flip();
190-
}
191-
192192
@Override
193193
public synchronized int available() throws IOException {
194194
if (!fileChannel.isOpen()) {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,6 @@ public B setAfterRead(final IOIntConsumer afterRead) {
102102

103103
private final IOIntConsumer afterRead;
104104

105-
/**
106-
* Constructs a new ProxyInputStream.
107-
*
108-
* @param proxy the InputStream to proxy.
109-
*/
110-
public ProxyInputStream(final InputStream proxy) {
111-
// the delegate is stored in a protected superclass variable named 'in'.
112-
super(proxy);
113-
this.exceptionHandler = Erase::rethrow;
114-
this.afterRead = IOIntConsumer.NOOP;
115-
}
116-
117105
/**
118106
* Constructs a new ProxyInputStream.
119107
*
@@ -127,6 +115,18 @@ protected ProxyInputStream(final AbstractBuilder<?, ?> builder) throws IOExcepti
127115
this(builder.getInputStream(), builder);
128116
}
129117

118+
/**
119+
* Constructs a new ProxyInputStream.
120+
*
121+
* @param proxy the InputStream to proxy.
122+
*/
123+
public ProxyInputStream(final InputStream proxy) {
124+
// the delegate is stored in a protected superclass variable named 'in'.
125+
super(proxy);
126+
this.exceptionHandler = Erase::rethrow;
127+
this.afterRead = IOIntConsumer.NOOP;
128+
}
129+
130130
/**
131131
* Constructs a new ProxyInputStream.
132132
*

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ private RandomAccessFileOutputStream(final RandomAccessFile randomAccessFile) {
8484
}
8585

8686
@Override
87-
public void write(final int b) throws IOException {
88-
randomAccessFile.write(b);
87+
public void close() throws IOException {
88+
this.randomAccessFile.close();
89+
super.close();
8990
}
9091

9192
@SuppressWarnings("resource")
@@ -96,9 +97,8 @@ public void flush() throws IOException {
9697
}
9798

9899
@Override
99-
public void close() throws IOException {
100-
this.randomAccessFile.close();
101-
super.close();
100+
public void write(final int b) throws IOException {
101+
randomAccessFile.write(b);
102102
}
103103

104104
}

src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,35 @@ private void compare(final String message, final byte[] expected, final byte[] a
5151
}
5252
}
5353

54+
@Test
55+
public void testAfterReadConsumer() throws Exception {
56+
final byte[] hello = "Hello".getBytes(StandardCharsets.UTF_8);
57+
final AtomicBoolean boolRef = new AtomicBoolean();
58+
// @formatter:off
59+
try (InputStream bounded = BoundedInputStream.builder()
60+
.setInputStream(new ByteArrayInputStream(hello))
61+
.setMaxCount(hello.length)
62+
.setAfterRead(i -> boolRef.set(true))
63+
.get()) {
64+
IOUtils.consume(bounded);
65+
}
66+
// @formatter:on
67+
assertTrue(boolRef.get());
68+
// Throwing
69+
final String message = "test exception message";
70+
// @formatter:off
71+
try (InputStream bounded = BoundedInputStream.builder()
72+
.setInputStream(new ByteArrayInputStream(hello))
73+
.setMaxCount(hello.length)
74+
.setAfterRead(i -> {
75+
throw new CustomIOException(message);
76+
})
77+
.get()) {
78+
assertEquals(message, assertThrowsExactly(CustomIOException.class, () -> IOUtils.consume(bounded)).getMessage());
79+
}
80+
// @formatter:on
81+
}
82+
5483
@SuppressWarnings("resource")
5584
@Test
5685
public void testAvailableAfterClose() throws Exception {
@@ -80,22 +109,6 @@ public void testCloseHandleIOException() throws IOException {
80109
ProxyInputStreamTest.testCloseHandleIOException(BoundedInputStream.builder());
81110
}
82111

83-
@SuppressWarnings("deprecation")
84-
@Test
85-
public void testPublicConstructors() throws IOException {
86-
final byte[] helloWorld = "Hello World".getBytes(StandardCharsets.UTF_8);
87-
try (ByteArrayInputStream baos = new ByteArrayInputStream(helloWorld);
88-
BoundedInputStream inputStream = new BoundedInputStream(baos)) {
89-
assertSame(baos, inputStream.unwrap());
90-
}
91-
final long maxCount = 2;
92-
try (ByteArrayInputStream baos = new ByteArrayInputStream(helloWorld);
93-
BoundedInputStream inputStream = new BoundedInputStream(baos, maxCount)) {
94-
assertSame(baos, inputStream.unwrap());
95-
assertSame(maxCount, inputStream.getMaxCount());
96-
}
97-
}
98-
99112
@ParameterizedTest
100113
@ValueSource(longs = { -100, -1, 0, 1, 2, 4, 8, 16, 32, 64 })
101114
public void testCounts(final long startCount) throws Exception {
@@ -287,35 +300,6 @@ public void testMarkReset() throws Exception {
287300
}
288301
}
289302

290-
@Test
291-
public void testAfterReadConsumer() throws Exception {
292-
final byte[] hello = "Hello".getBytes(StandardCharsets.UTF_8);
293-
final AtomicBoolean boolRef = new AtomicBoolean();
294-
// @formatter:off
295-
try (InputStream bounded = BoundedInputStream.builder()
296-
.setInputStream(new ByteArrayInputStream(hello))
297-
.setMaxCount(hello.length)
298-
.setAfterRead(i -> boolRef.set(true))
299-
.get()) {
300-
IOUtils.consume(bounded);
301-
}
302-
// @formatter:on
303-
assertTrue(boolRef.get());
304-
// Throwing
305-
final String message = "test exception message";
306-
// @formatter:off
307-
try (InputStream bounded = BoundedInputStream.builder()
308-
.setInputStream(new ByteArrayInputStream(hello))
309-
.setMaxCount(hello.length)
310-
.setAfterRead(i -> {
311-
throw new CustomIOException(message);
312-
})
313-
.get()) {
314-
assertEquals(message, assertThrowsExactly(CustomIOException.class, () -> IOUtils.consume(bounded)).getMessage());
315-
}
316-
// @formatter:on
317-
}
318-
319303
@Test
320304
public void testOnMaxCountConsumer() throws Exception {
321305
final byte[] hello = "Hello".getBytes(StandardCharsets.UTF_8);
@@ -444,6 +428,22 @@ public void testOnMaxLength() throws Exception {
444428
}
445429
}
446430

431+
@SuppressWarnings("deprecation")
432+
@Test
433+
public void testPublicConstructors() throws IOException {
434+
final byte[] helloWorld = "Hello World".getBytes(StandardCharsets.UTF_8);
435+
try (ByteArrayInputStream baos = new ByteArrayInputStream(helloWorld);
436+
BoundedInputStream inputStream = new BoundedInputStream(baos)) {
437+
assertSame(baos, inputStream.unwrap());
438+
}
439+
final long maxCount = 2;
440+
try (ByteArrayInputStream baos = new ByteArrayInputStream(helloWorld);
441+
BoundedInputStream inputStream = new BoundedInputStream(baos, maxCount)) {
442+
assertSame(baos, inputStream.unwrap());
443+
assertSame(maxCount, inputStream.getMaxCount());
444+
}
445+
}
446+
447447
@SuppressWarnings("resource")
448448
@Test
449449
public void testReadAfterClose() throws Exception {

0 commit comments

Comments
 (0)