Updated copyright message.
[meviz.git] / src / main / java / eu / svjatoslav / meviz / encoder / EncodingTask.java
index 816fba7..ae7e8a0 100755 (executable)
@@ -1,6 +1,6 @@
 /*
  * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright (C) 2012 -- 2018, 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
@@ -9,93 +9,85 @@
 
 package eu.svjatoslav.meviz.encoder;
 
-import java.io.File;
-
 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
 
+import java.io.File;
+
 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 String targetFormat;
-
-       public EncodingTask(
-                       final File source,
-                       final File destination,
-                       final eu.svjatoslav.meviz.encoder.converters.AbstractConverter converter,
-                       String targetFormat) {
-
-               this.source = source;
-               target = destination;
-               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 run = Runtime.getRuntime();
-                       Process pr;
-                       pr = run.exec(new String[] { "/bin/bash", "-c", command });
-
-                       pr.waitFor();
-
-               } catch (final Exception e) {
-                       System.out.println(e.toString());
-                       e.printStackTrace();
-               }
-
-       }
-
-       public 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;
-       }
+    /**
+     * 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;
+    }
 }