VERSION + fix custom image
[nikiroo-utils.git] / src / be / nikiroo / utils / serial / SerialUtils.java
index c65463281ea51eca82729db53f40370942ab55f6..a6a02a8e06205cb5996b0a94c1124056ce2cbf60 100644 (file)
@@ -174,7 +174,8 @@ public class SerialUtils {
                                                in.close();
                                        }
                                } finally {
-                                       encoded.close();
+                                       encoded.flush();
+                                       // Cannot close!
                                }
                        }
 
@@ -186,7 +187,9 @@ public class SerialUtils {
                        @Override
                        protected Object fromStream(InputStream in) throws IOException {
                                try {
-                                       return new Image(in);
+                                       // Cannot close it!
+                                       InputStream decoded = StringUtils.unbase64(in, false);
+                                       return new Image(decoded);
                                } catch (IOException e) {
                                        throw new UnknownFormatConversionException(e.getMessage());
                                }
@@ -373,6 +376,8 @@ public class SerialUtils {
                                e.printStackTrace(); // should not happen (see
                                                                                // setAccessible)
                        }
+
+                       write(out, "\n}");
                }
        }
 
@@ -512,7 +517,7 @@ public class SerialUtils {
                        if (e instanceof IOException) {
                                throw (IOException) e;
                        }
-                       throw new IOException(e.getMessage());
+                       throw new IOException(e.getMessage(), e);
                }
        }