+
+ /**
+ * Read a possibly encrypted line, or NULL if no more content.
+ *
+ * @param in
+ * the stream to read from
+ *
+ * @return the unencrypted line or NULL
+ *
+ *
+ * @throws IOException
+ * in case of I/O error
+ * @throws SSLException
+ * in case of crypt error
+ */
+ private String readLine(NextableInputStream in) throws IOException {
+ if (in.next()) {
+ String line = IOUtils.readSmallStream(in);
+ bytesReceived += line.length();
+ if (crypt != null) {
+ line = crypt.decrypt64s(line, false);
+ }
+
+ return line;
+ }
+
+ return null;
+ }
+
+ /**
+ * Write a line, possible encrypted.
+ *
+ * @param out
+ * the stream to write to
+ * @param line
+ * the line to write
+ * @throws IOException
+ * in case of I/O error
+ * @throws SSLException
+ * in case of crypt error
+ */
+ private void writeLine(OutputStream out, String line) throws IOException {
+ if (crypt == null) {
+ out.write(line.getBytes("UTF-8"));
+ bytesSent += line.length();
+ } else {
+ // TODO: how NOT to create so many big Strings?
+ String b64 = crypt.encrypt64(line, false);
+ out.write(b64.getBytes("UTF-8"));
+ bytesSent += b64.length();
+ }
+ out.write('\b');
+ bytesSent++;
+ }