Hello,
I am trying to get a feel for codec behavior so I decided to write a little test program
public class CodecTest {
private final static String filePath = "C:\\Users\\test\\test.txt";
public static void main(String[] args) {
Environment.initialize().assignErrorJournal();
Streams.wrap(IO.readFile(filePath, 10))
.decode(new DelimitedCodec<>((byte)32, true, StandardCodecs.STRING_CODEC)) //32 corresponds to a space
.consume(d -> {System.out.println(d);}, Throwable::printStackTrace, d -> System.out.println("EOF"));
}
}
Where test.txt contains the following text:
Hello, the quick brown fox jumps over the lazy dog.
If I omit the chunk-specifier (i.e., 10), Buffer.SMALL_BUFFER_SIZE will be used, I receive the following expected output:
Hello,
the
quick
brown
fox
jumps
over
the
lazy
EOF
Dog did not print because there was not a space. I believe.
If I keep it at 10 I get the output of:
Hello,
quick
wn
fox
ps
over
e
lazy
EOF
In the smaller buffer case it looks as if the buffers do not aggregate in anticipation of another delimiter, and functions through the flows are limited by the parent's buffer-size. Is this the expected behavior?
I ask because what I am ultimately trying to do is convert a stream of bytes into a message, and then pass that message along the stream. The stream of bytes contains a magic word and a length to separate each message. There is no guarantee that a read from the file (based on chunk size) will contain a full message; it could contain parts, or multiple messages (so the ability to buffer is necessary). Codec may not be the best way, but it seemed straightforward at first (because the stream is ultimately a collection of messages); map might have its uses. There shouldn't be multiple threads attacking this bit of code either since it's job is only to create messages for downstream subscribers. Any insight would be great.
Thanks,
James