From bbb0b7bb146c3be677bd9af4d6f919428d699130 Mon Sep 17 00:00:00 2001 From: h-thurow Date: Thu, 7 Dec 2023 15:20:21 +0100 Subject: [PATCH 1/2] With IM7 identify and other "commands" are symbolic links to magick. With cmd.getCanonicalPath() all these links are resolved to "magick" what makes the "commands" fail. --- pom.xml | 4 ++-- .../geko444/im4java/process/ProcessStarter.java | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 6458133..e8b4d35 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,8 @@ http://maven.apache.org/maven-v4_0_0.xsd"> UTF-8 - 1.6 - 1.6 + 1.8 + 1.8 im4java diff --git a/src/main/java/com/github/geko444/im4java/process/ProcessStarter.java b/src/main/java/com/github/geko444/im4java/process/ProcessStarter.java index 9f96a45..7bfb089 100644 --- a/src/main/java/com/github/geko444/im4java/process/ProcessStarter.java +++ b/src/main/java/com/github/geko444/im4java/process/ProcessStarter.java @@ -21,18 +21,14 @@ package com.github.geko444.im4java.process; -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.File; -import java.io.FileNotFoundException; +import java.io.*; +import java.nio.file.LinkOption; +import java.nio.file.Paths; import java.util.LinkedList; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; +import java.util.concurrent.atomic.AtomicInteger; /** This class implements the processing of os-commands using a @@ -654,7 +650,7 @@ public String searchForCmd(String pCmd, String pPath) } else { File cmd = new File(dirs[i],pCmd); if (cmd.exists()) { - return cmd.getCanonicalPath(); + return Paths.get(cmd.getPath()).toRealPath(LinkOption.NOFOLLOW_LINKS).toString(); } } } From e8df01d13756519eae0af8f76966794632b051a1 Mon Sep 17 00:00:00 2001 From: h-thurow Date: Thu, 7 Dec 2023 18:28:43 +0100 Subject: [PATCH 2/2] Im IM7 first line of cmdOutput is "Image:", not "Image: fileName.extension". That resulted in all subsequent attributes prefixed with "Image:". --- .../com/github/geko444/im4java/core/Info.java | 98 ++++++++++--------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/github/geko444/im4java/core/Info.java b/src/main/java/com/github/geko444/im4java/core/Info.java index 6e9ad6f..bac3db4 100644 --- a/src/main/java/com/github/geko444/im4java/core/Info.java +++ b/src/main/java/com/github/geko444/im4java/core/Info.java @@ -22,12 +22,12 @@ package com.github.geko444.im4java.core; -import java.util.*; -import java.io.*; - import com.github.geko444.im4java.process.ArrayListOutputConsumer; import com.github.geko444.im4java.process.Pipe; +import java.io.InputStream; +import java.util.*; + /** This class implements an image-information object. The one-argument constructor expects a filename and parses the output of the @@ -200,39 +200,39 @@ private void getCompleteInfo(String pImage, InputStream pInput) ArrayListOutputConsumer output = new ArrayListOutputConsumer(); identify.setOutputConsumer(output); if (pInput != null) { - Pipe inputPipe = new Pipe(pInput,null); - identify.setInputProvider(inputPipe); + Pipe inputPipe = new Pipe(pInput, null); + identify.setInputProvider(inputPipe); } identify.run(op); ArrayList cmdOutput = output.getOutput(); StringBuilder lineAccu = new StringBuilder(80); - for (String line:cmdOutput) { - if (line.length() == 0) { - // accumulate empty line as part of current attribute - lineAccu.append("\n\n"); - } else if (line.indexOf(':') == -1) { - // interpret this as a continuation-line of the current attribute - lineAccu.append("\n").append(line); - } else if (lineAccu.length() > 0) { - // new attribute, process old attribute first - parseLine(lineAccu.toString()); - lineAccu = new StringBuilder(80); - lineAccu.append(line); - } else { + for (String line : cmdOutput) { + if (line.length() == 0) { + // accumulate empty line as part of current attribute + lineAccu.append("\n\n"); + } else if (line.indexOf(':') == -1) { + // interpret this as a continuation-line of the current attribute + lineAccu.append("\n").append(line); + } else if (lineAccu.length() > 0) { + // new attribute, process old attribute first + parseLine(lineAccu.toString()); + lineAccu = new StringBuilder(80); + lineAccu.append(line); + } else { // new attribute, but nothing old to process - lineAccu.append(line); - } + lineAccu.append(line); + } } // process last item if (lineAccu.length() > 0) { - parseLine(lineAccu.toString()); + parseLine(lineAccu.toString()); } // finish and add last hashtable to linked-list addBaseInfo(); iAttribList.add(iAttributes); - + } catch (Exception ex) { throw new InfoException(ex); } @@ -277,38 +277,40 @@ private void parseLine(String pLine) { if (pLine.startsWith("Image:")) { // start of a new scene if (iAttributes != null) { - addBaseInfo(); - iAttribList.add(iAttributes); + addBaseInfo(); + iAttribList.add(iAttributes); } - iAttributes = new Hashtable(); + iAttributes = new Hashtable(); } - int indent = pLine.indexOf(pLine.trim())/2; - - String[] parts = pLine.trim().split(": ",2); - - // check indentation level and remove prefix if necessary - if (indent < iOldIndent) { - // remove tokens from iPrefix - int colonIndex=iPrefix.length()-1; - for (int i=0;i add attribute to attribute-prefix + iPrefix = iPrefix + parts[0]; } else { - iPrefix=iPrefix.substring(0,colonIndex+1); + // value => add (key,value) to attributes + iAttributes.put(iPrefix + parts[0], parts[1]); } } - iOldIndent = indent; - - // add a new attribute or increase prefix - if (parts.length == 1) { - // no value => add attribute to attribute-prefix - iPrefix=iPrefix+parts[0]; - } else { - // value => add (key,value) to attributes - iAttributes.put(iPrefix+parts[0],parts[1]); - } } //////////////////////////////////////////////////////////////////////////////