X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fdata%2FDownload.java;h=12b012947d79651d9b69f4a5cedac12c093e992c;hb=2d0f3614a96b0d8f7d5666c65ab80b3cbf5349ec;hp=0592eaf9477c925f2e42e9dc1cc31881a75207bc;hpb=db7e9612fa189cee9f4b9086e00d87c4d6c58bbf;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/data/Download.java b/src/main/java/net/pterodactylus/xdcc/data/Download.java index 0592eaf..12b0129 100644 --- a/src/main/java/net/pterodactylus/xdcc/data/Download.java +++ b/src/main/java/net/pterodactylus/xdcc/data/Download.java @@ -21,9 +21,13 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.io.OutputStream; import java.net.InetAddress; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.irc.DccReceiver; +import com.google.common.base.Predicate; + /** * Information about an ongoing download. * @@ -31,6 +35,15 @@ import net.pterodactylus.irc.DccReceiver; */ public class Download { + /** Predicate that identifies downloads that have started. */ + public static final Predicate FILTER_RUNNING = new Predicate() { + + @Override + public boolean apply(Download download) { + return download.dccReceiver() != null; + } + }; + /** The bot that is being downloaded from. */ private final Bot bot; @@ -38,19 +51,19 @@ public class Download { private final Pack pack; /** The name of the file being downloaded. */ - private String filename; + private final AtomicReference filename = new AtomicReference(); /** The size of the file being downloaded. */ - private long filesize; + private final AtomicLong filesize = new AtomicLong(); /** The remote address. */ - private InetAddress remoteAddress; + private final AtomicReference remoteAddress = new AtomicReference(); /** The output stream. */ - private OutputStream outputStream; + private final AtomicReference outputStream = new AtomicReference(); /** The DCC receiver. */ - private DccReceiver dccReceiver; + private final AtomicReference dccReceiver = new AtomicReference(); /** * Creates a new download. @@ -93,7 +106,7 @@ public class Download { * @return The full name of the file */ public String filename() { - return filename; + return filename.get(); } /** @@ -102,7 +115,7 @@ public class Download { * @return The size of the file */ public long filesize() { - return filesize; + return filesize.get(); } /** @@ -111,7 +124,7 @@ public class Download { * @return The remote address to download from */ public InetAddress remoteAddress() { - return remoteAddress; + return remoteAddress.get(); } /** @@ -120,7 +133,7 @@ public class Download { * @return The output stream */ public OutputStream outputStream() { - return outputStream; + return outputStream.get(); } /** @@ -129,7 +142,7 @@ public class Download { * @return The DCC receiver */ public DccReceiver dccReceiver() { - return dccReceiver; + return dccReceiver.get(); } // @@ -144,7 +157,7 @@ public class Download { * @return This download */ public Download filename(String filename) { - this.filename = filename; + this.filename.set(filename); return this; } @@ -156,7 +169,7 @@ public class Download { * @return This download */ public Download filesize(long filesize) { - this.filesize = filesize; + this.filesize.set(filesize); return this; } @@ -168,7 +181,7 @@ public class Download { * @return This download */ public Download remoteAddress(InetAddress remoteAddress) { - this.remoteAddress = remoteAddress; + this.remoteAddress.set(remoteAddress); return this; } @@ -180,7 +193,7 @@ public class Download { * @return This download */ public Download outputStream(OutputStream outputStream) { - this.outputStream = outputStream; + this.outputStream.set(outputStream); return this; } @@ -192,7 +205,7 @@ public class Download { * @return This download */ public Download dccReceiver(DccReceiver dccReceiver) { - this.dccReceiver = dccReceiver; + this.dccReceiver.set(dccReceiver); return this; }