From 9596adc0ca5b226e7682fc785f707d3fd1b2978e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 16 Mar 2013 01:12:38 +0100 Subject: [PATCH] Retrieve binary and parameters from subclass. --- .../sonitus/data/filter/ExternalFilter.java | 43 ++++++++++++---------- .../sonitus/data/filter/ExternalMp3Decoder.java | 14 +------ .../sonitus/data/filter/LameMp3Decoder.java | 29 +++++++++------ 3 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java index ff838d9..c3ab508 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java @@ -48,31 +48,12 @@ public abstract class ExternalFilter implements Filter { /** 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 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 parameters) { - this.binary = binary; - this.parameters = parameters; - } - // // FILTER METHODS @@ -94,7 +75,7 @@ public abstract class ExternalFilter implements Filter { format = source.format(); try { - Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.builder().add(binary).addAll(parameters).build(), String.class)); + final Process process = Runtime.getRuntime().exec(Iterables.toArray(ImmutableList.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(); @@ -142,6 +123,28 @@ public abstract class ExternalFilter implements Filter { } // + // 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 parameters(Format format); + + // // STATIC METHODS // diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java index ecdee68..88afa30 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java @@ -29,19 +29,7 @@ import net.pterodactylus.sonitus.data.Source; * * @author David ‘Bombe’ Roden */ -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 parameters) { - super(binary, parameters); - } +public abstract class ExternalMp3Decoder extends ExternalFilter { @Override public Format format() { diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java index d824041..aae01fe 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java @@ -17,6 +17,8 @@ package net.pterodactylus.sonitus.data.filter; +import net.pterodactylus.sonitus.data.Format; + import com.google.common.collect.ImmutableList; /** @@ -26,6 +28,12 @@ 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. * @@ -36,22 +44,21 @@ public class LameMp3Decoder extends ExternalMp3Decoder { * 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 generateParameters(boolean swapBytes) { + @Override + protected String binary(Format format) { + return binary; + } + + @Override + protected Iterable parameters(Format format) { ImmutableList.Builder parameters = ImmutableList.builder(); parameters.add("--mp3input").add("--decode").add("-t"); if (swapBytes) { -- 2.7.4