X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FFreenetInterface.java;h=838e4b0efadcda96d7281e78e11d29f5c6df0dda;hp=4b33139a4862d1d99e52f88f3302a2f7dab033ba;hb=35deb522de06ba7d97160445683375cf87529e8d;hpb=f814ad7a876bea03db77b30532eab3e7e03a05d8 diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 4b33139..838e4b0 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -32,6 +32,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nonnull; +import javax.inject.Inject; import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent; import net.pterodactylus.sone.core.event.ImageInsertFailedEvent; @@ -43,7 +44,6 @@ import net.pterodactylus.sone.data.TemporaryImage; import com.google.common.base.Function; import com.google.common.eventbus.EventBus; -import com.google.inject.Inject; import com.google.inject.Singleton; import freenet.client.ClientMetadata; @@ -178,7 +178,7 @@ public class FreenetInterface { @Override public boolean snoopMetadata(Metadata meta, ClientContext context) { String mimeType = meta.getMIMEType(); - boolean cancel = (mimeType == null) || backgroundFetchCallback.cancelForMimeType(uri, mimeType); + boolean cancel = (mimeType == null) || backgroundFetchCallback.shouldCancel(uri, mimeType, meta.dataLength()); if (cancel) { backgroundFetchCallback.failed(uri); } @@ -196,7 +196,7 @@ public class FreenetInterface { } public interface BackgroundFetchCallback { - boolean cancelForMimeType(@Nonnull FreenetURI uri, @Nonnull String mimeType); + boolean shouldCancel(@Nonnull FreenetURI uri, @Nonnull String mimeType, long size); void loaded(@Nonnull FreenetURI uri, @Nonnull String mimeType, @Nonnull byte[] data); void failed(@Nonnull FreenetURI uri); } @@ -355,56 +355,6 @@ public class FreenetInterface { } /** - * Container for a fetched URI and the {@link FetchResult}. - * - * @author David Roden - */ - public static class Fetched { - - /** The fetched URI. */ - private final FreenetURI freenetUri; - - /** The fetch result. */ - private final FetchResult fetchResult; - - /** - * Creates a new fetched URI. - * - * @param freenetUri - * The URI that was fetched - * @param fetchResult - * The fetch result - */ - public Fetched(FreenetURI freenetUri, FetchResult fetchResult) { - this.freenetUri = freenetUri; - this.fetchResult = fetchResult; - } - - // - // ACCESSORS - // - - /** - * Returns the fetched URI. - * - * @return The fetched URI - */ - public FreenetURI getFreenetUri() { - return freenetUri; - } - - /** - * Returns the fetch result. - * - * @return The fetch result - */ - public FetchResult getFetchResult() { - return fetchResult; - } - - } - - /** * Callback for USK watcher events. * * @author David ‘Bombe’ Roden @@ -558,11 +508,18 @@ public class FreenetInterface { } - public class InsertTokenSupplier implements Function { + public static class InsertTokenSupplier implements Function { + + private final FreenetInterface freenetInterface; + + @Inject + public InsertTokenSupplier(FreenetInterface freenetInterface) { + this.freenetInterface = freenetInterface; + } @Override public InsertToken apply(Image image) { - return new InsertToken(image); + return freenetInterface.new InsertToken(image); } }