I have a Java inputstream, that I skip 2 bytes every n bytes. Now the output of that are bytes that are clean after stripping the 2 delimiters every n bytes.
This output is a series of bytes where the first 4 bytes represent a length, so I need to get these calculate the length int and extract length + additional length bytes and write them to a file.
I use buffer to strip the 2 bytes but am not sure how to extract the length and length bytes. Basically, I need to gather/accumulate bytes for length and the additional length bytes that represent the message. Any help is appreciated.
Observable<Integer> byteObservable = Observable.create(emitter -> { try { while (true) { int b = fis.read(); if (b == -1) { // No more bytes to read emitter.onComplete(); } else { emitter.onNext(b); } } } catch (IOException e) { emitter.onError(e); } }); byteObservable .buffer(100, 102) // Buffer 100, skip 101/102 As an example consider the stream to be
05AB@@CDE0@@7123@@4567@@10AB@@CDEF@@GHIJ Stripped of @@ at every 4 bytes
05ABCDE07123456710ABCDEFGHIJ This is made of sub messages
05 ABCDE 07 1234567 10 ABCDEFGHIJ Take each of those messages and write them to a file.