/*
* Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright (C) 2012 -- 2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
*
* This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public License
- * as published by the Free Software Foundation.
- */
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+*/
package eu.svjatoslav.meviz.encoder;
-import java.io.File;
-
import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
-public class EncodingTask {
-
- /**
- * Source file to encode
- */
- private final File source;
-
- /**
- * Target file.
- */
- private final File target;
-
- private final AbstractConverter converter;
-
- private boolean useTerminal;
-
- private final String targetFormat;
-
- public EncodingTask(final File source, final File target, final AbstractConverter converter,
- final String targetFormat) {
-
- this.source = source;
- this.target = target;
- this.converter = converter;
- this.targetFormat = targetFormat;
- }
-
- /**
- * @return the useTerminal
- */
- public boolean doUseTerminal() {
- return useTerminal;
- }
-
- public String encodeApostrophes(final String input) {
- final StringBuffer result = new StringBuffer();
-
- for (final char c : input.toCharArray()) {
- if (c == '\'') {
- result.append("'\\''");
- continue;
- }
- result.append(c);
- }
-
- return result.toString();
- }
-
- public void execute(final EncodingOptions encodingOptions) {
- try {
- String command = getCommand(encodingOptions);
-
- if (doUseTerminal())
- command = "xterm -e '" + encodeApostrophes(command) + "'";
-
- System.out.println("Executing command: " + command);
-
- final Runtime runtime = Runtime.getRuntime();
- final Process process = runtime.exec(new String[] { "/bin/bash", "-c", command });
-
- process.waitFor();
-
- } catch (final Exception e) {
- System.out.println(e.toString());
- e.printStackTrace();
- }
-
- }
+import java.io.File;
- public String getCommand(final EncodingOptions encodingOptions) {
- return converter.getCommand(source, target, encodingOptions, targetFormat);
- }
+public class EncodingTask {
- /**
- * @param useTerminal
- * the useTerminal to set
- */
- public void setUseTerminal(final boolean useTerminal) {
- this.useTerminal = useTerminal;
- }
+ /**
+ * Source file to encode
+ */
+ private final File source;
+
+ /**
+ * Target file.
+ */
+ private final File target;
+
+ private final AbstractConverter converter;
+ private final String targetFormat;
+ private boolean useTerminal;
+
+ public EncodingTask(final File source, final File target, final AbstractConverter converter,
+ final String targetFormat) {
+
+ this.source = source;
+ this.target = target;
+ this.converter = converter;
+ this.targetFormat = targetFormat;
+ }
+
+ /**
+ * @return the useTerminal
+ */
+ private boolean doUseTerminal() {
+ return useTerminal;
+ }
+
+ private String encodeApostrophes(final String input) {
+ final StringBuilder result = new StringBuilder();
+
+ for (final char c : input.toCharArray()) {
+ if (c == '\'') {
+ result.append("'\\''");
+ continue;
+ }
+ result.append(c);
+ }
+
+ return result.toString();
+ }
+
+ public void execute(final EncodingOptions encodingOptions) {
+ try {
+ String command = getCommand(encodingOptions);
+
+ if (doUseTerminal())
+ command = "xterm -e '" + encodeApostrophes(command) + "'";
+
+ System.out.println("Executing command: " + command);
+
+ final Runtime runtime = Runtime.getRuntime();
+ final Process process = runtime.exec(new String[]{"/bin/bash", "-c", command});
+
+ process.waitFor();
+
+ } catch (final Exception e) {
+ System.out.println(e.toString());
+ e.printStackTrace();
+ }
+
+ }
+
+ private String getCommand(final EncodingOptions encodingOptions) {
+ return converter.getCommand(source, target, encodingOptions, targetFormat);
+ }
+
+ /**
+ * @param useTerminal the useTerminal to set
+ */
+ public void setUseTerminal(final boolean useTerminal) {
+ this.useTerminal = useTerminal;
+ }
}