Skip to content

Commit

Permalink
add result class to extend ExecResult and set the body
Browse files Browse the repository at this point in the history
  • Loading branch information
krwong committed Dec 11, 2024
1 parent ed82646 commit 6fad926
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package edu.unc.lib.boxc.services.camel.images;

import JP2ImageConverter.CLIMain;
import JP2ImageConverter.JP2ImageConverterCommand;
import JP2ImageConverter.options.JP2ImageConverterOptions;
import edu.unc.lib.boxc.services.camel.util.CdrFcrepoHeaders;
import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.component.exec.ExecCommand;
import org.apache.camel.component.exec.ExecResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.nio.file.Path;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;

/**
* Processor that runs jp24u to generate jp2 derivatives
Expand All @@ -29,6 +32,19 @@ public void process(Exchange exchange) throws Exception {
String[] command = new String[]{"jp24u", "kdu_compress", "-f", imagePath,
"-o", tempPath, "-sf", mimetype};
log.debug("Run jp24u command {} for type {}", command, mimetype);
CLIMain.runCommand(command);
int exitCode = CLIMain.runCommand(command);

Result result = new Result(new ByteArrayInputStream(tempPath.getBytes()), null, exitCode);
in.setBody(result);
}

public static class Result extends ExecResult {
private static final ExecCommand command = new ExecCommand("jp24u",
Arrays.asList("kdu_compress"), null, Long.valueOf(60), null,
null, null, false, LoggingLevel.OFF);

public Result(InputStream stdout, InputStream stderr, int exitCode) {
super(command, stdout, stderr, exitCode);
}
}
}

0 comments on commit 6fad926

Please sign in to comment.