File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed
src/main/java/org/culturegraph/mf/stream/sink Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 31
31
32
32
public final class ObjectJavaIoWriter <T > implements ObjectReceiver <T > {
33
33
34
- private final Writer writer ;
34
+ private Writer writer ;
35
35
private boolean closed ;
36
+ private final IOWriterFactory writerFactory ;
36
37
37
38
public ObjectJavaIoWriter (final Writer writer ) {
38
39
this .writer = writer ;
40
+ writerFactory = null ;
41
+ }
42
+
43
+ public ObjectJavaIoWriter (final IOWriterFactory writerFactory ) {
44
+ this .writerFactory = writerFactory ;
45
+ this .writer = writerFactory .createWriter ();
39
46
}
40
47
41
48
@ Override
@@ -51,7 +58,11 @@ public void process(final T obj) {
51
58
52
59
@ Override
53
60
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
+
55
66
}
56
67
57
68
@ Override
You can’t perform that action at this time.
0 commit comments