![]() |
Code Examples
A repository of 155 code examples for BeepBeep
|
Read complete comma-separated tokens from the standard input. More...
Static Public Member Functions | |
static void | main (String[] args) throws ProcessorException, InterruptedException |
Read complete comma-separated tokens from the standard input.
You should first understand how ReadStdin works before look at this example. In this example, we pipe the character strings of the StreamReader into a CsvFeeder before sending its output into the Print
processor.
Graphically, the processor chain is represented as follows:
The main difference of this chain is that the CsvFeeder
only outputs complete tokens, which are delimited by a comma. Suppose you compile this program as a runnable JAR (for example, read-tokens.jar
) and run it in the same way as ReadStdin, using the named pipe mypipe
.
$ cat mypipe > java -jar read-tokens.jar
From a second command line window, you can now push strings to the program by echo
ing them to mypipe
:
$ echo "abc,def," > mypipe
The program will output
abc def
Note here how each of abc
and def
have been printed on two separate lines. This is because the CSV feeder broke the input string into two events, since there are two commas that indicate the presence of two tokens. This also means that the feeder waits until the comma before outputting an event; hence writing:
$ echo "gh" > mypipe
will result in no output. The CSV feeder buffers the character string until it sees the token delimiter. Typing:
$ echo "i,jkl," > mypipe
will produce
ghi jkl
The usefulness of the CsvFeeder (or of other token feeders available in BeepBeep) is to reconstruct complete tokens out of character strings. Processors such as the StreamReader read their input into chunks in such a way that a token can be split across two successive chunks (its beginning in the first chunk, and its end in the second).
Definition at line 88 of file ReadTokens.java.