1
0
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:
2012-01-17 23:11:03 -02:00
parent ff4abca387
commit a4c569f10e
29 changed files with 581 additions and 61 deletions

View File

@@ -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());
}
}

View File

@@ -25,7 +25,9 @@ import com.rogiel.httpchannel.captcha.exception.UnsolvableCaptchaServiceExceptio
import com.rogiel.httpchannel.service.exception.NoCaptchaServiceException; 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> * @author <a href="http://www.rogiel.com">Rogiel</a>
* @version 1.0 * @version 1.0
@@ -35,8 +37,22 @@ public abstract class AbstractService implements Service {
* The service {@link Logger} instance * The service {@link Logger} instance
*/ */
protected final Logger logger = LoggerFactory.getLogger(this.getClass()); 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; protected CaptchaService<Captcha> captchaService;
@Override
public ServiceMode getServiceMode() {
return serviceMode;
}
@Override @Override
public Service clone() { public Service clone() {
try { try {

View File

@@ -32,4 +32,14 @@ import java.nio.channels.ReadableByteChannel;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public interface DownloadChannel extends HttpChannel, ReadableByteChannel { public interface DownloadChannel extends HttpChannel, ReadableByteChannel {
/**
* @return the service instance providing this download
*/
@Override
DownloadService<?> getService();
/**
* @return the downloader providing this download
*/
Downloader<?> getDownloader();
} }

View File

@@ -87,7 +87,7 @@ public interface Downloader<C extends DownloaderConfiguration> {
NoCaptchaServiceException; 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)} * see {@link #openChannel(DownloadListener, long)}
* *
* @param position * @param position
@@ -157,7 +157,7 @@ public interface Downloader<C extends DownloaderConfiguration> {
NoCaptchaServiceException; 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)} * start. For more details, see {@link #openChannel(DownloadListener, long)}
* <p> * <p>
* Note that {@link DownloadNotResumableException} is never thrown because * Note that {@link DownloadNotResumableException} is never thrown because

View File

@@ -4,6 +4,7 @@
package com.rogiel.httpchannel.service; package com.rogiel.httpchannel.service;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException;
import java.nio.channels.Channel; import java.nio.channels.Channel;
/** /**
@@ -14,10 +15,15 @@ public interface HttpChannel extends Channel, Closeable {
/** /**
* @return the file size * @return the file size
*/ */
long getFilesize(); long size() throws IOException;
/** /**
* @return the file name * @return the file name
*/ */
String getFilename(); String filename() throws IOException;
/**
* @return the service providing data to this channel
*/
Service getService();
} }

View File

@@ -53,6 +53,23 @@ public interface Service extends Cloneable {
*/ */
int getMinorVersion(); 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 * Sets this service captcha service. CaptchaService are safe to be switched
* even after an transfer has begun. * even after an transfer has begun.

View File

@@ -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;
}

View File

@@ -45,6 +45,17 @@ public interface UploadChannel extends HttpChannel, WritableByteChannel {
*/ */
URI getDownloadLink(); URI getDownloadLink();
/**
* @return the service instance providing this upload
*/
@Override
UploadService<?> getService();
/**
* @return the {@link Uploader} providing this upload
*/
Uploader<?> getUploader();
/** /**
* @throws UploadLinkNotFoundException * @throws UploadLinkNotFoundException
* if after the upload, the download link cannot be found * if after the upload, the download link cannot be found

View File

@@ -14,4 +14,7 @@ import com.rogiel.httpchannel.service.Authenticator.AuthenticatorConfiguration;
public final class NullAuthenticatorConfiguration implements public final class NullAuthenticatorConfiguration implements
AuthenticatorConfiguration { AuthenticatorConfiguration {
public static final NullAuthenticatorConfiguration SHARED_INSTANCE = new NullAuthenticatorConfiguration(); public static final NullAuthenticatorConfiguration SHARED_INSTANCE = new NullAuthenticatorConfiguration();
private NullAuthenticatorConfiguration() {
}
} }

View File

@@ -13,4 +13,7 @@ import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
public final class NullDownloaderConfiguration implements public final class NullDownloaderConfiguration implements
DownloaderConfiguration { DownloaderConfiguration {
public static final NullDownloaderConfiguration SHARED_INSTANCE = new NullDownloaderConfiguration(); public static final NullDownloaderConfiguration SHARED_INSTANCE = new NullDownloaderConfiguration();
private NullDownloaderConfiguration() {
}
} }

View File

@@ -12,4 +12,7 @@ import com.rogiel.httpchannel.service.Uploader.UploaderConfiguration;
*/ */
public final class NullUploaderConfiguration implements UploaderConfiguration { public final class NullUploaderConfiguration implements UploaderConfiguration {
public static final NullUploaderConfiguration SHARED_INSTANCE = new NullUploaderConfiguration(); public static final NullUploaderConfiguration SHARED_INSTANCE = new NullUploaderConfiguration();
private NullUploaderConfiguration() {
}
} }

View File

@@ -25,13 +25,41 @@ import com.rogiel.httpchannel.service.Credential;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class AuthenticationServices { 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) { S service, C configuration, String username, String password) {
return service.getAuthenticator(new Credential(username, password), return service.getAuthenticator(new Credential(username, password),
configuration); 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) { S service, String username, String password) {
return service.getAuthenticator(new Credential(username, password)); return service.getAuthenticator(new Credential(username, password));
} }

View File

@@ -25,6 +25,19 @@ import com.rogiel.httpchannel.service.DownloadService;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class DownloadServices { 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) public static boolean canDownload(DownloadService<?> service, URI uri)
throws IOException { throws IOException {
return service.matchURI(uri); return service.matchURI(uri);

View File

@@ -28,18 +28,58 @@ import com.rogiel.httpchannel.service.Uploader.UploaderConfiguration;
* @author <a href="http://www.rogiel.com">Rogiel</a> * @author <a href="http://www.rogiel.com">Rogiel</a>
*/ */
public class UploadServices { 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( public static <S extends UploadService<C>, C extends UploaderConfiguration> Uploader<C> upload(
S service, C configuration, Path path) throws IOException { S service, C configuration, Path path) throws IOException {
return service.getUploader(path.getFileName().toString(), return service.getUploader(path.getFileName().toString(),
Files.size(path), configuration); 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( public static <S extends UploadService<C>, C extends UploaderConfiguration> Uploader<C> upload(
S service, Path path) throws IOException { S service, Path path) throws IOException {
return service.getUploader(path.getFileName().toString(), return service.getUploader(path.getFileName().toString(),
Files.size(path)); 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) public static boolean canUpload(UploadService<?> service, Path path)
throws IOException { throws IOException {
return service.getMaximumFilesize() >= Files.size(path); return service.getMaximumFilesize() >= Files.size(path);

View File

@@ -93,11 +93,13 @@ public class ChannelCopy implements Callable<List<URI>> {
* *
* @param downloadChannel * @param downloadChannel
* the download channel * the download channel
* @throws IOException
* if any {@link IOException} occur
*/ */
public ChannelCopy(DownloadChannel downloadChannel) { public ChannelCopy(DownloadChannel downloadChannel) throws IOException {
this.downloadChannel = downloadChannel; this.downloadChannel = downloadChannel;
this.filename = downloadChannel.getFilename(); this.filename = downloadChannel.filename();
this.filesize = downloadChannel.getFilesize(); this.filesize = downloadChannel.size();
} }
/** /**
@@ -128,8 +130,8 @@ public class ChannelCopy implements Callable<List<URI>> {
.openChannel(); .openChannel();
this.downloadChannel = downloadChannel; this.downloadChannel = downloadChannel;
this.filename = downloadChannel.getFilename(); this.filename = downloadChannel.filename();
this.filesize = downloadChannel.getFilesize(); this.filesize = downloadChannel.size();
} }
/** /**

View File

@@ -18,6 +18,7 @@ import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Credential; import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.Service; import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID; import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel; import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService; import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader; import com.rogiel.httpchannel.service.Uploader;
@@ -66,6 +67,12 @@ public class DepositFilesService extends AbstractHttpService implements
return 0; return 0;
} }
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
}
@Override @Override
public Uploader<NullUploaderConfiguration> getUploader(String filename, public Uploader<NullUploaderConfiguration> getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) { long filesize, NullUploaderConfiguration configuration) {
@@ -131,7 +138,7 @@ public class DepositFilesService extends AbstractHttpService implements
public UploaderImpl(String filename, long filesize, public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) { NullUploaderConfiguration configuration) {
super(filename, filesize, configuration); super(DepositFilesService.this, filename, filesize, configuration);
} }
@Override @Override
@@ -209,6 +216,7 @@ public class DepositFilesService extends AbstractHttpService implements
captchaService.valid(captcha); captchaService.valid(captcha);
if (!page.contains(VALID_LOGIN_REDIRECT)) if (!page.contains(VALID_LOGIN_REDIRECT))
throw new AuthenticationInvalidCredentialException(); throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return; return;
} }
} }

View File

@@ -32,6 +32,7 @@ import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Credential; import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.Service; import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID; import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel; import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService; import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader; import com.rogiel.httpchannel.service.Uploader;
@@ -81,6 +82,12 @@ public class FileSonicService extends AbstractHttpService implements Service,
return 0; return 0;
} }
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
}
@Override @Override
public Uploader<NullUploaderConfiguration> getUploader(String filename, public Uploader<NullUploaderConfiguration> getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) { long filesize, NullUploaderConfiguration configuration) {
@@ -149,7 +156,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize, public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) { NullUploaderConfiguration configuration) {
super(filename, filesize, configuration); super(FileSonicService.this, filename, filesize, configuration);
} }
@Override @Override
@@ -186,6 +193,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
public void login() throws IOException { public void login() throws IOException {
logger.debug("Logging to filesonic.com"); logger.debug("Logging to filesonic.com");
api.login(credential.getUsername(), credential.getPassword()); api.login(credential.getUsername(), credential.getPassword());
serviceMode = ServiceMode.NON_PREMIUM;
// if (username == null) // if (username == null)
// throw new AuthenticationInvalidCredentialException(); // throw new AuthenticationInvalidCredentialException();
} }

View File

@@ -22,8 +22,6 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
import org.htmlparser.Tag; 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.DownloaderCapability;
import com.rogiel.httpchannel.service.Service; import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID; import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel; import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService; import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader; import com.rogiel.httpchannel.service.Uploader;
import com.rogiel.httpchannel.service.UploaderCapability; 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;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback; import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration; import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
@@ -99,6 +97,12 @@ public class HotFileService extends AbstractHttpService implements Service,
return 0; return 0;
} }
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
}
@Override @Override
public Uploader<NullUploaderConfiguration> getUploader(String filename, public Uploader<NullUploaderConfiguration> getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) { long filesize, NullUploaderConfiguration configuration) {
@@ -191,7 +195,7 @@ public class HotFileService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize, public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) { NullUploaderConfiguration configuration) {
super(filename, filesize, configuration); super(HotFileService.this, filename, filesize, configuration);
} }
@Override @Override
@@ -224,7 +228,7 @@ public class HotFileService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> { AbstractHttpDownloader<NullDownloaderConfiguration> {
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) { public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration); super(HotFileService.this, uri, configuration);
} }
@Override @Override
@@ -251,14 +255,7 @@ public class HotFileService extends AbstractHttpService implements Service,
// final String tmHash = PatternUtils.find(DOWNLOAD_TMHASH_PATTERN, // final String tmHash = PatternUtils.find(DOWNLOAD_TMHASH_PATTERN,
// content);F // content);F
if (downloadUrl != null && downloadUrl.length() > 0) { if (downloadUrl != null && downloadUrl.length() > 0) {
final HttpResponse downloadResponse = get(downloadUrl) return download(get(downloadUrl));
.request();
final String filename = FilenameUtils.getName(downloadUrl);
long contentLength = getContentLength(downloadResponse);
return new InputStreamDownloadChannel(downloadResponse
.getEntity().getContent(), contentLength, filename);
} else { } else {
throw new IOException("Download link not found"); throw new IOException("Download link not found");
} }
@@ -284,6 +281,7 @@ public class HotFileService extends AbstractHttpService implements Service,
final Tag accountTag = page.getTagByID("account"); final Tag accountTag = page.getTagByID("account");
if (accountTag == null) if (accountTag == null)
throw new AuthenticationInvalidCredentialException(); throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
} }
@Override @Override

View File

@@ -42,6 +42,7 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability; import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service; import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID; import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel; import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService; import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader; import com.rogiel.httpchannel.service.Uploader;
@@ -102,6 +103,12 @@ public class MegaUploadService extends AbstractHttpService implements Service,
return 0; return 0;
} }
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
}
@Override @Override
public Uploader<MegaUploadUploaderConfiguration> getUploader( public Uploader<MegaUploadUploaderConfiguration> getUploader(
String filename, long filesize, String filename, long filesize,
@@ -200,7 +207,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize, public UploaderImpl(String filename, long filesize,
MegaUploadUploaderConfiguration configuration) { MegaUploadUploaderConfiguration configuration) {
super(filename, filesize, configuration); super(MegaUploadService.this, filename, filesize, configuration);
} }
@Override @Override
@@ -210,7 +217,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
.asPage(); .asPage();
final String uri = page.findFormAction(UPLOAD_URI_PATTERN); final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URI is {}", uri); logger.debug("Upload URI is {}", uri);
final LinkedUploadChannel channel = createLinkedChannel(this); final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(uri) uploadFuture = multipartPost(uri)
.parameter("multimessage_0", configuration.description()) .parameter("multimessage_0", configuration.description())
@@ -236,7 +243,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
Downloader<MegaUploadDownloaderConfiguration> { Downloader<MegaUploadDownloaderConfiguration> {
public DownloaderImpl(URI uri, public DownloaderImpl(URI uri,
MegaUploadDownloaderConfiguration configuration) { MegaUploadDownloaderConfiguration configuration) {
super(uri, configuration); super(MegaUploadService.this, uri, configuration);
} }
@Override @Override
@@ -313,6 +320,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
String username = page.findScript(LOGIN_USERNAME_PATTERN, 1); String username = page.findScript(LOGIN_USERNAME_PATTERN, 1);
if (username == null) if (username == null)
throw new AuthenticationInvalidCredentialException(); throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
} }
@Override @Override

View File

@@ -23,6 +23,7 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability; import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service; import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID; import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel; import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService; import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader; import com.rogiel.httpchannel.service.Uploader;
@@ -80,6 +81,12 @@ public class MultiUploadService extends AbstractHttpService implements Service,
return 0; return 0;
} }
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
}
@Override @Override
public Uploader<MultiUploadUploaderConfiguration> getUploader( public Uploader<MultiUploadUploaderConfiguration> getUploader(
String filename, long filesize, String filename, long filesize,
@@ -178,7 +185,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize, public UploaderImpl(String filename, long filesize,
MultiUploadUploaderConfiguration configuration) { MultiUploadUploaderConfiguration configuration) {
super(filename, filesize, configuration); super(MultiUploadService.this, filename, filesize, configuration);
} }
@Override @Override
@@ -225,7 +232,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
Downloader<NullDownloaderConfiguration> { Downloader<NullDownloaderConfiguration> {
protected DownloaderImpl(URI uri, protected DownloaderImpl(URI uri,
NullDownloaderConfiguration configuration) { NullDownloaderConfiguration configuration) {
super(uri, configuration); super(MultiUploadService.this, uri, configuration);
} }
@Override @Override
@@ -258,6 +265,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
if (!page.containsIgnoreCase(credential.getUsername())) if (!page.containsIgnoreCase(credential.getUsername()))
throw new AuthenticationInvalidCredentialException(); throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
} }
@Override @Override

View File

@@ -24,6 +24,7 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability; import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service; import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID; import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel; import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService; import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader; import com.rogiel.httpchannel.service.Uploader;
@@ -82,6 +83,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
return 0; return 0;
} }
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
}
@Override @Override
public Uploader<NullUploaderConfiguration> getUploader(String filename, public Uploader<NullUploaderConfiguration> getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) { long filesize, NullUploaderConfiguration configuration) {
@@ -177,7 +184,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize, public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) { NullUploaderConfiguration configuration) {
super(filename, filesize, configuration); super(UploadHereService.this, filename, filesize, configuration);
} }
@Override @Override
@@ -223,7 +230,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
AbstractHttpDownloader<NullDownloaderConfiguration> implements AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> { Downloader<NullDownloaderConfiguration> {
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) { public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration); super(UploadHereService.this, uri, configuration);
} }
@Override @Override
@@ -288,6 +295,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
.parameter("password", credential.getPassword()).asPage(); .parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING)) if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException(); throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
} }
@Override @Override

View File

@@ -24,6 +24,7 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability; import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service; import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID; import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel; import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService; import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader; import com.rogiel.httpchannel.service.Uploader;
@@ -82,6 +83,12 @@ public class UploadKingService extends AbstractHttpService implements Service,
return 0; return 0;
} }
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
}
@Override @Override
public Uploader<NullUploaderConfiguration> getUploader(String filename, public Uploader<NullUploaderConfiguration> getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) { long filesize, NullUploaderConfiguration configuration) {
@@ -177,7 +184,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
public UploaderImpl(String filename, long filesize, public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) { NullUploaderConfiguration configuration) {
super(filename, filesize, configuration); super(UploadKingService.this, filename, filesize, configuration);
} }
@Override @Override
@@ -220,7 +227,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
AbstractHttpDownloader<NullDownloaderConfiguration> implements AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> { Downloader<NullDownloaderConfiguration> {
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) { public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration); super(UploadKingService.this, uri, configuration);
} }
@Override @Override
@@ -287,6 +294,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
.parameter("password", credential.getPassword()).asPage(); .parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING)) if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException(); throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
} }
@Override @Override

View File

@@ -1,8 +1,10 @@
package com.rogiel.httpchannel.service.impl; package com.rogiel.httpchannel.service.impl;
import com.rogiel.httpchannel.service.AbstractHttpService; import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Service; import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID; import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
/** /**
* This service handles uploads to UploadKing.com. * This service handles uploads to UploadKing.com.
@@ -35,14 +37,15 @@ public class ZShareService extends AbstractHttpService implements Service/*
// Pattern.CASE_INSENSITIVE); // Pattern.CASE_INSENSITIVE);
// private static final Pattern DOWNLOAD_ID_PATTERN = Pattern // private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
// .compile("\"downloadid\":\"([0-9a-zA-Z]*)\""); // .compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
// private static final Pattern DOWNLOAD_URI_PATTERN = Pattern // private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
// .compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*"); // .compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
// private static final Pattern TIMER_PATTERN = Pattern.compile( // private static final Pattern TIMER_PATTERN = Pattern.compile(
// "count = ([0-9]*);", Pattern.COMMENTS); // "count = ([0-9]*);", Pattern.COMMENTS);
// private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern // private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
// .compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\""); // .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 @Override
public ServiceID getServiceID() { public ServiceID getServiceID() {
@@ -59,6 +62,16 @@ public class ZShareService extends AbstractHttpService implements Service/*
return 0; return 0;
} }
@Override
public ServiceMode getServiceMode() {
return null;
}
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>();
}
// @Override // @Override
// public Uploader<ZShareUploaderConfiguration> getUploader(String filename, // public Uploader<ZShareUploaderConfiguration> getUploader(String filename,
// long filesize, ZShareUploaderConfiguration configuration) { // long filesize, ZShareUploaderConfiguration configuration) {

View File

@@ -22,6 +22,7 @@ import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
*/ */
public abstract class AbstractDownloader<C extends DownloaderConfiguration> public abstract class AbstractDownloader<C extends DownloaderConfiguration>
implements Downloader<C> { implements Downloader<C> {
protected final DownloadService<?> service;
/** /**
* The download URI * The download URI
*/ */
@@ -35,12 +36,16 @@ public abstract class AbstractDownloader<C extends DownloaderConfiguration>
/** /**
* Creates a new instance * Creates a new instance
* *
* @param service
* the download service
* @param uri * @param uri
* the download uri * the download uri
* @param configuration * @param configuration
* the configuration object * the configuration object
*/ */
protected AbstractDownloader(URI uri, C configuration) { protected AbstractDownloader(DownloadService<?> service, URI uri,
C configuration) {
this.service = service;
this.uri = uri; this.uri = uri;
this.configuration = configuration; this.configuration = configuration;
} }
@@ -69,7 +74,8 @@ public abstract class AbstractDownloader<C extends DownloaderConfiguration>
protected InputStreamDownloadChannel createInputStreamChannel( protected InputStreamDownloadChannel createInputStreamChannel(
InputStream in, long length, String filename) { InputStream in, long length, String filename) {
return new InputStreamDownloadChannel(in, length, filename); return new InputStreamDownloadChannel(service, this, in, length,
filename);
} }
@Override @Override

View File

@@ -38,9 +38,10 @@ import com.rogiel.httpchannel.util.ThreadUtils;
public abstract class AbstractHttpDownloader<C extends DownloaderConfiguration> public abstract class AbstractHttpDownloader<C extends DownloaderConfiguration>
extends AbstractDownloader<C> implements Downloader<C> { extends AbstractDownloader<C> implements Downloader<C> {
private final Logger logger = LoggerFactory.getLogger(this.getClass()); private final Logger logger = LoggerFactory.getLogger(this.getClass());
protected AbstractHttpDownloader(URI uri, C configuration) { protected AbstractHttpDownloader(DownloadService<?> service, URI uri,
super(uri, configuration); C configuration) {
super(service, uri, configuration);
} }
protected long getContentLength(HttpResponse response) { protected long getContentLength(HttpResponse response) {

View File

@@ -15,7 +15,17 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadCh
*/ */
public abstract class AbstractUploader<C extends UploaderConfiguration> public abstract class AbstractUploader<C extends UploaderConfiguration>
implements Uploader<C> { implements Uploader<C> {
/**
* The upload service
*/
protected final UploadService<?> service;
/**
* The name of the file to be uploaded
*/
protected final String filename; protected final String filename;
/**
* The size of the file to be uploaded
*/
protected final long filesize; protected final long filesize;
/** /**
@@ -26,6 +36,8 @@ public abstract class AbstractUploader<C extends UploaderConfiguration>
/** /**
* Creates a new instance * Creates a new instance
* *
* @param service
* the upload service
* @param filename * @param filename
* the file name * the file name
* @param filesize * @param filesize
@@ -33,7 +45,9 @@ public abstract class AbstractUploader<C extends UploaderConfiguration>
* @param configuration * @param configuration
* the configuration object * 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.filename = filename;
this.filesize = filesize; this.filesize = filesize;
this.configuration = configuration; this.configuration = configuration;
@@ -48,7 +62,8 @@ public abstract class AbstractUploader<C extends UploaderConfiguration>
*/ */
protected LinkedUploadChannel createLinkedChannel( protected LinkedUploadChannel createLinkedChannel(
LinkedUploadChannelCloseCallback closeCallback) { LinkedUploadChannelCloseCallback closeCallback) {
return new LinkedUploadChannel(closeCallback, filesize, filename); return new LinkedUploadChannel(service, this, closeCallback, filesize,
filename);
} }
@Override @Override

View File

@@ -23,7 +23,8 @@ import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import com.rogiel.httpchannel.service.DownloadChannel; 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> * @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -32,11 +33,17 @@ import com.rogiel.httpchannel.service.DownloadChannel;
public class InputStreamDownloadChannel implements DownloadChannel { public class InputStreamDownloadChannel implements DownloadChannel {
private final ReadableByteChannel channel; private final ReadableByteChannel channel;
private final DownloadService<?> service;
private final Downloader<?> downloader;
private final long length; private final long length;
private final String filename; 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) { final String filename) {
this.service = service;
this.downloader = downloader;
this.channel = Channels.newChannel(in); this.channel = Channels.newChannel(in);
this.length = length; this.length = length;
this.filename = filename; this.filename = filename;
@@ -58,12 +65,22 @@ public class InputStreamDownloadChannel implements DownloadChannel {
} }
@Override @Override
public long getFilesize() { public long size() {
return length; return length;
} }
@Override @Override
public String getFilename() { public String filename() {
return filename; return filename;
} }
@Override
public DownloadService<?> getService() {
return service;
}
@Override
public Downloader<?> getDownloader() {
return downloader;
}
} }

View File

@@ -27,6 +27,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.rogiel.httpchannel.service.UploadChannel; 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; import com.rogiel.httpchannel.service.exception.UploadLinkNotFoundException;
/** /**
@@ -41,6 +43,15 @@ public class LinkedUploadChannel implements UploadChannel {
*/ */
private final Logger logger = LoggerFactory.getLogger(this.getClass()); 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 * The destionation {@link Channel}. Data writted is forwarded to this
* channel. * channel.
@@ -69,8 +80,11 @@ public class LinkedUploadChannel implements UploadChannel {
*/ */
private boolean open = true; private boolean open = true;
public LinkedUploadChannel(LinkedUploadChannelCloseCallback closeCallback, public LinkedUploadChannel(UploadService<?> service, Uploader<?> uploader,
long filesize, String filename) { LinkedUploadChannelCloseCallback closeCallback, long filesize,
String filename) {
this.service = service;
this.uploader = uploader;
this.closeCallback = closeCallback; this.closeCallback = closeCallback;
this.filename = filename; this.filename = filename;
this.length = filesize; this.length = filesize;
@@ -110,12 +124,12 @@ public class LinkedUploadChannel implements UploadChannel {
} }
@Override @Override
public long getFilesize() { public long size() {
return length; return length;
} }
@Override @Override
public String getFilename() { public String filename() {
return filename; return filename;
} }
@@ -124,6 +138,16 @@ public class LinkedUploadChannel implements UploadChannel {
return downloadLink; 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 * Links this {@link Channel} to the destionation {@link Channel}. All data
* written in this channel will be redirected to the destination * written in this channel will be redirected to the destination

View File

@@ -42,7 +42,7 @@ public class LinkedUploadChannelContentBody extends AbstractContentBody {
@Override @Override
public String getFilename() { public String getFilename() {
return channel.getFilename(); return channel.filename();
} }
@Override @Override
@@ -64,7 +64,7 @@ public class LinkedUploadChannelContentBody extends AbstractContentBody {
@Override @Override
public long getContentLength() { public long getContentLength() {
return channel.getFilesize(); return channel.size();
} }
@Override @Override