|
16 | 16 | package org.metafacture.strings;
|
17 | 17 |
|
18 | 18 | import org.metafacture.framework.FluxCommand;
|
19 |
| -import org.metafacture.framework.ObjectPipe; |
20 | 19 | import org.metafacture.framework.ObjectReceiver;
|
21 | 20 | import org.metafacture.framework.annotations.Description;
|
22 | 21 | import org.metafacture.framework.annotations.In;
|
23 | 22 | import org.metafacture.framework.annotations.Out;
|
| 23 | +import org.metafacture.framework.helpers.DefaultObjectPipe; |
24 | 24 |
|
25 | 25 | /**
|
26 | 26 | * Collects strings and emits them as records when a line matches the pattern.
|
|
34 | 34 | @In(String.class)
|
35 | 35 | @Out(String.class)
|
36 | 36 | @FluxCommand("lines-to-records")
|
37 |
| -public final class LineRecorder implements ObjectPipe<String, ObjectReceiver<String>> { |
| 37 | +public final class LineRecorder extends DefaultObjectPipe<String, ObjectReceiver<String>> { |
38 | 38 |
|
39 | 39 | private static final int SB_CAPACITY = 4096 * 7;
|
40 | 40 | // empty line is the default
|
@@ -70,34 +70,16 @@ record = new StringBuilder(SB_CAPACITY);
|
70 | 70 | }
|
71 | 71 | }
|
72 | 72 |
|
73 |
| - private boolean isClosed() { |
74 |
| - return isClosed; |
75 |
| - } |
76 |
| - |
77 | 73 | @Override
|
78 |
| - public void resetStream() { |
79 |
| - record = new StringBuilder(SB_CAPACITY); |
80 |
| - } |
81 |
| - |
82 |
| - @Override |
83 |
| - public void closeStream() { |
84 |
| - getReceiver().process(record.toString()); |
85 |
| - isClosed = true; |
| 74 | + protected void onCloseStream() { |
| 75 | + if (record.length() > 0) { |
| 76 | + getReceiver().process(record.toString()); |
| 77 | + } |
86 | 78 | }
|
87 | 79 |
|
88 | 80 | @Override
|
89 |
| - public <R extends ObjectReceiver<String>> R setReceiver(final R newReceiver) { |
90 |
| - receiver = newReceiver; |
91 |
| - return newReceiver; |
92 |
| - } |
93 |
| - |
94 |
| - /** |
95 |
| - * Returns a reference to the downstream module. |
96 |
| - * |
97 |
| - * @return reference to the downstream module |
98 |
| - */ |
99 |
| - protected ObjectReceiver<String> getReceiver() { |
100 |
| - return receiver; |
| 81 | + public void onResetStream() { |
| 82 | + record = new StringBuilder(SB_CAPACITY); |
101 | 83 | }
|
102 | 84 |
|
103 | 85 | }
|
0 commit comments