13
13
* See the License for the specific language governing permissions and
14
14
* limitations under the License.
15
15
*/
16
- package org .culturegraph .mf .stream .converter ;
17
-
18
- import java .util .regex .Pattern ;
19
-
20
- import org .culturegraph .mf .exceptions .FormatException ;
21
- import org .culturegraph .mf .framework .DefaultObjectPipe ;
22
- import org .culturegraph .mf .framework .StreamReceiver ;
23
- import org .culturegraph .mf .framework .annotations .Description ;
24
- import org .culturegraph .mf .framework .annotations .In ;
25
- import org .culturegraph .mf .framework .annotations .Out ;
26
- import org .culturegraph .mf .types .CGEntity ;
27
- import org .slf4j .Logger ;
28
- import org .slf4j .LoggerFactory ;
29
-
30
-
31
- /**
32
- * Reads Strings CGEntity format.
33
- *
34
- * @see CGEntityEncoder
35
- *
36
- * @author Markus Michael Geipel, Christoph Böhme
37
- *
38
- */
39
- @ Description ("Reads Strings CGEntity format." )
40
- @ In (String .class )
41
- @ Out (StreamReceiver .class )
42
- public final class CGEntityDecoder
43
- extends DefaultObjectPipe <String , StreamReceiver > {
44
-
45
- private static final Pattern FIELD_PATTERN = Pattern .compile (
46
- String .valueOf (CGEntity .FIELD_DELIMITER ), Pattern .LITERAL );
47
- private static final Pattern SUBFIELD_PATTERN = Pattern .compile (
48
- String .valueOf (CGEntity .SUB_DELIMITER ), Pattern .LITERAL );
49
-
50
- private static final Logger LOG = LoggerFactory
51
- .getLogger (CGEntityDecoder .class );
52
-
53
- @ Override
54
- public void process (final String record ) {
55
- process (record , getReceiver ());
56
- }
57
-
58
- public static void process (final String record , final StreamReceiver receiver ) {
59
- try {
60
- final String [] fields = FIELD_PATTERN .split (record );
61
- receiver .startRecord (fields [0 ]);
62
- for (int i = 1 ; i < fields .length ; ++i ) {
63
- final char firstChar = fields [i ].charAt (0 );
64
- if (firstChar == CGEntity .LITERAL_MARKER ) {
65
- final String [] parts = SUBFIELD_PATTERN
66
- .split (fields [i ], -1 );
67
- receiver .literal (
68
- parts [0 ].substring (1 ),
69
- parts [1 ].replace (CGEntity .NEWLINE_ESC ,
70
- CGEntity .NEWLINE ));
71
- } else if (firstChar == CGEntity .ENTITY_START_MARKER ) {
72
- receiver .startEntity (fields [i ].substring (1 ));
73
- } else if (firstChar == CGEntity .ENTITY_END_MARKER ) {
74
- receiver .endEntity ();
75
- } else if (firstChar == CGEntity .NEWLINE ) {
76
- LOG .debug ("unexpected newline" );
77
- } else {
78
- throw new FormatException (record );
79
- }
80
- }
81
- receiver .endRecord ();
82
- } catch (IndexOutOfBoundsException exception ) {
83
- throw new FormatException (record , exception );
84
- }
85
- }
86
-
16
+ package org .culturegraph .mf .stream .converter ;
17
+
18
+ import java .util .regex .Pattern ;
19
+
20
+ import org .culturegraph .mf .exceptions .FormatException ;
21
+ import org .culturegraph .mf .framework .DefaultObjectPipe ;
22
+ import org .culturegraph .mf .framework .StreamReceiver ;
23
+ import org .culturegraph .mf .framework .annotations .Description ;
24
+ import org .culturegraph .mf .framework .annotations .In ;
25
+ import org .culturegraph .mf .framework .annotations .Out ;
26
+ import org .culturegraph .mf .types .CGEntity ;
27
+ import org .slf4j .Logger ;
28
+ import org .slf4j .LoggerFactory ;
29
+
30
+
31
+ /**
32
+ * Reads Strings CGEntity format.
33
+ *
34
+ * @see CGEntityEncoder
35
+ *
36
+ * @author Markus Michael Geipel, Christoph Böhme
37
+ *
38
+ * @deprecated Use FormetaDecoder instead
39
+ *
40
+ */
41
+ @ Description ("Reads Strings CGEntity format." )
42
+ @ In (String .class )
43
+ @ Out (StreamReceiver .class )
44
+ @ Deprecated
45
+ public final class CGEntityDecoder
46
+ extends DefaultObjectPipe <String , StreamReceiver > {
47
+
48
+ private static final Pattern FIELD_PATTERN = Pattern .compile (
49
+ String .valueOf (CGEntity .FIELD_DELIMITER ), Pattern .LITERAL );
50
+ private static final Pattern SUBFIELD_PATTERN = Pattern .compile (
51
+ String .valueOf (CGEntity .SUB_DELIMITER ), Pattern .LITERAL );
52
+
53
+ private static final Logger LOG = LoggerFactory
54
+ .getLogger (CGEntityDecoder .class );
55
+
56
+ @ Override
57
+ public void process (final String record ) {
58
+ process (record , getReceiver ());
59
+ }
60
+
61
+ public static void process (final String record , final StreamReceiver receiver ) {
62
+ try {
63
+ final String [] fields = FIELD_PATTERN .split (record );
64
+ receiver .startRecord (fields [0 ]);
65
+ for (int i = 1 ; i < fields .length ; ++i ) {
66
+ final char firstChar = fields [i ].charAt (0 );
67
+ if (firstChar == CGEntity .LITERAL_MARKER ) {
68
+ final String [] parts = SUBFIELD_PATTERN
69
+ .split (fields [i ], -1 );
70
+ receiver .literal (
71
+ parts [0 ].substring (1 ),
72
+ parts [1 ].replace (CGEntity .NEWLINE_ESC ,
73
+ CGEntity .NEWLINE ));
74
+ } else if (firstChar == CGEntity .ENTITY_START_MARKER ) {
75
+ receiver .startEntity (fields [i ].substring (1 ));
76
+ } else if (firstChar == CGEntity .ENTITY_END_MARKER ) {
77
+ receiver .endEntity ();
78
+ } else if (firstChar == CGEntity .NEWLINE ) {
79
+ LOG .debug ("unexpected newline" );
80
+ } else {
81
+ throw new FormatException (record );
82
+ }
83
+ }
84
+ receiver .endRecord ();
85
+ } catch (IndexOutOfBoundsException exception ) {
86
+ throw new FormatException (record , exception );
87
+ }
88
+ }
89
+
87
90
}
0 commit comments