2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.meviz.encoder;
14 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
16 public class EncodingTask {
19 * Source file to encode
21 private final File source;
26 private final File target;
28 private final AbstractConverter converter;
30 private boolean useTerminal;
32 private final String targetFormat;
34 public EncodingTask(final File source, final File target, final AbstractConverter converter,
35 final String targetFormat) {
39 this.converter = converter;
40 this.targetFormat = targetFormat;
44 * @return the useTerminal
46 public boolean doUseTerminal() {
50 public String encodeApostrophes(final String input) {
51 final StringBuffer result = new StringBuffer();
53 for (final char c : input.toCharArray()) {
55 result.append("'\\''");
61 return result.toString();
64 public void execute(final EncodingOptions encodingOptions) {
66 String command = getCommand(encodingOptions);
69 command = "xterm -e '" + encodeApostrophes(command) + "'";
71 System.out.println("Executing command: " + command);
73 final Runtime runtime = Runtime.getRuntime();
74 final Process process = runtime.exec(new String[] { "/bin/bash", "-c", command });
78 } catch (final Exception e) {
79 System.out.println(e.toString());
85 public String getCommand(final EncodingOptions encodingOptions) {
86 return converter.getCommand(source, target, encodingOptions, targetFormat);
91 * the useTerminal to set
93 public void setUseTerminal(final boolean useTerminal) {
94 this.useTerminal = useTerminal;