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;
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;
@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);
}
};
FetchContext fetchContext = client.getFetchContext();
try {
- ClientGetter clientGetter = client.fetch(uri, 1048576, callback, fetchContext, RequestStarter.INTERACTIVE_PRIORITY_CLASS);
+ ClientGetter clientGetter = client.fetch(uri, 2097152, callback, fetchContext, RequestStarter.INTERACTIVE_PRIORITY_CLASS);
clientGetter.setMetaSnoop(snoop);
clientGetter.restart(uri, fetchContext.filterData, node.clientCore.clientContext);
} catch (FetchException fe) {
}
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);
}
}
/**
- * Container for a fetched URI and the {@link FetchResult}.
- *
- * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
- */
- 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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
}
- public class InsertTokenSupplier implements Function<Image, InsertToken> {
+ public static class InsertTokenSupplier implements Function<Image, InsertToken> {
+
+ 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);
}
}