Fixed all issues in boundary stream

This commit is contained in:
Ziver Koc 2016-07-12 17:22:30 +02:00
parent 43dc9a11cb
commit f2939f819f
9 changed files with 139 additions and 67 deletions

View file

@ -88,6 +88,25 @@ public class IOUtil {
return str.toString();
}
/**
* Reads on line terminated by a new line or carriage return from a stream.
*
* @param in the stream to read from
* @return a String that contains one line excluding line terminating
* characters, null if it is the end of the stream
*/
public static String readLine(InputStream in) throws IOException {
StringBuilder str = new StringBuilder(80);
int c = 0;
while ((c=in.read()) >= 0 && (c != '\n') && (c != '\r'))
str.append((char)c);
if (c == '\r')
in.read(); // if the last char is carriage return we assume the next char in the stream will be new line so skip it
if (c == -1 && str.length() == 0)
return null; // End of the stream
return str.toString();
}
/**
* Copies all data from one InputStream to another OutputStream.
* The streams will not be closed after method has returned.