Search in sources :

Example 1 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class PipeInOutTest method testPipeOut.

/**
 * @throws Exception
 */
@Test
public void testPipeOut() throws Exception {
    File srcFile = ImageResourceUtils.extractFile("bad-ass-tattoo-fail.jpg");
    File destFile = new File(srcFile.getPath() + ".piped." + FilenameUtils.getExtension(srcFile.getName()));
    try {
        Soft convertSoft = Convert.search();
        IMOperation op = new IMOperation();
        op.image(srcFile).autoOrient().quality(60D).image(// <-------- means standard output
        "jpg:-");
        try (OutputStream outputStream = new FileOutputStream(destFile)) {
            convertSoft.withParameters(op.toList()).output(// <--------- out
            outputStream).execute();
        }
        assertEquals(EXPECTED_SHA1, sha1Of(destFile));
    } finally {
        srcFile.delete();
        destFile.delete();
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Soft(org.fagu.fmv.soft.Soft) Test(org.junit.Test)

Example 2 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class PipeInOutTest method testPipeInOut.

/**
 * @throws Exception
 */
@Test
public void testPipeInOut() throws Exception {
    File srcFile = ImageResourceUtils.extractFile("bad-ass-tattoo-fail.jpg");
    File destFile = new File(srcFile.getPath() + ".piped." + FilenameUtils.getExtension(srcFile.getName()));
    try {
        Soft convertSoft = Convert.search();
        IMOperation op = new IMOperation();
        // <-------- means standard input
        op.image("-").autoOrient().quality(60D).image(// <-------- means standard output
        "jpg:-");
        try (InputStream inputStream = new FileInputStream(srcFile);
            OutputStream outputStream = new FileOutputStream(destFile)) {
            convertSoft.withParameters(op.toList()).input(// <--------- in
            inputStream).output(// <--------- out
            outputStream).execute();
        }
        assertEquals(EXPECTED_SHA1, sha1Of(destFile));
    } finally {
        srcFile.delete();
        destFile.delete();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Soft(org.fagu.fmv.soft.Soft) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 3 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class ConvertSoftProviderTestCase method test.

@Test
@Ignore
public void test() {
    Soft soft = Convert.search();
    for (SoftFound softFound : soft.getFounds()) {
        System.out.println(softFound.getLocalizedBy());
        System.out.println(softFound + " / " + softFound.getReason());
        System.out.println();
    }
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) Soft(org.fagu.fmv.soft.Soft) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Soft

use of org.fagu.fmv.soft.Soft 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 5 with Soft

use of org.fagu.fmv.soft.Soft in project fmv by f-agu.

the class JavaSoftProviderTestCase method testFind.

/**
 */
@Test
@Ignore
public void testFind() {
    Soft java = Java.search();
    for (SoftFound softFound : java.getFounds()) {
        System.out.println(softFound);
    }
    System.out.println();
    System.out.println(java);
}
Also used : SoftFound(org.fagu.fmv.soft.find.SoftFound) Soft(org.fagu.fmv.soft.Soft) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Soft (org.fagu.fmv.soft.Soft)12 File (java.io.File)8 Test (org.junit.Test)7 SoftFound (org.fagu.fmv.soft.find.SoftFound)4 FMVExecuteException (org.fagu.fmv.soft.exec.exception.FMVExecuteException)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 StringJoiner (java.util.StringJoiner)2 Ignore (org.junit.Ignore)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 FileUtils (org.apache.commons.io.FileUtils)1 IMOperation (org.fagu.fmv.im.IMOperation)1 Convert (org.fagu.fmv.im.soft.Convert)1 Logger (org.fagu.fmv.mymedia.logger.Logger)1 Loggers (org.fagu.fmv.mymedia.logger.Loggers)1