Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ http://maven.apache.org/maven-v4_0_0.xsd">

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<name>im4java</name>
Expand Down
98 changes: 50 additions & 48 deletions src/main/java/com/github/geko444/im4java/core/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> 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);
}
Expand Down Expand Up @@ -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<String,String>();
iAttributes = new Hashtable<String, String>();
}
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<iOldIndent-indent;++i) {
colonIndex = iPrefix.lastIndexOf(':',colonIndex-1);
if (!pLine.trim().equals("Image:")) {
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 < iOldIndent - indent;++i) {
colonIndex = iPrefix.lastIndexOf(':', colonIndex - 1);
}
if (colonIndex == -1) {
iPrefix = "";
} else {
iPrefix = iPrefix.substring(0, colonIndex + 1);
}
}
if (colonIndex == -1) {
iPrefix="";
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 {
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]);
}
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}
}
Expand Down