Fix regression in AbstractConnection: return null instead of empty string on closed connection

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1179 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-13 07:07:29 +00:00
parent a702183d1a
commit 2cab4c6ded
1 changed files with 11 additions and 2 deletions

View File

@ -52,7 +52,7 @@ public class AbstractConnection extends Thread {
}
public String readLine() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteArrayOutputStream baos = null;
int b;
while ((b = read()) > -1) {
if (b == '\r') {
@ -64,13 +64,21 @@ public class AbstractConnection extends Thread {
} else if (b == '\n') {
break;
}
if (baos == null) {
baos = new ByteArrayOutputStream();
}
baos.write(b);
}
return new String(baos.toByteArray(), encoding);
if (baos != null) {
return new String(baos.toByteArray(), encoding);
} else {
return null;
}
}
/**
* Read byteSize bytes from inputStream, return content as String.
*
* @param byteSize content size
* @return content
* @throws IOException on error
@ -81,6 +89,7 @@ public class AbstractConnection extends Thread {
/**
* Read byteSize bytes from inputStream, return content as byte array.
*
* @param byteSize content size
* @return content
* @throws IOException on error