From 70ea21939e6071954eeb05f2a42e7a92a02013f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 4 Jun 2013 06:44:00 +0200 Subject: [PATCH] Rename dummy filter to basic filter. --- .../sonitus/data/filter/AudioProcessingFilter.java | 4 +- .../sonitus/data/filter/BasicFilter.java | 136 +++++++++++++++++++++ .../sonitus/data/filter/DummyFilter.java | 136 --------------------- .../sonitus/data/filter/ExternalFilter.java | 4 +- .../sonitus/data/filter/PredicateFilter.java | 2 +- .../sonitus/data/filter/RateLimitingFilter.java | 2 +- .../sonitus/data/filter/TimeCounterFilter.java | 4 +- 7 files changed, 144 insertions(+), 144 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sonitus/data/filter/BasicFilter.java delete mode 100644 src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java index e87935b..7312f7f 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java @@ -28,7 +28,7 @@ import net.pterodactylus.sonitus.io.ProcessingOutputStream; * * @author David ‘Bombe’ Roden */ -public abstract class AudioProcessingFilter extends DummyFilter { +public abstract class AudioProcessingFilter extends BasicFilter { /** * Creates a new audio processing filter with the given name. @@ -41,7 +41,7 @@ public abstract class AudioProcessingFilter extends DummyFilter { } // - // DUMMYFILTER METHODS + // BASICFILTER METHODS // @Override diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/BasicFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/BasicFilter.java new file mode 100644 index 0000000..0f248d6 --- /dev/null +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/BasicFilter.java @@ -0,0 +1,136 @@ +/* + * Sonitus - AbstractFilter.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sonitus.data.filter; + +import java.io.EOFException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import net.pterodactylus.sonitus.data.AbstractControlledComponent; +import net.pterodactylus.sonitus.data.Controller; +import net.pterodactylus.sonitus.data.Filter; +import net.pterodactylus.sonitus.data.Metadata; + +import com.google.common.io.Closeables; + +/** + * Basic {@link Filter} implementation that pipes its input to its output. + * + * @author David ‘Bombe’ Roden + */ +public class BasicFilter extends AbstractControlledComponent implements Filter { + + /** The input stream from which to read. */ + private InputStream inputStream; + + /** The output stream to which to write. */ + private OutputStream outputStream; + + /** + * Creates a new dummy filter with the given name. + * + * @param name + * The name of the filter + */ + public BasicFilter(String name) { + super(name); + } + + // + // CONTROLLED METHODS + // + + @Override + public List> controllers() { + return Collections.emptyList(); + } + + // + // FILTER METHODS + // + + @Override + public void open(Metadata metadata) throws IOException { + metadataUpdated(metadata); + inputStream = createInputStream(); + outputStream = createOutputStream(); + } + + @Override + public void close() { + try { + Closeables.close(outputStream, true); + Closeables.close(inputStream, true); + } catch (IOException e) { + /* won’t throw. */ + } + } + + @Override + public void process(byte[] buffer) throws IOException { + outputStream.write(buffer); + outputStream.flush(); + } + + @Override + public byte[] get(int bufferSize) throws IOException { + byte[] buffer = new byte[bufferSize]; + int read = inputStream.read(buffer); + if (read == -1) { + throw new EOFException(); + } + return Arrays.copyOf(buffer, read); + } + + // + // SUBCLASS METHODS + // + + /** + * Creates the input stream from which {@link net.pterodactylus.sonitus.data.Pipeline} + * will read the audio data. If you override this, you have to override {@link + * #createOutputStream()}, too! + * + * @return The input stream to read from + * @throws IOException + * if an I/O error occurs + */ + protected InputStream createInputStream() throws IOException { + return new PipedInputStream(); + } + + /** + * Creates the output stream to which {@link net.pterodactylus.sonitus.data.Pipeline} + * will write the audio data. If you override this, you have to override {@link + * #createInputStream()}, too! + * + * @return The output stream to write to + * @throws IOException + * if an I/O error occurs + */ + protected OutputStream createOutputStream() throws IOException { + return new PipedOutputStream((PipedInputStream) inputStream); + } + +} diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java deleted file mode 100644 index ae6899d..0000000 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Sonitus - AbstractFilter.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sonitus.data.filter; - -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import net.pterodactylus.sonitus.data.AbstractControlledComponent; -import net.pterodactylus.sonitus.data.Controller; -import net.pterodactylus.sonitus.data.Filter; -import net.pterodactylus.sonitus.data.Metadata; - -import com.google.common.io.Closeables; - -/** - * Dummy {@link Filter} implementation that pipes its input to its output. - * - * @author David ‘Bombe’ Roden - */ -public class DummyFilter extends AbstractControlledComponent implements Filter { - - /** The input stream from which to read. */ - private InputStream inputStream; - - /** The output stream to which to write. */ - private OutputStream outputStream; - - /** - * Creates a new dummy filter with the given name. - * - * @param name - * The name of the filter - */ - public DummyFilter(String name) { - super(name); - } - - // - // CONTROLLED METHODS - // - - @Override - public List> controllers() { - return Collections.emptyList(); - } - - // - // FILTER METHODS - // - - @Override - public void open(Metadata metadata) throws IOException { - metadataUpdated(metadata); - inputStream = createInputStream(); - outputStream = createOutputStream(); - } - - @Override - public void close() { - try { - Closeables.close(outputStream, true); - Closeables.close(inputStream, true); - } catch (IOException e) { - /* won’t throw. */ - } - } - - @Override - public void process(byte[] buffer) throws IOException { - outputStream.write(buffer); - outputStream.flush(); - } - - @Override - public byte[] get(int bufferSize) throws IOException { - byte[] buffer = new byte[bufferSize]; - int read = inputStream.read(buffer); - if (read == -1) { - throw new EOFException(); - } - return Arrays.copyOf(buffer, read); - } - - // - // SUBCLASS METHODS - // - - /** - * Creates the input stream from which {@link net.pterodactylus.sonitus.data.Pipeline} - * will read the audio data. If you override this, you have to override {@link - * #createOutputStream()}, too! - * - * @return The input stream to read from - * @throws IOException - * if an I/O error occurs - */ - protected InputStream createInputStream() throws IOException { - return new PipedInputStream(); - } - - /** - * Creates the output stream to which {@link net.pterodactylus.sonitus.data.Pipeline} - * will write the audio data. If you override this, you have to override {@link - * #createInputStream()}, too! - * - * @return The output stream to write to - * @throws IOException - * if an I/O error occurs - */ - protected OutputStream createOutputStream() throws IOException { - return new PipedOutputStream((PipedInputStream) inputStream); - } - -} 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 990f976..73338b5 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java @@ -34,7 +34,7 @@ import com.google.common.collect.Iterables; * * @author David ‘Bombe’ Roden */ -public abstract class ExternalFilter extends DummyFilter { +public abstract class ExternalFilter extends BasicFilter { /** The logger. */ private final Logger logger = Logger.getLogger(getClass().getName()); @@ -70,7 +70,7 @@ public abstract class ExternalFilter extends DummyFilter { } // - // DUMMYFILTER METHODS + // BASICFILTER METHODS // @Override diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java index b400dc7..8968596 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java @@ -33,7 +33,7 @@ import com.google.common.base.Predicate; * * @author David ‘Bombe’ Roden */ -public class PredicateFilter extends DummyFilter { +public class PredicateFilter extends BasicFilter { /** The predicate. */ private final Predicate metadataPredicate; diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java index b2890ca..881deeb 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java @@ -29,7 +29,7 @@ import net.pterodactylus.sonitus.data.Metadata; * * @author David ‘Bombe’ Roden */ -public class RateLimitingFilter extends DummyFilter { +public class RateLimitingFilter extends BasicFilter { /** The logger. */ private static final Logger logger = Logger.getLogger(RateLimitingFilter.class.getName()); diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java index 1c53d55..cfa93af 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java @@ -31,7 +31,7 @@ import net.pterodactylus.sonitus.data.Metadata; * * @author David ‘Bombe’ Roden */ -public class TimeCounterFilter extends DummyFilter { +public class TimeCounterFilter extends BasicFilter { /** The byte counter. */ private final AtomicLong counter = new AtomicLong(); @@ -95,7 +95,7 @@ public class TimeCounterFilter extends DummyFilter { } // - // DUMMYFILTER METHODS + // BASICFILTER METHODS // @Override -- 2.7.4