You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/01/11 13:34:19 UTC
[commons-io] branch master updated: Use try-with-resources.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 02782f5 Use try-with-resources.
02782f5 is described below
commit 02782f5e735ec2920ec163e6750e5d9f64b15660
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Jan 11 08:34:17 2022 -0500
Use try-with-resources.
---
.../io/input/CharSequenceInputStreamTest.java | 32 +++++++++++-----------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java b/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
index 13dee59..4e19570 100644
--- a/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
@@ -195,26 +195,26 @@ private boolean isAvailabilityTestableForCharset(final String csName) {
// This is because the initial read fills the buffer from the CharSequence
// so data1 gets the first buffer full; data2 will get the next buffer full
private void testIO_356(final int bufferSize, final int dataSize, final int readFirst, final String csName) throws Exception {
- final CharSequenceInputStream is = new CharSequenceInputStream(ALPHABET, csName, bufferSize);
-
- for (int i = 0; i < readFirst; i++) {
- final int ch = is.read();
- assertNotEquals(-1, ch);
- }
-
- is.mark(dataSize);
+ final byte[] data1;
+ final byte[] data2;
+ try (final CharSequenceInputStream is = new CharSequenceInputStream(ALPHABET, csName, bufferSize)) {
+ for (int i = 0; i < readFirst; i++) {
+ final int ch = is.read();
+ assertNotEquals(-1, ch);
+ }
- final byte[] data1 = new byte[dataSize];
- final int readCount1 = is.read(data1);
- assertEquals(dataSize, readCount1);
+ is.mark(dataSize);
- is.reset(); // should allow data to be re-read
+ data1 = new byte[dataSize];
+ final int readCount1 = is.read(data1);
+ assertEquals(dataSize, readCount1);
- final byte[] data2 = new byte[dataSize];
- final int readCount2 = is.read(data2);
- assertEquals(dataSize, readCount2);
+ is.reset(); // should allow data to be re-read
- is.close();
+ data2 = new byte[dataSize];
+ final int readCount2 = is.read(data2);
+ assertEquals(dataSize, readCount2);
+ }
// data buffers should be identical
assertArrayEquals(data1, data2, "bufferSize=" + bufferSize + " dataSize=" + dataSize);