mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Implements SeekableDownloadChannel
The SeekableDownloadChannel implements SeekableByteChannel and allows to set the position of the channel and read data from that point onward. The SeekableDownloadChannel implementation, creates a new internal DownloadChannel at every call to position(long), that will create a resume channel onto that point, thus, not all service implementations are supported.
This commit is contained in:
@@ -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}.
|
||||
* <p>
|
||||
* You can use {@link #isSupported(DownloadChannel)} or
|
||||
* {@link #isSupported(DownloadService)} to check whether an channel or a
|
||||
* service is supported.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @see SeekableDownloadChannel#isSupported(DownloadChannel)
|
||||
* @see SeekableDownloadChannel#isSupported(DownloadService))
|
||||
*/
|
||||
public class SeekableDownloadChannel implements DownloadChannel,
|
||||
SeekableByteChannel {
|
||||
/**
|
||||
* The current opened channel.
|
||||
* <p>
|
||||
* 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 <b>not</b> 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}.
|
||||
* <p>
|
||||
*
|
||||
* {@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 <code>service</code> supports
|
||||
* {@link SeekableDownloadChannel}
|
||||
*
|
||||
* @param service
|
||||
* the service
|
||||
* @return <code>true</code> 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 <code>channel</code> supports
|
||||
* {@link SeekableDownloadChannel}
|
||||
*
|
||||
* @param channel
|
||||
* the channelO
|
||||
* @return <code>true</code> if the channel is supported
|
||||
*/
|
||||
public static boolean isSupported(DownloadChannel channel) {
|
||||
return isSupported(channel.getService());
|
||||
}
|
||||
}
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @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<Captcha> captchaService;
|
||||
|
||||
@Override
|
||||
public ServiceMode getServiceMode() {
|
||||
return serviceMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Service clone() {
|
||||
try {
|
||||
|
||||
@@ -32,4 +32,14 @@ import java.nio.channels.ReadableByteChannel;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface DownloadChannel extends HttpChannel, ReadableByteChannel {
|
||||
/**
|
||||
* @return the service instance providing this download
|
||||
*/
|
||||
@Override
|
||||
DownloadService<?> getService();
|
||||
|
||||
/**
|
||||
* @return the downloader providing this download
|
||||
*/
|
||||
Downloader<?> getDownloader();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public interface Downloader<C extends DownloaderConfiguration> {
|
||||
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<C extends DownloaderConfiguration> {
|
||||
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)}
|
||||
* <p>
|
||||
* Note that {@link DownloadNotResumableException} is never thrown because
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<ServiceMode> getPossibleServiceModes();
|
||||
|
||||
/**
|
||||
* Sets this service captcha service. CaptchaService are safe to be switched
|
||||
* even after an transfer has begun.
|
||||
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public enum ServiceMode {
|
||||
UNAUTHENTICATED, NON_PREMIUM, PREMIUM;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,41 @@ import com.rogiel.httpchannel.service.Credential;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AuthenticationServices {
|
||||
public static <S extends AuthenticationService<C>, C extends AuthenticatorConfiguration> Authenticator<C> authenticate(
|
||||
/**
|
||||
* Creates a new {@link Credential} with <code>username</code> and
|
||||
* <code>password</code> and creates a new {@link Authenticator} with it and
|
||||
* <code>configuration</code>. {@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 <S extends AuthenticationService<C>, C extends AuthenticatorConfiguration> Authenticator<C> authenticator(
|
||||
S service, C configuration, String username, String password) {
|
||||
return service.getAuthenticator(new Credential(username, password),
|
||||
configuration);
|
||||
}
|
||||
|
||||
public static <S extends AuthenticationService<C>, C extends AuthenticatorConfiguration> Authenticator<C> authenticate(
|
||||
/**
|
||||
* Creates a new {@link Credential} with <code>username</code> and
|
||||
* <code>password</code> 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 <S extends AuthenticationService<C>, C extends AuthenticatorConfiguration> Authenticator<C> authenticator(
|
||||
S service, String username, String password) {
|
||||
return service.getAuthenticator(new Credential(username, password));
|
||||
}
|
||||
|
||||
@@ -25,6 +25,19 @@ import com.rogiel.httpchannel.service.DownloadService;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class DownloadServices {
|
||||
/**
|
||||
* Checks whether the given <code>uri</code> can be downloaded with the
|
||||
* {@link DownloadService} <code>service</code>.
|
||||
*
|
||||
* @param service
|
||||
* the {@link DownloadService}
|
||||
* @param uri
|
||||
* the checking {@link URI}
|
||||
* @return <code>true</code> if this {@link URI} can be downloaded with
|
||||
* <code>service</code>
|
||||
* @throws IOException
|
||||
* if any exception is thrown while checking
|
||||
*/
|
||||
public static boolean canDownload(DownloadService<?> service, URI uri)
|
||||
throws IOException {
|
||||
return service.matchURI(uri);
|
||||
|
||||
@@ -28,18 +28,58 @@ import com.rogiel.httpchannel.service.Uploader.UploaderConfiguration;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class UploadServices {
|
||||
/**
|
||||
* Creates a new {@link Uploader} for the given NIO {@link Path}, using
|
||||
* <code>configuration</code> 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 <S extends UploadService<C>, C extends UploaderConfiguration> Uploader<C> 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 <S extends UploadService<C>, C extends UploaderConfiguration> Uploader<C> upload(
|
||||
S service, Path path) throws IOException {
|
||||
return service.getUploader(path.getFileName().toString(),
|
||||
Files.size(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given <code>service</code> can upload the file
|
||||
* represented by <code>path</code>
|
||||
*
|
||||
* @param service
|
||||
* the upload service
|
||||
* @param path
|
||||
* the file {@link Path}
|
||||
* @return <code>true</code> 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);
|
||||
|
||||
@@ -93,11 +93,13 @@ public class ChannelCopy implements Callable<List<URI>> {
|
||||
*
|
||||
* @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<List<URI>> {
|
||||
.openChannel();
|
||||
|
||||
this.downloadChannel = downloadChannel;
|
||||
this.filename = downloadChannel.getFilename();
|
||||
this.filesize = downloadChannel.getFilesize();
|
||||
this.filename = downloadChannel.filename();
|
||||
this.filesize = downloadChannel.size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> 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();
|
||||
}
|
||||
|
||||
@@ -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<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> 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<NullDownloaderConfiguration> {
|
||||
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
|
||||
|
||||
@@ -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<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<MegaUploadUploaderConfiguration> 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
|
||||
@@ -236,7 +243,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
||||
Downloader<MegaUploadDownloaderConfiguration> {
|
||||
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
|
||||
|
||||
@@ -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<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<MultiUploadUploaderConfiguration> 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<NullDownloaderConfiguration> {
|
||||
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
|
||||
|
||||
@@ -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<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> 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<NullDownloaderConfiguration> implements
|
||||
Downloader<NullDownloaderConfiguration> {
|
||||
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
|
||||
|
||||
@@ -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<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> 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<NullDownloaderConfiguration> implements
|
||||
Downloader<NullDownloaderConfiguration> {
|
||||
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
|
||||
|
||||
@@ -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.
|
||||
@@ -42,7 +44,8 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
||||
// 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 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<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Uploader<ZShareUploaderConfiguration> getUploader(String filename,
|
||||
// long filesize, ZShareUploaderConfiguration configuration) {
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
|
||||
*/
|
||||
public abstract class AbstractDownloader<C extends DownloaderConfiguration>
|
||||
implements Downloader<C> {
|
||||
protected final DownloadService<?> service;
|
||||
/**
|
||||
* The download URI
|
||||
*/
|
||||
@@ -35,12 +36,16 @@ public abstract class AbstractDownloader<C extends DownloaderConfiguration>
|
||||
/**
|
||||
* 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<C extends DownloaderConfiguration>
|
||||
|
||||
protected InputStreamDownloadChannel createInputStreamChannel(
|
||||
InputStream in, long length, String filename) {
|
||||
return new InputStreamDownloadChannel(in, length, filename);
|
||||
return new InputStreamDownloadChannel(service, this, in, length,
|
||||
filename);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,8 +39,9 @@ public abstract class AbstractHttpDownloader<C extends DownloaderConfiguration>
|
||||
extends AbstractDownloader<C> implements Downloader<C> {
|
||||
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) {
|
||||
|
||||
@@ -15,7 +15,17 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadCh
|
||||
*/
|
||||
public abstract class AbstractUploader<C extends UploaderConfiguration>
|
||||
implements Uploader<C> {
|
||||
/**
|
||||
* 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<C extends UploaderConfiguration>
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param service
|
||||
* the upload service
|
||||
* @param filename
|
||||
* the file name
|
||||
* @param filesize
|
||||
@@ -33,7 +45,9 @@ public abstract class AbstractUploader<C extends UploaderConfiguration>
|
||||
* @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<C extends UploaderConfiguration>
|
||||
*/
|
||||
protected LinkedUploadChannel createLinkedChannel(
|
||||
LinkedUploadChannelCloseCallback closeCallback) {
|
||||
return new LinkedUploadChannel(closeCallback, filesize, filename);
|
||||
return new LinkedUploadChannel(service, this, closeCallback, filesize,
|
||||
filename);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user