thufir

Untitled

Aug 29th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package teln;
  2.  
  3. import static java.lang.System.out;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6.  
  7. public class StreamReader {
  8.  
  9. private StreamReader() {
  10. }
  11.  
  12. StreamReader(InputStream inputStream) throws IOException {
  13. printEachLine(inputStream);
  14. }
  15.  
  16. private void printEachLine(InputStream inputStream) {
  17. char ch = 0;
  18. StringBuilder sb = new StringBuilder();
  19. out.println("lines..");
  20. boolean eol = false;
  21. do {
  22. try {
  23. ch = (char) inputStream.read();
  24. } catch (IOException ex) {
  25. out.println(sb); //hmm, doesn't seem to print...or prints nothing
  26. }
  27. sb.append(ch);
  28. if ((ch == 10)) {
  29. out.print(sb); //prints everything but last line
  30. sb = new StringBuilder();
  31. }
  32.  
  33. } while (!eol);
  34.  
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment