+
+ /**
+ * Read a possibly encrypted line.
+ *
+ * @param in
+ * the stream to read from
+ * @return the unencrypted line
+ *
+ *
+ * @throws IOException
+ * in case of I/O error
+ * @throws SSLException
+ * in case of crypt error
+ */
+ private String readLine(InputStream in) throws IOException {
+ if (inReader == null) {
+ inReader = new BufferedReader(new InputStreamReader(in));
+ }
+ String line = inReader.readLine();
+ if (line != null) {
+ bytesReceived += line.length();
+ if (crypt != null) {
+ line = crypt.decrypt64s(line, false);
+ }
+ }
+
+ return line;
+ }
+
+ private BufferedReader inReader;
+
+ /**
+ * 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("\n".getBytes("UTF-8"));
+ bytesSent++;
+ }