java BufferReader has a method readLine which reads till '\n' or '\r' is read and then returns the line string. Example:
InputStreamReader isr = new InputStreamReader(socket.getInputStream());
BufferReader br =new BufferReader(isr);
String line = null;
while ((line = br.readLine()) != null) {
// Do something
}
I want a custom buffer which reads exactly like BufferReader but instead of returning line when it matches '\n', it should return the string till it reads a pattern 10=???\u0001.
It is basically a fix message which always ends with 10=???\u0001, where ? is number and \u0001 is a character.
You might be interested in using a
Scannerwith a custom delimiter (set usinguseDelimiter).You really shouldn’t override a method named
readLineto do anything other than read lines (as delimited by\r\n,\n\ror\nbased on your operating system). It’s counter intuitive and can be confusing to yourself or others later down the road.