Skip to content

Commit d0ecdb0

Browse files
author
mgeipel
committed
fixed #47
1 parent c76c5c0 commit d0ecdb0

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
package org.culturegraph.mf.stream.sink;
17+
18+
import java.io.IOException;
19+
import java.io.Writer;
20+
21+
import org.culturegraph.mf.exceptions.MetafactureException;
22+
import org.culturegraph.mf.framework.ObjectReceiver;
23+
24+
/**
25+
* @param <T> object type
26+
*
27+
* @author Christoph Böhme, Markus Geipel
28+
*
29+
*/
30+
31+
32+
public final class ObjectJavaIoWriter<T> implements ObjectReceiver<T> {
33+
34+
private final Writer writer;
35+
36+
public ObjectJavaIoWriter(final Writer writer) {
37+
this.writer = writer;
38+
}
39+
40+
@Override
41+
public void process(final T obj) {
42+
try {
43+
writer.write(obj.toString());
44+
writer.append('\n');
45+
} catch (IOException e) {
46+
throw new MetafactureException(e);
47+
}
48+
}
49+
50+
@Override
51+
public void resetStream() {
52+
throw new UnsupportedOperationException("Cannot reset ObjectJavaIoWriter");
53+
}
54+
55+
@Override
56+
public void closeStream() {
57+
try {
58+
writer.close();
59+
} catch (IOException e) {
60+
throw new MetafactureException(e);
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)