Pull all interfaces into a single interface: Filter.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / sink / FileSink.java
index 48476b3..5011321 100644 (file)
@@ -19,16 +19,10 @@ package net.pterodactylus.sonitus.data.sink;
 
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
 import java.util.logging.Logger;
 
-import net.pterodactylus.sonitus.data.Controller;
+import net.pterodactylus.sonitus.data.AbstractFilter;
 import net.pterodactylus.sonitus.data.Metadata;
-import net.pterodactylus.sonitus.data.Sink;
-import net.pterodactylus.sonitus.data.event.MetadataUpdated;
-
-import com.google.common.eventbus.EventBus;
 
 /**
  * {@link net.pterodactylus.sonitus.data.Sink} that writes all received data
@@ -36,57 +30,30 @@ import com.google.common.eventbus.EventBus;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class FileSink implements Sink {
+public class FileSink extends AbstractFilter {
 
        /** The logger. */
        private static final Logger logger = Logger.getLogger(FileSink.class.getName());
 
-       /** The event bus. */
-       private final EventBus eventBus;
-
        /** The path of the file to write to. */
        private final String path;
 
        /** The output stream writing to the file. */
        private FileOutputStream fileOutputStream;
 
-       /** The current metadata. */
-       private Metadata metadata;
-
        /**
         * Creates a new file sink that will write to the given path.
         *
-        * @param eventBus
-        *              The event bus
         * @param path
         *              The path of the file to write to
         */
-       public FileSink(EventBus eventBus, String path) {
-               this.eventBus = eventBus;
+       public FileSink(String path) {
+               super(path);
                this.path = path;
        }
 
        //
-       // CONTROLLED METHODS
-       //
-
-       @Override
-       public String name() {
-               return path;
-       }
-
-       @Override
-       public Metadata metadata() {
-               return metadata;
-       }
-
-       @Override
-       public List<Controller<?>> controllers() {
-               return Collections.emptyList();
-       }
-
-       //
-       // SINK METHODS
+       // FILTER METHODS
        //
 
        @Override
@@ -105,12 +72,6 @@ public class FileSink implements Sink {
        }
 
        @Override
-       public void metadataUpdated(Metadata metadata) {
-               this.metadata = metadata;
-               eventBus.post(new MetadataUpdated(this, metadata));
-       }
-
-       @Override
        public void process(byte[] buffer) throws IOException {
                fileOutputStream.write(buffer);
                logger.finest(String.format("FileSink: Wrote %d Bytes.", buffer.length));