changeset 7:801cdc780ca8

Work around ImageIO bug.
author David Barts <n5jrn@me.com>
date Fri, 17 Jul 2020 19:56:25 -0700
parents 9129ae110146
children b5fcabce391f
files src/name/blackcap/imageprep/Menus.kt
diffstat 1 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/name/blackcap/imageprep/Menus.kt	Fri Jul 17 17:58:55 2020 -0700
+++ b/src/name/blackcap/imageprep/Menus.kt	Fri Jul 17 19:56:25 2020 -0700
@@ -97,9 +97,15 @@
         w.dispose()
     }
 
+    /* xxx - ImageIO bug? */
+    private class NullOutputStream : java.io.OutputStream() {
+        override fun write(b: Int): Unit {}
+    }
+
     private fun doClose() {
         val w = FocusManager.getCurrentManager().activeWindow as? RotateDialog
         if (w == null) {
+            LOGGER.log(Level.INFO, "beep!")
             Toolkit.getDefaultToolkit().beep()
             return
         }
@@ -125,7 +131,21 @@
         swingWorker<IOException?> {
             inBackground {
                 try {
-                    val ios = ImageIO.createImageOutputStream(file)
+                    /* xxx - ImageIO bug? */
+                    val devNull = java.io.PrintStream(NullOutputStream())
+                    val oldOut = System.out
+                    System.setOut(devNull)
+                    val oldErr = System.err
+                    System.setErr(devNull)
+                    val ios = try {
+                        ImageIO.createImageOutputStream(file)
+                    } finally {
+                        System.setErr(oldErr)
+                        System.setOut(oldOut)
+                    }
+                    if (ios == null)
+                        throw IOException()
+                    /* xxx - end workaround */
                     val writer = ImageIO.getImageWritersByFormatName("jpeg").next()
                     val iwp = writer.getDefaultWriteParam().apply {
                         setCompressionMode(ImageWriteParam.MODE_EXPLICIT)