X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2Fsink%2FFileSink.java;h=48476b39cd8bb5f5afe547e1097e6347ca61f598;hb=e89b413f56de06f24b223bb2cc4ed3973424d5ee;hp=7210f718be684920cd9fe1a4a8d66593cc62198d;hpb=7188da95cfb6dc2bf140eb8ac7e4dc99a0761a97;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java index 7210f71..48476b3 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java @@ -19,10 +19,16 @@ 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.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 @@ -35,24 +41,58 @@ public class FileSink implements Sink { /** 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(String path) { + public FileSink(EventBus eventBus, String path) { + this.eventBus = eventBus; this.path = path; } + // + // CONTROLLED METHODS + // + + @Override + public String name() { + return path; + } + + @Override + public Metadata metadata() { + return metadata; + } + + @Override + public List> controllers() { + return Collections.emptyList(); + } + + // + // SINK METHODS + // + @Override public void open(Metadata metadata) throws IOException { fileOutputStream = new FileOutputStream(path); + metadataUpdated(metadata); } @Override @@ -66,7 +106,8 @@ public class FileSink implements Sink { @Override public void metadataUpdated(Metadata metadata) { - /* ignore. */ + this.metadata = metadata; + eventBus.post(new MetadataUpdated(this, metadata)); } @Override