From: Niki Roo Date: Sun, 3 Mar 2019 11:07:17 +0000 (+0100) Subject: update to latest nikiroo-utils X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;ds=sidebyside;p=jvcard.git update to latest nikiroo-utils --- diff --git a/libs/nikiroo-utils-2.0.0-sources.jar b/libs/nikiroo-utils-4.4.5-sources.jar similarity index 55% rename from libs/nikiroo-utils-2.0.0-sources.jar rename to libs/nikiroo-utils-4.4.5-sources.jar index 26cad68..de86d02 100644 Binary files a/libs/nikiroo-utils-2.0.0-sources.jar and b/libs/nikiroo-utils-4.4.5-sources.jar differ diff --git a/src/be/nikiroo/jvcard/launcher/Main.java b/src/be/nikiroo/jvcard/launcher/Main.java index 0860fec..61287b3 100644 --- a/src/be/nikiroo/jvcard/launcher/Main.java +++ b/src/be/nikiroo/jvcard/launcher/Main.java @@ -1,17 +1,13 @@ package be.nikiroo.jvcard.launcher; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Field; import java.net.Socket; import java.nio.charset.Charset; import java.util.LinkedList; import java.util.List; -import javax.imageio.ImageIO; - import be.nikiroo.jvcard.Card; import be.nikiroo.jvcard.Contact; import be.nikiroo.jvcard.Data; @@ -26,6 +22,8 @@ import be.nikiroo.jvcard.resources.DisplayOption; import be.nikiroo.jvcard.resources.RemoteBundle; import be.nikiroo.jvcard.resources.StringId; import be.nikiroo.jvcard.resources.TransBundle; +import be.nikiroo.utils.IOUtils; +import be.nikiroo.utils.Image; import be.nikiroo.utils.ImageUtils; import be.nikiroo.utils.StringUtils; import be.nikiroo.utils.Version; @@ -40,6 +38,7 @@ import be.nikiroo.utils.resources.Bundles; * */ public class Main { + /** The name of the program */ static public final String APPLICATION_TITLE = "jVcard"; static private final int ERR_NO_FILE = 1; @@ -353,14 +352,11 @@ public class Main { } String b64; - InputStream in = null; + Image img = new Image(IOUtils.toByteArray(f)); try { - in = new FileInputStream(f); - b64 = ImageUtils.toBase64(in); + b64 = img.toBase64(); } finally { - if (in != null) { - in.close(); - } + img.close(); } // remove previous photos: @@ -400,10 +396,10 @@ public class Main { String filename = contact.toString(format, ""); File f = new File(dir, filename + ".png"); System.out.println("Saving " + f); + Image img = new Image(photo.getValue()); try { - ImageIO.write( - ImageUtils.fromBase64(photo.getValue()), - "png", f); + ImageUtils.getInstance().saveAsImage(img, f, + "png"); } catch (IOException e) { System.err.println(trans( StringId.CLI_ERR_CANNOT_SAVE_PHOTO, diff --git a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java index 791d57c..2137bd8 100644 --- a/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java +++ b/src/be/nikiroo/jvcard/tui/panes/ContactDetails.java @@ -16,8 +16,8 @@ import be.nikiroo.jvcard.tui.KeyAction; import be.nikiroo.jvcard.tui.KeyAction.DataType; import be.nikiroo.jvcard.tui.KeyAction.Mode; import be.nikiroo.jvcard.tui.UiColors; -import be.nikiroo.utils.ImageUtils; import be.nikiroo.utils.StringUtils; +import be.nikiroo.utils.ui.ImageUtilsAwt; import com.googlecode.lanterna.TerminalSize; import com.googlecode.lanterna.gui2.BorderLayout; @@ -196,7 +196,13 @@ public class ContactDetails extends MainContent { if (encoding != null && encoding.getValue() != null && encoding.getValue().equalsIgnoreCase("b")) { try { - image = ImageUtils.fromBase64(photo.getValue()); + be.nikiroo.utils.Image img = new be.nikiroo.utils.Image( + photo.getValue()); + try { + image = ImageUtilsAwt.fromImage(img); + } finally { + img.close(); + } } catch (Exception e) { System.err.println("Cannot parse image for contact: " + contact.getPreferredDataValue("UID"));