diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/channel/SeekableDownloadChannel.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/channel/SeekableDownloadChannel.java
new file mode 100644
index 0000000..126f65f
--- /dev/null
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/channel/SeekableDownloadChannel.java
@@ -0,0 +1,232 @@
+/**
+ *
+ */
+package com.rogiel.httpchannel.channel;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.ByteBuffer;
+import java.nio.channels.NonWritableChannelException;
+import java.nio.channels.SeekableByteChannel;
+
+import com.rogiel.httpchannel.service.DownloadChannel;
+import com.rogiel.httpchannel.service.DownloadService;
+import com.rogiel.httpchannel.service.Downloader;
+import com.rogiel.httpchannel.service.DownloaderCapability;
+
+/**
+ * Creates a pseudo-seekable {@link DownloadChannel}. This implementations opens
+ * a new connection on every call to {@link #position(long)} and thus might
+ * consume a lot of bandwidth to start downloads. Also, some services do not
+ * support download resuming, those services are not supported by
+ * {@link SeekableDownloadChannel}.
+ *
+ * You can use {@link #isSupported(DownloadChannel)} or
+ * {@link #isSupported(DownloadService)} to check whether an channel or a
+ * service is supported.
+ *
+ * @author Rogiel
+ * @see SeekableDownloadChannel#isSupported(DownloadChannel)
+ * @see SeekableDownloadChannel#isSupported(DownloadService))
+ */
+public class SeekableDownloadChannel implements DownloadChannel,
+ SeekableByteChannel {
+ /**
+ * The current opened channel.
+ *
+ * This channel will be swapped at every call to {@link #position(long)}.
+ */
+ private DownloadChannel channel;
+ /**
+ * The current channel position
+ */
+ private long position = 0;
+
+ /**
+ * Creates a new {@link SeekableDownloadChannel} using an base
+ * {@link DownloadChannel}
+ *
+ * @param channel
+ * the base {@link DownloadChannel}
+ * @throws IOException
+ * if the channel is not supported
+ * @see SeekableDownloadChannel#isSupported(DownloadChannel)
+ */
+ private SeekableDownloadChannel(DownloadChannel channel,
+ boolean closeIfNotSupported) throws IOException {
+ if (!isSupported(channel)) {
+ if (closeIfNotSupported)
+ channel.close();
+ throw new IOException("This channel is not supported");
+ }
+ this.channel = channel;
+ }
+
+ /**
+ * Creates a new {@link SeekableDownloadChannel} using an base
+ * {@link DownloadChannel}. If not supported, an {@link IOException} is
+ * thrown and the channel is not closed.
+ *
+ * @param channel
+ * the base {@link DownloadChannel}
+ * @throws IOException
+ * if the channel is not supported
+ */
+ public SeekableDownloadChannel(DownloadChannel channel) throws IOException {
+ this(channel, false);
+ }
+
+ /**
+ * Creates a new {@link SeekableDownloadChannel} using an base
+ * {@link Downloader}
+ *
+ * @param downloader
+ * the base {@link Downloader}
+ * @throws IOException
+ * if any exception occur while opening the channel or if the
+ * channel is not supported
+ */
+ public SeekableDownloadChannel(Downloader> downloader) throws IOException {
+ this(downloader.openChannel(), true);
+ }
+
+ /**
+ * Creates a new {@link SeekableDownloadChannel} using an base
+ * {@link DownloadService} and an {@link URI}.
+ *
+ * @param service
+ * the base {@link DownloadService}
+ * @param uri
+ * the base {@link URI}
+ * @throws IOException
+ * if any exception occur while opening the channel or if the
+ * channel is not supported
+ */
+ public SeekableDownloadChannel(DownloadService> service, URI uri)
+ throws IOException {
+ this(service.getDownloader(uri));
+ }
+
+ @Override
+ public long size() throws IOException {
+ return channel.size();
+ }
+
+ @Override
+ public String filename() throws IOException {
+ return channel.filename();
+ }
+
+ @Override
+ public DownloadService> getService() {
+ return channel.getService();
+ }
+
+ @Override
+ public Downloader> getDownloader() {
+ return channel.getDownloader();
+ }
+
+ @Override
+ public boolean isOpen() {
+ return channel.isOpen();
+ }
+
+ @Override
+ public void close() throws IOException {
+ channel.close();
+ channel = null;
+ position = 0;
+ }
+
+ @Override
+ public int read(ByteBuffer dst) throws IOException {
+ int read = channel.read(dst);
+ position += read;
+ return read;
+ }
+
+ /**
+ * This implementation always throws an {@link NonWritableChannelException}.
+ *
+ *
+ * {@inheritDoc}
+ *
+ * @throws NonWritableChannelException
+ * always (download channels are read-only)
+ */
+ @Override
+ public int write(ByteBuffer src) throws IOException {
+ throw new NonWritableChannelException();
+ }
+
+ @Override
+ public long position() throws IOException {
+ return position;
+ }
+
+ @Override
+ public SeekableDownloadChannel position(long newPosition)
+ throws IOException {
+ // closes the current channel
+ channel.close();
+ // now open a new channel
+ this.position = newPosition;
+ channel = channel.getDownloader().openChannel(position);
+ return this;
+ }
+
+ /**
+ * Always throws an {@link NonWritableChannelException}
+ *
+ * @throws NonWritableChannelException
+ * always (download channels are read-only)
+ */
+ @Override
+ public SeekableDownloadChannel truncate(long size) throws IOException {
+ throw new NonWritableChannelException();
+ }
+
+ /**
+ * @return the current {@link DownloadChannel}
+ */
+ public DownloadChannel channel() {
+ return channel;
+ }
+
+ /**
+ * Checks whether the given service supports
+ * {@link SeekableDownloadChannel}
+ *
+ * @param service
+ * the service
+ * @return true if the service is supported
+ */
+ public static boolean isSupported(DownloadService> service) {
+ switch (service.getServiceMode()) {
+ case UNAUTHENTICATED:
+ return service.getDownloadCapabilities().has(
+ DownloaderCapability.UNAUTHENTICATED_RESUME);
+ case NON_PREMIUM:
+ return service.getDownloadCapabilities().has(
+ DownloaderCapability.NON_PREMIUM_ACCOUNT_RESUME);
+ case PREMIUM:
+ return service.getDownloadCapabilities().has(
+ DownloaderCapability.PREMIUM_ACCOUNT_RESUME);
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Checks whether the given channel supports
+ * {@link SeekableDownloadChannel}
+ *
+ * @param channel
+ * the channelO
+ * @return true if the channel is supported
+ */
+ public static boolean isSupported(DownloadChannel channel) {
+ return isSupported(channel.getService());
+ }
+}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AbstractService.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AbstractService.java
index 348401c..e28c1b2 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AbstractService.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/AbstractService.java
@@ -25,7 +25,9 @@ import com.rogiel.httpchannel.captcha.exception.UnsolvableCaptchaServiceExceptio
import com.rogiel.httpchannel.service.exception.NoCaptchaServiceException;
/**
- * This is an abstract {@link Service} implementation.
+ * This is an abstract {@link Service} implementation. Service implementators
+ * should try to implement this abstract class instead of directly implementing
+ * {@link Service}.
*
* @author Rogiel
* @version 1.0
@@ -35,8 +37,22 @@ public abstract class AbstractService implements Service {
* The service {@link Logger} instance
*/
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ /**
+ * The currently active service mode
+ */
+ protected ServiceMode serviceMode = ServiceMode.UNAUTHENTICATED;
+
+ /**
+ * This service {@link CaptchaService} that is used to resolve CAPTCHAS
+ */
protected CaptchaService captchaService;
+ @Override
+ public ServiceMode getServiceMode() {
+ return serviceMode;
+ }
+
@Override
public Service clone() {
try {
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/DownloadChannel.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/DownloadChannel.java
index f3791a4..9d9dbea 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/DownloadChannel.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/DownloadChannel.java
@@ -32,4 +32,14 @@ import java.nio.channels.ReadableByteChannel;
* @author Rogiel
*/
public interface DownloadChannel extends HttpChannel, ReadableByteChannel {
+ /**
+ * @return the service instance providing this download
+ */
+ @Override
+ DownloadService> getService();
+
+ /**
+ * @return the downloader providing this download
+ */
+ Downloader> getDownloader();
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Downloader.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Downloader.java
index 457eaf6..df65d7f 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Downloader.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Downloader.java
@@ -87,7 +87,7 @@ public interface Downloader {
NoCaptchaServiceException;
/**
- * Opens a new {@link DownloadChannel} with not listener. For more details,
+ * Opens a new {@link DownloadChannel} with no listener. For more details,
* see {@link #openChannel(DownloadListener, long)}
*
* @param position
@@ -157,7 +157,7 @@ public interface Downloader {
NoCaptchaServiceException;
/**
- * Opens a new {@link DownloadChannel} with not listener and positioned at
+ * Opens a new {@link DownloadChannel} with no listener and positioned at
* start. For more details, see {@link #openChannel(DownloadListener, long)}
*
* Note that {@link DownloadNotResumableException} is never thrown because
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/HttpChannel.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/HttpChannel.java
index 15e9c8e..685c111 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/HttpChannel.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/HttpChannel.java
@@ -4,6 +4,7 @@
package com.rogiel.httpchannel.service;
import java.io.Closeable;
+import java.io.IOException;
import java.nio.channels.Channel;
/**
@@ -14,10 +15,15 @@ public interface HttpChannel extends Channel, Closeable {
/**
* @return the file size
*/
- long getFilesize();
+ long size() throws IOException;
/**
* @return the file name
*/
- String getFilename();
+ String filename() throws IOException;
+
+ /**
+ * @return the service providing data to this channel
+ */
+ Service getService();
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Service.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Service.java
index 4627084..5b98ef9 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Service.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Service.java
@@ -53,6 +53,23 @@ public interface Service extends Cloneable {
*/
int getMinorVersion();
+ /**
+ * Returns the currently active service mode. The mode is not static and can
+ * be changed with an {@link Authenticator}
+ *
+ * @return the service mode
+ */
+ ServiceMode getServiceMode();
+
+ /**
+ * Return the matrix of supported modes for this {@link Service}.
+ *
+ * @return {@link CapabilityMatrix} with all supported modes of this
+ * {@link Service}.
+ * @see DownloaderCapability
+ */
+ CapabilityMatrix getPossibleServiceModes();
+
/**
* Sets this service captcha service. CaptchaService are safe to be switched
* even after an transfer has begun.
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/ServiceMode.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/ServiceMode.java
new file mode 100644
index 0000000..2aaa183
--- /dev/null
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/ServiceMode.java
@@ -0,0 +1,14 @@
+/**
+ *
+ */
+package com.rogiel.httpchannel.service;
+
+/**
+ * The available modes on the service. Defines if it is using an
+ * unauthenticated, non-premium or premium mode.
+ *
+ * @author Rogiel
+ */
+public enum ServiceMode {
+ UNAUTHENTICATED, NON_PREMIUM, PREMIUM;
+}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/UploadChannel.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/UploadChannel.java
index 7de30c8..2f86e07 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/UploadChannel.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/UploadChannel.java
@@ -45,6 +45,17 @@ public interface UploadChannel extends HttpChannel, WritableByteChannel {
*/
URI getDownloadLink();
+ /**
+ * @return the service instance providing this upload
+ */
+ @Override
+ UploadService> getService();
+
+ /**
+ * @return the {@link Uploader} providing this upload
+ */
+ Uploader> getUploader();
+
/**
* @throws UploadLinkNotFoundException
* if after the upload, the download link cannot be found
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullAuthenticatorConfiguration.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullAuthenticatorConfiguration.java
index f2832e4..9b3fd8b 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullAuthenticatorConfiguration.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullAuthenticatorConfiguration.java
@@ -14,4 +14,7 @@ import com.rogiel.httpchannel.service.Authenticator.AuthenticatorConfiguration;
public final class NullAuthenticatorConfiguration implements
AuthenticatorConfiguration {
public static final NullAuthenticatorConfiguration SHARED_INSTANCE = new NullAuthenticatorConfiguration();
+
+ private NullAuthenticatorConfiguration() {
+ }
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullDownloaderConfiguration.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullDownloaderConfiguration.java
index 4a0ae36..926f618 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullDownloaderConfiguration.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullDownloaderConfiguration.java
@@ -13,4 +13,7 @@ import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
public final class NullDownloaderConfiguration implements
DownloaderConfiguration {
public static final NullDownloaderConfiguration SHARED_INSTANCE = new NullDownloaderConfiguration();
+
+ private NullDownloaderConfiguration() {
+ }
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullUploaderConfiguration.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullUploaderConfiguration.java
index 105ced4..d931c36 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullUploaderConfiguration.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/config/NullUploaderConfiguration.java
@@ -12,4 +12,7 @@ import com.rogiel.httpchannel.service.Uploader.UploaderConfiguration;
*/
public final class NullUploaderConfiguration implements UploaderConfiguration {
public static final NullUploaderConfiguration SHARED_INSTANCE = new NullUploaderConfiguration();
+
+ private NullUploaderConfiguration() {
+ }
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/AuthenticationServices.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/AuthenticationServices.java
index a059d70..a59bbe7 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/AuthenticationServices.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/AuthenticationServices.java
@@ -25,13 +25,41 @@ import com.rogiel.httpchannel.service.Credential;
* @author Rogiel
*/
public class AuthenticationServices {
- public static , C extends AuthenticatorConfiguration> Authenticator authenticate(
+ /**
+ * Creates a new {@link Credential} with username and
+ * password and creates a new {@link Authenticator} with it and
+ * configuration. {@link Authenticator#login()} is not called.
+ *
+ * @param service
+ * the service
+ * @param configuration
+ * the authenticator configuration
+ * @param username
+ * the username
+ * @param password
+ * the password
+ * @return a newly created {@link Authenticator}
+ */
+ public static , C extends AuthenticatorConfiguration> Authenticator authenticator(
S service, C configuration, String username, String password) {
return service.getAuthenticator(new Credential(username, password),
configuration);
}
- public static , C extends AuthenticatorConfiguration> Authenticator authenticate(
+ /**
+ * Creates a new {@link Credential} with username and
+ * password and creates a new {@link Authenticator} with it.
+ * {@link Authenticator#login()} is not called.
+ *
+ * @param service
+ * the service
+ * @param username
+ * the username
+ * @param password
+ * the password
+ * @return a newly created {@link Authenticator}
+ */
+ public static , C extends AuthenticatorConfiguration> Authenticator authenticator(
S service, String username, String password) {
return service.getAuthenticator(new Credential(username, password));
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/DownloadServices.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/DownloadServices.java
index a8b3184..745a8e1 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/DownloadServices.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/DownloadServices.java
@@ -25,6 +25,19 @@ import com.rogiel.httpchannel.service.DownloadService;
* @author Rogiel
*/
public class DownloadServices {
+ /**
+ * Checks whether the given uri can be downloaded with the
+ * {@link DownloadService} service.
+ *
+ * @param service
+ * the {@link DownloadService}
+ * @param uri
+ * the checking {@link URI}
+ * @return true if this {@link URI} can be downloaded with
+ * service
+ * @throws IOException
+ * if any exception is thrown while checking
+ */
public static boolean canDownload(DownloadService> service, URI uri)
throws IOException {
return service.matchURI(uri);
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/UploadServices.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/UploadServices.java
index 977dc06..68fc396 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/UploadServices.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/UploadServices.java
@@ -28,18 +28,58 @@ import com.rogiel.httpchannel.service.Uploader.UploaderConfiguration;
* @author Rogiel
*/
public class UploadServices {
+ /**
+ * Creates a new {@link Uploader} for the given NIO {@link Path}, using
+ * configuration as the {@link Uploader} configuration.
+ *
+ * @param service
+ * the upload service
+ * @param configuration
+ * the uploader configuration
+ * @param path
+ * the NIO.2 {@link Path}
+ * @return a newly created {@link Uploader}
+ * @throws IOException
+ * if any exception occur while fetching {@link Path}
+ * information
+ */
public static , C extends UploaderConfiguration> Uploader upload(
S service, C configuration, Path path) throws IOException {
return service.getUploader(path.getFileName().toString(),
Files.size(path), configuration);
}
+ /**
+ * Creates a new {@link Uploader} for the given NIO {@link Path}.
+ *
+ * @param service
+ * the upload service
+ * @param path
+ * the NIO.2 {@link Path}
+ * @return a newly created {@link Uploader}
+ * @throws IOException
+ * if any exception occur while fetching {@link Path}
+ * information
+ */
public static , C extends UploaderConfiguration> Uploader upload(
S service, Path path) throws IOException {
return service.getUploader(path.getFileName().toString(),
Files.size(path));
}
+ /**
+ * Checks whether the given service can upload the file
+ * represented by path
+ *
+ * @param service
+ * the upload service
+ * @param path
+ * the file {@link Path}
+ * @return true if the upload will be acepted
+ * @throws IOException
+ * if any exception occur while fetching {@link Path}
+ * information
+ */
public static boolean canUpload(UploadService> service, Path path)
throws IOException {
return service.getMaximumFilesize() >= Files.size(path);
diff --git a/httpchannel-channelcopy/src/main/java/com/rogiel/httpchannel/copy/ChannelCopy.java b/httpchannel-channelcopy/src/main/java/com/rogiel/httpchannel/copy/ChannelCopy.java
index 319ed83..30cfb17 100644
--- a/httpchannel-channelcopy/src/main/java/com/rogiel/httpchannel/copy/ChannelCopy.java
+++ b/httpchannel-channelcopy/src/main/java/com/rogiel/httpchannel/copy/ChannelCopy.java
@@ -93,11 +93,13 @@ public class ChannelCopy implements Callable> {
*
* @param downloadChannel
* the download channel
+ * @throws IOException
+ * if any {@link IOException} occur
*/
- public ChannelCopy(DownloadChannel downloadChannel) {
+ public ChannelCopy(DownloadChannel downloadChannel) throws IOException {
this.downloadChannel = downloadChannel;
- this.filename = downloadChannel.getFilename();
- this.filesize = downloadChannel.getFilesize();
+ this.filename = downloadChannel.filename();
+ this.filesize = downloadChannel.size();
}
/**
@@ -128,8 +130,8 @@ public class ChannelCopy implements Callable> {
.openChannel();
this.downloadChannel = downloadChannel;
- this.filename = downloadChannel.getFilename();
- this.filesize = downloadChannel.getFilesize();
+ this.filename = downloadChannel.filename();
+ this.filesize = downloadChannel.size();
}
/**
diff --git a/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/impl/DepositFilesService.java b/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/impl/DepositFilesService.java
index 5ffc3b6..82e330b 100644
--- a/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/impl/DepositFilesService.java
+++ b/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/impl/DepositFilesService.java
@@ -18,6 +18,7 @@ import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -66,6 +67,12 @@ public class DepositFilesService extends AbstractHttpService implements
return 0;
}
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED,
+ ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
+ }
+
@Override
public Uploader getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) {
@@ -131,7 +138,7 @@ public class DepositFilesService extends AbstractHttpService implements
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
- super(filename, filesize, configuration);
+ super(DepositFilesService.this, filename, filesize, configuration);
}
@Override
@@ -209,6 +216,7 @@ public class DepositFilesService extends AbstractHttpService implements
captchaService.valid(captcha);
if (!page.contains(VALID_LOGIN_REDIRECT))
throw new AuthenticationInvalidCredentialException();
+ serviceMode = ServiceMode.NON_PREMIUM;
return;
}
}
diff --git a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/impl/FileSonicService.java b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/impl/FileSonicService.java
index d744bc2..4f45bb3 100644
--- a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/impl/FileSonicService.java
+++ b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/impl/FileSonicService.java
@@ -32,6 +32,7 @@ import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -81,6 +82,12 @@ public class FileSonicService extends AbstractHttpService implements Service,
return 0;
}
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED,
+ ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
+ }
+
@Override
public Uploader getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) {
@@ -149,7 +156,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
- super(filename, filesize, configuration);
+ super(FileSonicService.this, filename, filesize, configuration);
}
@Override
@@ -186,6 +193,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
public void login() throws IOException {
logger.debug("Logging to filesonic.com");
api.login(credential.getUsername(), credential.getPassword());
+ serviceMode = ServiceMode.NON_PREMIUM;
// if (username == null)
// throw new AuthenticationInvalidCredentialException();
}
diff --git a/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java b/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java
index 1053ebc..e4c17c9 100644
--- a/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java
+++ b/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java
@@ -22,8 +22,6 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.htmlparser.Tag;
@@ -43,11 +41,11 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
import com.rogiel.httpchannel.service.UploaderCapability;
-import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
@@ -99,6 +97,12 @@ public class HotFileService extends AbstractHttpService implements Service,
return 0;
}
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED,
+ ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
+ }
+
@Override
public Uploader getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) {
@@ -191,7 +195,7 @@ public class HotFileService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
- super(filename, filesize, configuration);
+ super(HotFileService.this, filename, filesize, configuration);
}
@Override
@@ -224,7 +228,7 @@ public class HotFileService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader {
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
- super(uri, configuration);
+ super(HotFileService.this, uri, configuration);
}
@Override
@@ -251,14 +255,7 @@ public class HotFileService extends AbstractHttpService implements Service,
// final String tmHash = PatternUtils.find(DOWNLOAD_TMHASH_PATTERN,
// content);F
if (downloadUrl != null && downloadUrl.length() > 0) {
- final HttpResponse downloadResponse = get(downloadUrl)
- .request();
-
- final String filename = FilenameUtils.getName(downloadUrl);
- long contentLength = getContentLength(downloadResponse);
-
- return new InputStreamDownloadChannel(downloadResponse
- .getEntity().getContent(), contentLength, filename);
+ return download(get(downloadUrl));
} else {
throw new IOException("Download link not found");
}
@@ -284,6 +281,7 @@ public class HotFileService extends AbstractHttpService implements Service,
final Tag accountTag = page.getTagByID("account");
if (accountTag == null)
throw new AuthenticationInvalidCredentialException();
+ serviceMode = ServiceMode.NON_PREMIUM;
}
@Override
diff --git a/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java b/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java
index e9457aa..6fa7cba 100644
--- a/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java
+++ b/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java
@@ -42,6 +42,7 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -102,6 +103,12 @@ public class MegaUploadService extends AbstractHttpService implements Service,
return 0;
}
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED,
+ ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
+ }
+
@Override
public Uploader getUploader(
String filename, long filesize,
@@ -200,7 +207,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize,
MegaUploadUploaderConfiguration configuration) {
- super(filename, filesize, configuration);
+ super(MegaUploadService.this, filename, filesize, configuration);
}
@Override
@@ -210,7 +217,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
.asPage();
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URI is {}", uri);
-
+
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(uri)
.parameter("multimessage_0", configuration.description())
@@ -236,7 +243,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
Downloader {
public DownloaderImpl(URI uri,
MegaUploadDownloaderConfiguration configuration) {
- super(uri, configuration);
+ super(MegaUploadService.this, uri, configuration);
}
@Override
@@ -313,6 +320,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
String username = page.findScript(LOGIN_USERNAME_PATTERN, 1);
if (username == null)
throw new AuthenticationInvalidCredentialException();
+ serviceMode = ServiceMode.NON_PREMIUM;
}
@Override
diff --git a/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/impl/MultiUploadService.java b/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/impl/MultiUploadService.java
index 162ab96..7bd8f35 100644
--- a/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/impl/MultiUploadService.java
+++ b/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/impl/MultiUploadService.java
@@ -23,6 +23,7 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -80,6 +81,12 @@ public class MultiUploadService extends AbstractHttpService implements Service,
return 0;
}
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED,
+ ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
+ }
+
@Override
public Uploader getUploader(
String filename, long filesize,
@@ -178,7 +185,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize,
MultiUploadUploaderConfiguration configuration) {
- super(filename, filesize, configuration);
+ super(MultiUploadService.this, filename, filesize, configuration);
}
@Override
@@ -225,7 +232,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
Downloader {
protected DownloaderImpl(URI uri,
NullDownloaderConfiguration configuration) {
- super(uri, configuration);
+ super(MultiUploadService.this, uri, configuration);
}
@Override
@@ -258,6 +265,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
if (!page.containsIgnoreCase(credential.getUsername()))
throw new AuthenticationInvalidCredentialException();
+ serviceMode = ServiceMode.NON_PREMIUM;
}
@Override
diff --git a/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/impl/UploadHereService.java b/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/impl/UploadHereService.java
index 6954c85..f80f96e 100644
--- a/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/impl/UploadHereService.java
+++ b/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/impl/UploadHereService.java
@@ -24,6 +24,7 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -82,6 +83,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
return 0;
}
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED,
+ ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
+ }
+
@Override
public Uploader getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) {
@@ -177,7 +184,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
- super(filename, filesize, configuration);
+ super(UploadHereService.this, filename, filesize, configuration);
}
@Override
@@ -223,7 +230,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
AbstractHttpDownloader implements
Downloader {
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
- super(uri, configuration);
+ super(UploadHereService.this, uri, configuration);
}
@Override
@@ -288,6 +295,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException();
+ serviceMode = ServiceMode.NON_PREMIUM;
}
@Override
diff --git a/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/impl/UploadKingService.java b/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/impl/UploadKingService.java
index 074d8b7..4a19d1b 100644
--- a/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/impl/UploadKingService.java
+++ b/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/impl/UploadKingService.java
@@ -24,6 +24,7 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -82,6 +83,12 @@ public class UploadKingService extends AbstractHttpService implements Service,
return 0;
}
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED,
+ ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
+ }
+
@Override
public Uploader getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) {
@@ -177,7 +184,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
- super(filename, filesize, configuration);
+ super(UploadKingService.this, filename, filesize, configuration);
}
@Override
@@ -220,7 +227,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
AbstractHttpDownloader implements
Downloader {
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
- super(uri, configuration);
+ super(UploadKingService.this, uri, configuration);
}
@Override
@@ -287,6 +294,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException();
+ serviceMode = ServiceMode.NON_PREMIUM;
}
@Override
diff --git a/httpchannel-service/httpchannel-service-zshare/src/main/java/com/rogiel/httpchannel/service/impl/ZShareService.java b/httpchannel-service/httpchannel-service-zshare/src/main/java/com/rogiel/httpchannel/service/impl/ZShareService.java
index f589d9f..8e3935a 100644
--- a/httpchannel-service/httpchannel-service-zshare/src/main/java/com/rogiel/httpchannel/service/impl/ZShareService.java
+++ b/httpchannel-service/httpchannel-service-zshare/src/main/java/com/rogiel/httpchannel/service/impl/ZShareService.java
@@ -1,8 +1,10 @@
package com.rogiel.httpchannel.service.impl;
import com.rogiel.httpchannel.service.AbstractHttpService;
+import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.ServiceMode;
/**
* This service handles uploads to UploadKing.com.
@@ -35,14 +37,15 @@ public class ZShareService extends AbstractHttpService implements Service/*
// Pattern.CASE_INSENSITIVE);
// private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
// .compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
-// private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
-// .compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
-// private static final Pattern TIMER_PATTERN = Pattern.compile(
-// "count = ([0-9]*);", Pattern.COMMENTS);
-// private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
-// .compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
-//
-// private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
+ // private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
+ // .compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
+ // private static final Pattern TIMER_PATTERN = Pattern.compile(
+ // "count = ([0-9]*);", Pattern.COMMENTS);
+ // private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
+ // .compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
+ //
+ // private static final String INVALID_LOGIN_STRING =
+ // "Incorrect username and/or password. Please try again!";
@Override
public ServiceID getServiceID() {
@@ -59,6 +62,16 @@ public class ZShareService extends AbstractHttpService implements Service/*
return 0;
}
+ @Override
+ public ServiceMode getServiceMode() {
+ return null;
+ }
+
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix();
+ }
+
// @Override
// public Uploader getUploader(String filename,
// long filesize, ZShareUploaderConfiguration configuration) {
diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractDownloader.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractDownloader.java
index 14ba846..37c2c47 100644
--- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractDownloader.java
+++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractDownloader.java
@@ -22,6 +22,7 @@ import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
*/
public abstract class AbstractDownloader
implements Downloader {
+ protected final DownloadService> service;
/**
* The download URI
*/
@@ -35,12 +36,16 @@ public abstract class AbstractDownloader
/**
* Creates a new instance
*
+ * @param service
+ * the download service
* @param uri
* the download uri
* @param configuration
* the configuration object
*/
- protected AbstractDownloader(URI uri, C configuration) {
+ protected AbstractDownloader(DownloadService> service, URI uri,
+ C configuration) {
+ this.service = service;
this.uri = uri;
this.configuration = configuration;
}
@@ -69,7 +74,8 @@ public abstract class AbstractDownloader
protected InputStreamDownloadChannel createInputStreamChannel(
InputStream in, long length, String filename) {
- return new InputStreamDownloadChannel(in, length, filename);
+ return new InputStreamDownloadChannel(service, this, in, length,
+ filename);
}
@Override
diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpDownloader.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpDownloader.java
index 6e78a9f..c142274 100644
--- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpDownloader.java
+++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpDownloader.java
@@ -38,9 +38,10 @@ import com.rogiel.httpchannel.util.ThreadUtils;
public abstract class AbstractHttpDownloader
extends AbstractDownloader implements Downloader {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- protected AbstractHttpDownloader(URI uri, C configuration) {
- super(uri, configuration);
+
+ protected AbstractHttpDownloader(DownloadService> service, URI uri,
+ C configuration) {
+ super(service, uri, configuration);
}
protected long getContentLength(HttpResponse response) {
diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractUploader.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractUploader.java
index d38f35d..b4f7f03 100644
--- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractUploader.java
+++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractUploader.java
@@ -15,7 +15,17 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadCh
*/
public abstract class AbstractUploader
implements Uploader {
+ /**
+ * The upload service
+ */
+ protected final UploadService> service;
+ /**
+ * The name of the file to be uploaded
+ */
protected final String filename;
+ /**
+ * The size of the file to be uploaded
+ */
protected final long filesize;
/**
@@ -26,6 +36,8 @@ public abstract class AbstractUploader
/**
* Creates a new instance
*
+ * @param service
+ * the upload service
* @param filename
* the file name
* @param filesize
@@ -33,7 +45,9 @@ public abstract class AbstractUploader
* @param configuration
* the configuration object
*/
- public AbstractUploader(String filename, long filesize, C configuration) {
+ public AbstractUploader(UploadService> service, String filename,
+ long filesize, C configuration) {
+ this.service = service;
this.filename = filename;
this.filesize = filesize;
this.configuration = configuration;
@@ -48,7 +62,8 @@ public abstract class AbstractUploader
*/
protected LinkedUploadChannel createLinkedChannel(
LinkedUploadChannelCloseCallback closeCallback) {
- return new LinkedUploadChannel(closeCallback, filesize, filename);
+ return new LinkedUploadChannel(service, this, closeCallback, filesize,
+ filename);
}
@Override
diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/InputStreamDownloadChannel.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/InputStreamDownloadChannel.java
index 9688d7d..17e194a 100644
--- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/InputStreamDownloadChannel.java
+++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/InputStreamDownloadChannel.java
@@ -23,7 +23,8 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import com.rogiel.httpchannel.service.DownloadChannel;
-
+import com.rogiel.httpchannel.service.DownloadService;
+import com.rogiel.httpchannel.service.Downloader;
/**
* @author Rogiel
@@ -32,11 +33,17 @@ import com.rogiel.httpchannel.service.DownloadChannel;
public class InputStreamDownloadChannel implements DownloadChannel {
private final ReadableByteChannel channel;
+ private final DownloadService> service;
+ private final Downloader> downloader;
+
private final long length;
private final String filename;
- public InputStreamDownloadChannel(InputStream in, final long length,
+ public InputStreamDownloadChannel(DownloadService> service,
+ Downloader> downloader, InputStream in, final long length,
final String filename) {
+ this.service = service;
+ this.downloader = downloader;
this.channel = Channels.newChannel(in);
this.length = length;
this.filename = filename;
@@ -58,12 +65,22 @@ public class InputStreamDownloadChannel implements DownloadChannel {
}
@Override
- public long getFilesize() {
+ public long size() {
return length;
}
@Override
- public String getFilename() {
+ public String filename() {
return filename;
}
+
+ @Override
+ public DownloadService> getService() {
+ return service;
+ }
+
+ @Override
+ public Downloader> getDownloader() {
+ return downloader;
+ }
}
diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java
index f8b3fa5..603bdae 100644
--- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java
+++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java
@@ -27,6 +27,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rogiel.httpchannel.service.UploadChannel;
+import com.rogiel.httpchannel.service.UploadService;
+import com.rogiel.httpchannel.service.Uploader;
import com.rogiel.httpchannel.service.exception.UploadLinkNotFoundException;
/**
@@ -41,6 +43,15 @@ public class LinkedUploadChannel implements UploadChannel {
*/
private final Logger logger = LoggerFactory.getLogger(this.getClass());
+ /**
+ * The upload service
+ */
+ private final UploadService> service;
+ /**
+ * The uploader instance
+ */
+ private final Uploader> uploader;
+
/**
* The destionation {@link Channel}. Data writted is forwarded to this
* channel.
@@ -69,8 +80,11 @@ public class LinkedUploadChannel implements UploadChannel {
*/
private boolean open = true;
- public LinkedUploadChannel(LinkedUploadChannelCloseCallback closeCallback,
- long filesize, String filename) {
+ public LinkedUploadChannel(UploadService> service, Uploader> uploader,
+ LinkedUploadChannelCloseCallback closeCallback, long filesize,
+ String filename) {
+ this.service = service;
+ this.uploader = uploader;
this.closeCallback = closeCallback;
this.filename = filename;
this.length = filesize;
@@ -110,12 +124,12 @@ public class LinkedUploadChannel implements UploadChannel {
}
@Override
- public long getFilesize() {
+ public long size() {
return length;
}
@Override
- public String getFilename() {
+ public String filename() {
return filename;
}
@@ -124,6 +138,16 @@ public class LinkedUploadChannel implements UploadChannel {
return downloadLink;
}
+ @Override
+ public UploadService> getService() {
+ return service;
+ }
+
+ @Override
+ public Uploader> getUploader() {
+ return uploader;
+ }
+
/**
* Links this {@link Channel} to the destionation {@link Channel}. All data
* written in this channel will be redirected to the destination
diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannelContentBody.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannelContentBody.java
index c28a8cb..f6c0e3b 100644
--- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannelContentBody.java
+++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannelContentBody.java
@@ -42,7 +42,7 @@ public class LinkedUploadChannelContentBody extends AbstractContentBody {
@Override
public String getFilename() {
- return channel.getFilename();
+ return channel.filename();
}
@Override
@@ -64,7 +64,7 @@ public class LinkedUploadChannelContentBody extends AbstractContentBody {
@Override
public long getContentLength() {
- return channel.getFilesize();
+ return channel.size();
}
@Override