Search in sources :

Example 1 with NestedException

use of org.fagu.fmv.soft.exec.exception.NestedException in project fmv by f-agu.

the class GSExceptionKnowAnalyzeTestCase method runPdfToImage.

// *************************************
/**
 * @param srcResource
 * @param expectedMessage
 * @param consumer
 * @throws IOException
 */
private void runPdfToImage(String srcResource, String expectedMessage, Consumer<SoftExecutor> consumer) throws IOException {
    File folder = new File(System.getProperty("java.io.tmpdir"), "gs-pdf2img-test");
    try {
        FileUtils.deleteDirectory(folder);
        folder.mkdirs();
        File srcFile = srcResource != null ? Resource.extract(folder, srcResource) : folder;
        File outFile = new File(srcFile.getPath() + ".jpg");
        try {
            Soft gsSoft = GS.search();
            List<String> list = new ArrayList<>();
            list.add("-sDEVICE=png16m");
            list.add("-sOutputFile=" + outFile.getPath());
            list.add("-r200");
            list.add("-dNOPAUSE");
            list.add("-dBATCH");
            list.add("-dSAFER");
            list.add("-dFirstPage=1");
            list.add("-dLastPage=1");
            list.add("-dUseCropBox");
            list.add(srcFile.getAbsolutePath());
            SoftExecutor customizeExecutor = gsSoft.withParameters(list).workingDirectory(srcFile.getParentFile());
            // .logCommandLine(System.out::println);
            if (consumer != null) {
                consumer.accept(customizeExecutor);
            }
            customizeExecutor.execute();
            fail();
        } catch (FMVExecuteException e) {
            if (e.isKnown()) {
                assertEquals(expectedMessage, e.getExceptionKnown().toString());
            } else {
                new NestedException(e).messageToLines().forEach(System.out::println);
                throw e;
            }
        }
    } finally {
        FileUtils.deleteDirectory(folder);
    }
}
Also used : FMVExecuteException(org.fagu.fmv.soft.exec.exception.FMVExecuteException) ArrayList(java.util.ArrayList) SoftExecutor(org.fagu.fmv.soft.SoftExecutor) NestedException(org.fagu.fmv.soft.exec.exception.NestedException) File(java.io.File) Soft(org.fagu.fmv.soft.Soft)

Example 2 with NestedException

use of org.fagu.fmv.soft.exec.exception.NestedException in project fmv by f-agu.

the class NoOverwriteDeblock method accept.

@Override
public void accept(ExceptionKnown exceptionKnown) throws IOException {
    NestedException nestedException = exceptionKnown.getNestedException();
    String lastLine = getLineIfBlocked(nestedException);
    if (lastLine != null) {
        throw new ProcessBlockedException(lastLine);
    }
    throw nestedException.getIOException();
}
Also used : ProcessBlockedException(org.fagu.fmv.soft.exec.exception.ProcessBlockedException) NestedException(org.fagu.fmv.soft.exec.exception.NestedException)

Aggregations

NestedException (org.fagu.fmv.soft.exec.exception.NestedException)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Soft (org.fagu.fmv.soft.Soft)1 SoftExecutor (org.fagu.fmv.soft.SoftExecutor)1 FMVExecuteException (org.fagu.fmv.soft.exec.exception.FMVExecuteException)1 ProcessBlockedException (org.fagu.fmv.soft.exec.exception.ProcessBlockedException)1