now mostly streamified!
[nikiroo-utils.git] / src / be / nikiroo / utils / serial / server / ConnectAction.java
index 901632627b218d35469fcc7cb6b71f2af2b8144d..d359e08b217f623ddde1749090aeefc2391deffd 100644 (file)
@@ -9,6 +9,7 @@ import javax.net.ssl.SSLException;
 
 import be.nikiroo.utils.CryptUtils;
 import be.nikiroo.utils.IOUtils;
+import be.nikiroo.utils.StringUtils;
 import be.nikiroo.utils.serial.Exporter;
 import be.nikiroo.utils.serial.Importer;
 import be.nikiroo.utils.streams.BufferedOutputStream;
@@ -288,7 +289,7 @@ abstract class ConnectAction {
                synchronized (lock) {
                        OutputStream sub;
                        if (crypt != null) {
-                               sub = crypt.encrypt64(out.open(), false);
+                               sub = crypt.encrypt64(out.open());
                        } else {
                                sub = out.open();
                        }
@@ -301,7 +302,7 @@ abstract class ConnectAction {
 
                        try {
                                if (asString) {
-                                       sub.write(data.toString().getBytes("UTF-8"));
+                                       sub.write(StringUtils.getBytes(data.toString()));
                                } else {
                                        new Exporter(sub).append(data);
                                }
@@ -363,6 +364,7 @@ abstract class ConnectAction {
         * @throws java.lang.NullPointerException
         *             for Objects only: if the counter part has no data to send
         */
+       @SuppressWarnings("resource")
        private Object rec(boolean asString) throws IOException,
                        NoSuchFieldException, NoSuchMethodException,
                        ClassNotFoundException, java.lang.NullPointerException {
@@ -374,7 +376,7 @@ abstract class ConnectAction {
                                        contentToSend = false;
                                }
 
-                               if (in.next()) {
+                               if (in.next() && !in.eof()) {
                                        // TODO: could be possible to check for non-crypt and only
                                        // do it for crypt
                                        InputStream read = new ReplaceInputStream(in.open(), //
@@ -383,7 +385,7 @@ abstract class ConnectAction {
 
                                        try {
                                                if (crypt != null) {
-                                                       read = crypt.decrypt64(read, false);
+                                                       read = crypt.decrypt64(read);
                                                }
 
                                                if (asString) {