From: David ‘Bombe’ Roden Date: Sat, 16 Mar 2013 18:51:01 +0000 (+0100) Subject: Add method to expose a source’s metadata. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6e88b4e3439165dbd6584c79d3f909e10af95f49;p=sonitus.git Add method to expose a source’s metadata. --- diff --git a/src/main/java/net/pterodactylus/sonitus/data/Source.java b/src/main/java/net/pterodactylus/sonitus/data/Source.java index e75b920..270a8bf 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Source.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Source.java @@ -36,6 +36,13 @@ public interface Source { Format format(); /** + * Returns the metadata of this source. + * + * @return The metadata of this source + */ + Metadata metadata(); + + /** * Retrieves the given name of bytes from this source. The source should always * try to read as much data as was requested but is free to return a byte array * with less elements that requested. However, the byte array will always be 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 73d4b5f..3bfb774 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java @@ -30,6 +30,7 @@ import net.pterodactylus.sonitus.data.ConnectException; import net.pterodactylus.sonitus.data.Connection; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Format; +import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Source; import net.pterodactylus.sonitus.io.InputStreamDrainer; @@ -65,6 +66,11 @@ public abstract class ExternalFilter implements Filter { } @Override + public Metadata metadata() { + return source.metadata(); + } + + @Override public byte[] get(int bufferSize) throws EOFException, IOException { byte[] buffer = new byte[bufferSize]; int read = pipedInputStream.read(buffer); diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java index a6566ed..33424ac 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java @@ -32,6 +32,7 @@ import java.util.logging.Logger; import net.pterodactylus.sonitus.data.ConnectException; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Format; +import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.ReusableSink; import net.pterodactylus.sonitus.data.Source; import net.pterodactylus.sonitus.data.event.SourceFinishedEvent; @@ -72,6 +73,13 @@ public class MultiSourceFilter implements Filter, ReusableSink { } @Override + public Metadata metadata() { + synchronized (syncObject) { + return connection.source.metadata(); + } + } + + @Override public byte[] get(int bufferSize) throws EOFException, IOException { byte[] buffer = new byte[bufferSize]; InputStream inputStream; 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 c87a986..a573295 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java @@ -30,6 +30,7 @@ import net.pterodactylus.sonitus.data.ConnectException; import net.pterodactylus.sonitus.data.Connection; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Format; +import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Source; import com.google.common.base.Preconditions; @@ -74,6 +75,11 @@ public class RateLimitingFilter implements Filter { } @Override + public Metadata metadata() { + return source.metadata(); + } + + @Override public byte[] get(int bufferSize) throws EOFException, IOException { byte[] buffer = new byte[bufferSize]; int read = pipedInputStream.read(buffer); diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java index cc61ce0..c967e12 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java @@ -29,6 +29,7 @@ import java.io.InputStream; import java.util.Arrays; import net.pterodactylus.sonitus.data.Format; +import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Source; import net.pterodactylus.sonitus.io.IdentifyingInputStream; @@ -83,6 +84,11 @@ public class FileSource implements Source { } @Override + public Metadata metadata() { + return new Metadata().name(path); + } + + @Override public byte[] get(int bufferSize) throws IOException { byte[] buffer = new byte[bufferSize]; int read = ByteStreams.read(fileInputStream, buffer, 0, bufferSize);