private String readLine() throws IOException {
		byte[] readBytes = new byte[512];
		int readIndex = 0;
		while (true) {
			int nextByte = remoteInputStream.read();
			if (nextByte == -1) {
				if (readIndex == 0) {
					return null;
				}
				break;
			}
			if (nextByte == 10) {
				if (!ignoreNextLinefeed) {
					break;
				}
			}
			ignoreNextLinefeed = false;
			if (nextByte == 13) {
				ignoreNextLinefeed = true;
				break;
			}
			if (readIndex == readBytes.length) {
				/* recopy & enlarge array */
				byte[] newReadBytes = new byte[readBytes.length * 2];
				System.arraycopy(readBytes, 0, newReadBytes, 0, readBytes.length);
				readBytes = newReadBytes;
			}
			readBytes[readIndex++] = (byte) nextByte;
		}
		ByteBuffer byteBuffer = ByteBuffer.wrap(readBytes, 0, readIndex);
		return Charset.forName("UTF-8").decode(byteBuffer).toString();
	}