From 6e88b4e3439165dbd6584c79d3f909e10af95f49 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 16 Mar 2013 19:51:01 +0100 Subject: [PATCH] =?utf8?q?Add=20method=20to=20expose=20a=20source=E2=80=99?= =?utf8?q?s=20metadata.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/java/net/pterodactylus/sonitus/data/Source.java | 7 +++++++ .../net/pterodactylus/sonitus/data/filter/ExternalFilter.java | 6 ++++++ .../net/pterodactylus/sonitus/data/filter/MultiSourceFilter.java | 8 ++++++++ .../net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java | 6 ++++++ .../java/net/pterodactylus/sonitus/data/source/FileSource.java | 6 ++++++ 5 files changed, 33 insertions(+) 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); -- 2.7.4