1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-08 08:32:51 +00:00

Implements uploadhere.com service

This commit is contained in:
2012-01-15 20:23:01 -02:00
parent 23f80b50e6
commit 1719e54b77
34 changed files with 790 additions and 429 deletions

View File

@@ -86,7 +86,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
MultiUploadUploaderConfiguration configuration) {
if (configuration == null)
configuration = new MultiUploadUploaderConfiguration();
return new MultiUploadUploader(filename, filesize, configuration);
return new UploaderImpl(filename, filesize, configuration);
}
@Override
@@ -121,7 +121,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
NullDownloaderConfiguration configuration) {
return new MultiUploaderDownloader(url, configuration);
return new DownloaderImpl(url, configuration);
}
@Override
@@ -151,7 +151,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public Authenticator<NullAuthenticatorConfiguration> getAuthenticator(
Credential credential, NullAuthenticatorConfiguration configuration) {
return new MultiUploadAuthenticator(credential, configuration);
return new AuthenticatorImpl(credential, configuration);
}
@Override
@@ -170,13 +170,13 @@ public class MultiUploadService extends AbstractHttpService implements Service,
return new CapabilityMatrix<AuthenticatorCapability>();
}
protected class MultiUploadUploader extends
protected class UploaderImpl extends
AbstractUploader<MultiUploadUploaderConfiguration> implements
Uploader<MultiUploadUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
private Future<String> uploadFuture;
public MultiUploadUploader(String filename, long filesize,
public UploaderImpl(String filename, long filesize,
MultiUploadUploaderConfiguration configuration) {
super(filename, filesize, configuration);
}
@@ -216,10 +216,10 @@ public class MultiUploadService extends AbstractHttpService implements Service,
}
}
protected class MultiUploaderDownloader extends
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> {
protected MultiUploaderDownloader(URL url,
protected DownloaderImpl(URL url,
NullDownloaderConfiguration configuration) {
super(url, configuration);
}
@@ -237,10 +237,10 @@ public class MultiUploadService extends AbstractHttpService implements Service,
}
}
protected class MultiUploadAuthenticator extends
protected class AuthenticatorImpl extends
AbstractAuthenticator<NullAuthenticatorConfiguration> implements
Authenticator<NullAuthenticatorConfiguration> {
public MultiUploadAuthenticator(Credential credential,
public AuthenticatorImpl(Credential credential,
NullAuthenticatorConfiguration configuration) {
super(credential, configuration);
}

View File

@@ -4,10 +4,10 @@ import java.util.EnumSet;
import com.rogiel.httpchannel.service.Uploader.DescriptionableUploaderConfiguration;
import com.rogiel.httpchannel.service.Uploader.UploaderConfiguration;
import com.rogiel.httpchannel.service.impl.MultiUploadService.MultiUploadUploader;
import com.rogiel.httpchannel.service.impl.MultiUploadService.UploaderImpl;
/**
* Describes an configuration for an {@link MultiUploadUploader}
* Describes an configuration for an {@link UploaderImpl}
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/

View File

@@ -1,32 +1,68 @@
package com.rogiel.httpchannel.service.impl;
import java.net.MalformedURLException;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import com.rogiel.httpchannel.service.AbstractServiceTest;
import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.Service;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class MultiUploadServiceTest extends AbstractServiceTest {
@Override
protected Service createService() {
return new MultiUploadService();
import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.util.ChannelUtils;
public class MultiUploadServiceTest {
public static final Path TEST_UPLOAD_FILE = Paths
.get("src/test/resources/upload-test-file.txt");
public static final byte[] EXPECTED_FULL_CHECKSUM = new byte[] { 27, -93,
-76, 6, 123, -31, -9, 1, -100, 103, 123, -108, -22, -3, 121, -54,
-127, 27, 43, -8 };
public static final byte[] EXPECTED_RESUME_CHECKSUM = new byte[] { 39, -29,
-107, -76, -69, -122, -20, 78, -27, -60, 95, -23, 70, -127, -17,
101, -39, -87, -2, -67 };
private MultiUploadService service;
@Before
public void setUp() throws Exception {
this.service = new MultiUploadService();
}
@Override
protected URL createDownloadURL() throws MalformedURLException {
return new URL("http://www.multiupload.com/QPDUXJDZZY");
@Test
public void testUploader() throws IOException {
final URL url = ChannelUtils.upload(service, TEST_UPLOAD_FILE);
Assert.assertNotNull(url);
System.out.println("Uploaded file to " + url);
}
@Override
protected Credential createValidCredential() {
return null;
@Test
public void testDownloader() throws IOException, NoSuchAlgorithmException {
final byte[] data = ChannelUtils
.toByteArray(((DownloadService<?>) service).getDownloader(
new URL("http://www.multiupload.com/TJOYWB4JEW"))
.openChannel());
assertChecksum("Downloaded data checksum did not matched", "SHA1",
data, EXPECTED_FULL_CHECKSUM);
}
@Override
protected Credential createInvalidCredential() {
return new Credential("invalid-"
+ Double.toString(Math.random() * 1000), Double.toString(Math
.random() * Integer.MAX_VALUE));
@Test
public void testDownloaderResume() throws IOException,
NoSuchAlgorithmException {
final byte[] data = ChannelUtils
.toByteArray(((DownloadService<?>) service).getDownloader(
new URL("http://www.multiupload.com/TJOYWB4JEW"))
.openChannel(50));
assertChecksum("Downloaded data checksum did not matched", "SHA1",
data, EXPECTED_RESUME_CHECKSUM);
}
public static void assertChecksum(String message, String algorithm,
byte[] data, byte[] expected) throws NoSuchAlgorithmException {
final MessageDigest md = MessageDigest.getInstance(algorithm);
final byte[] actual = md.digest(data);
Assert.assertArrayEquals(message, expected, actual);
}
}