Using a java.util.Scanner instance, is it possible for it to return all remaining content? My scenario is that once I have read a number of fields within a String, I just want to get whatever is left and store that somewhere else. For example my content could include:
1,2,Some Garbage with \' special characters and so on
I would construct the scanner using , as the delimiter, call getInt() twice and then want to get "Some Garbage with \' special characters and so on" back in one call.
There is no “good” way to do this with Scanner. You can try
String next(Pattern pattern)passing to it multiline pattern like$:Pattern p = Pattern.compile("$", Pattern.MULTILINE);I have not tried this but it will probably work. Just do not forget to check it when several lines are remaining in your input.
BUT I think that better way is just to read from wrapped input stream using ordinary
read(byte[])method in loop. It is because Scanner is not attended to read stream as is. It is attended to read separate fields. And it does it very well. In your case you just want to read “blob”, so just read it using payload stream.