Skip to content

Commit 90fd537

Browse files
author
mgeipel
committed
fixed #54
ObjectJavaIoWriter now optionally takes a IoWriterFactory as constructor argument.
1 parent 0daf49f commit 90fd537

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2013 Deutsche Nationalbibliothek
3+
*
4+
* Licensed under the Apache License, Version 2.0 the "License";
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.culturegraph.mf.stream.sink;
18+
19+
import java.io.Writer;
20+
21+
/**
22+
* Interface for classes creating {@link Writer}s. Used in {@link ObjectJavaIoWriter}.
23+
*
24+
* @author markus geipel
25+
*
26+
*/
27+
public interface IOWriterFactory {
28+
Writer createWriter();
29+
}

src/main/java/org/culturegraph/mf/stream/sink/ObjectJavaIoWriter.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@
3131

3232
public final class ObjectJavaIoWriter<T> implements ObjectReceiver<T> {
3333

34-
private final Writer writer;
34+
private Writer writer;
3535
private boolean closed;
36+
private final IOWriterFactory writerFactory;
3637

3738
public ObjectJavaIoWriter(final Writer writer) {
3839
this.writer = writer;
40+
writerFactory = null;
41+
}
42+
43+
public ObjectJavaIoWriter(final IOWriterFactory writerFactory) {
44+
this.writerFactory = writerFactory;
45+
this.writer = writerFactory.createWriter();
3946
}
4047

4148
@Override
@@ -51,7 +58,11 @@ public void process(final T obj) {
5158

5259
@Override
5360
public void resetStream() {
54-
throw new UnsupportedOperationException("Cannot reset ObjectJavaIoWriter");
61+
if(writerFactory==null){
62+
throw new UnsupportedOperationException("Cannot reset ObjectJavaIoWriter. No IOWriterFactory set.");
63+
}
64+
writer = writerFactory.createWriter();
65+
5566
}
5667

5768
@Override

0 commit comments

Comments
 (0)