Skip to content

Commit c9106c6

Browse files
committed
Merge pull request #4 from garcia-jj/ot-addingcloseable
Using AutoCloseable to allow us to use try-with-resources statement
2 parents c603758 + 61c1e7b commit c9106c6

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/org/beanio/BeanReader.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.beanio;
1717

18+
import java.io.Closeable;
1819
import java.io.IOException;
1920

2021
import org.beanio.internal.util.Debuggable;
@@ -28,7 +29,7 @@
2829
* @since 1.0
2930
* @see StreamFactory
3031
*/
31-
public interface BeanReader extends Debuggable {
32+
public interface BeanReader extends Debuggable, Closeable {
3233

3334
/**
3435
* Reads a single bean from the input stream. If the end of the stream is
@@ -108,7 +109,8 @@ public int skip(int count) throws BeanReaderIOException, MalformedRecordExceptio
108109
* @throws BeanReaderIOException if the underlying input stream throws an
109110
* {@link IOException} or this reader was already closed
110111
*/
111-
public void close() throws BeanReaderIOException;
112+
@Override
113+
public void close() throws BeanReaderIOException;
112114

113115
/**
114116
* Sets the error handler to handle exceptions thrown by {@link #read()}.

src/org/beanio/BeanWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* @since 1.0
3030
* @see StreamFactory
3131
*/
32-
public interface BeanWriter extends Debuggable {
32+
public interface BeanWriter extends Debuggable, AutoCloseable {
3333

3434
/**
3535
* Writes a bean object to this output stream.
@@ -68,6 +68,7 @@ public interface BeanWriter extends Debuggable {
6868
* @throws BeanWriterIOException if the underlying output stream throws an {@link IOException},
6969
* or if this writer is already closed
7070
*/
71-
public void close() throws BeanWriterIOException;
71+
@Override
72+
public void close() throws BeanWriterIOException;
7273

7374
}

test/org/beanio/StreamFactoryTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,9 @@ public void testCreateReaderForFile() {
8585
factory.loadResource("org/beanio/mapping.xml");
8686

8787
File file = new File("test/org/beanio/file.txt");
88-
BeanReader in = factory.createReader("stream1", file);
89-
try {
88+
try (BeanReader in = factory.createReader("stream1", file)) {
9089
while (in.read() != null);
9190
}
92-
finally {
93-
in.close();
94-
}
9591
}
9692

9793
@Test(expected=BeanIOException.class)

0 commit comments

Comments
 (0)