/** The logger. */
private static final Logger logger = Logger.getLogger(ExternalFilter.class.getName());
- /** The binary to execute. */
- private final String binary;
-
- /** The parameters for the binary. */
- private final Iterable<String> parameters;
-
/** The format of the source. */
private Format format;
/** The input stream that will hold the converted source. */
private PipedInputStream pipedInputStream;
- /**
- * Creates a new external filter.
- *
- * @param binary
- * The binary to execute
- * @param parameters
- * The parameter for the binary
- */
- public ExternalFilter(String binary, Iterable<String> parameters) {
- this.binary = binary;
- this.parameters = parameters;
- }
-
//
// FILTER METHODS
format = source.format();
try {
- Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.<String>builder().add(binary).addAll(parameters).build(), String.class));
+ final Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.<String>builder().add(binary(format)).addAll(parameters(format)).build(), String.class));
final InputStream processOutput = process.getInputStream();
final OutputStream processInput = process.getOutputStream();
final InputStream processError = process.getErrorStream();
}
//
+ // SUBCLASS METHODS
+ //
+
+ /**
+ * Returns the location of the binary to execute.
+ *
+ * @param format
+ * The format being processed
+ * @return The location of the binary to execute
+ */
+ protected abstract String binary(Format format);
+
+ /**
+ * Returns the parameters for the binary.
+ *
+ * @param format
+ * The format being processed
+ * @return The parameters for the binary
+ */
+ protected abstract Iterable<String> parameters(Format format);
+
+ //
// STATIC METHODS
//
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public class ExternalMp3Decoder extends ExternalFilter {
-
- /**
- * Creates a new external MP3 decoder.
- *
- * @param binary
- * The binary to execute
- * @param parameters
- * The parameters for the binary
- */
- public ExternalMp3Decoder(String binary, Iterable<String> parameters) {
- super(binary, parameters);
- }
+public abstract class ExternalMp3Decoder extends ExternalFilter {
@Override
public Format format() {
package net.pterodactylus.sonitus.data.filter;
+import net.pterodactylus.sonitus.data.Format;
+
import com.google.common.collect.ImmutableList;
/**
*/
public class LameMp3Decoder extends ExternalMp3Decoder {
+ /** The location of the binary. */
+ private final String binary;
+
+ /** Whether to swap bytes in the decoded output. */
+ private final boolean swapBytes;
+
/**
* Creates a new LAME MP3 decoder.
*
* endianness
*/
public LameMp3Decoder(String binary, boolean swapBytes) {
- super(binary, generateParameters(swapBytes));
+ this.binary = binary;
+ this.swapBytes = swapBytes;
}
//
- // STATIC METHODS
+ // EXTERNALFILTER METHODS
//
- /**
- * Generates the parameters for LAME.
- *
- * @param swapBytes
- * {@code true} to swap the decoded bytes, {@code false} to use platform
- * endianness
- * @return The parameters for LAME
- */
- private static Iterable<String> generateParameters(boolean swapBytes) {
+ @Override
+ protected String binary(Format format) {
+ return binary;
+ }
+
+ @Override
+ protected Iterable<String> parameters(Format format) {
ImmutableList.Builder parameters = ImmutableList.builder();
parameters.add("--mp3input").add("--decode").add("-t");
if (swapBytes) {