I'm not sure I fully understand, you would like to read an InputStream once (in fact, this is not so dirty IMO, because if the error occurs only in the log stream, and not in the stream you are parsing?), And then just record and parse the same InputStream ?
If the above is the case to show a solution:
InputStream is=...; byte[] bytes=new byte[1028]; while(is.read(bytes)!=-1) { log(bytes);
even better for simultaneously logging and writing will create a new Thread / Runnable for both methods, run them and wait for them to return using ( thread.join(); ):
InputStream is=...; byte[] bytes=new byte[1028]; while(is.read(bytes)!=-1) { Thread t1=new Thread(new Runnable() { @Override public void run() { log(bytes); //call function to log } }); Thread t2=new Thread(new Runnable() { @Override public void run() { parse(bytes);//call function to parse } }); t1.start(); t2.start(); try { t1.join(); t2.join(); }catch(Exception ex) { ex.printStackTrace(); } }
source share