Compare commits
2 Commits
main
...
ghostscrip
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
429e071408 | ||
|
|
cd3cc63291 |
@ -80,7 +80,7 @@ public class GhostScriptOutputHandler extends Thread {
|
||||
if (type.equals(Type.ERROR)) {
|
||||
log.error("{}_{}>{}", processName, type.name(), line);
|
||||
} else {
|
||||
log.debug("{}_{}>{}", processName, type.name(), line);
|
||||
log.info("{}_{}>{}", processName, type.name(), line);
|
||||
addProcessedImageToQueue(line);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -15,14 +16,12 @@ import com.knecon.fforesight.service.ocr.processor.model.ImageFile;
|
||||
import com.knecon.fforesight.service.ocr.processor.model.PageBatch;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
||||
@SuppressWarnings("PMD") // can't figure out how to safely close the stdOut and stdError streams in line 72/74
|
||||
public class GhostScriptService {
|
||||
@ -34,6 +33,37 @@ public class GhostScriptService {
|
||||
private Semaphore concurrencySemaphore = new Semaphore(3);
|
||||
|
||||
|
||||
public GhostScriptService(OcrServiceSettings ocrServiceSettings) {
|
||||
|
||||
this.ocrServiceSettings = ocrServiceSettings;
|
||||
assertGhostscriptIsInstalled();
|
||||
}
|
||||
|
||||
|
||||
private void assertGhostscriptIsInstalled() {
|
||||
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec("gs -v");
|
||||
InputStream stdOut = p.getInputStream();
|
||||
InputStream errOut = p.getErrorStream();
|
||||
assert p.waitFor(1, TimeUnit.SECONDS);
|
||||
log.info("Ghostscript is installed.");
|
||||
String out = new String(stdOut.readAllBytes());
|
||||
String error = new String(errOut.readAllBytes());
|
||||
for (String line : out.split("\n")) {
|
||||
log.info(line);
|
||||
}
|
||||
if (!error.isBlank()) {
|
||||
log.error(error);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Ghostscript is not installed!");
|
||||
log.error(e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SneakyThrows
|
||||
public void startBatchRender(PageBatch batch, ImageProcessingSupervisor supervisor, Consumer<ImageFile> successHandler, Consumer<String> errorHandler) {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user