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

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