diff --git a/src/main/java/com/rogiel/httpchannel/service/Authenticator.java b/src/main/java/com/rogiel/httpchannel/service/Authenticator.java
index 41d1d8a..5f868ad 100644
--- a/src/main/java/com/rogiel/httpchannel/service/Authenticator.java
+++ b/src/main/java/com/rogiel/httpchannel/service/Authenticator.java
@@ -31,17 +31,15 @@ public interface Authenticator {
* Note: If you want to logout the user, see
* {@link Authenticator#logout()}
*
- * @param listener
- * the listener do keep a track on the authentication progress
+ * @return true if login was successful
*/
- boolean login(AuthenticatorListener listener) throws IOException;
+ boolean login() throws IOException;
/**
* Logout into the {@link Service}. The session is restored to an not
* logged-in state.
*
- * @param listener
- * the listener do keep a track on the logout progress
+ * @return true if logout was successful
*/
- boolean logout(AuthenticatorListener listener) throws IOException;
+ boolean logout() throws IOException;
}
diff --git a/src/main/java/com/rogiel/httpchannel/service/AuthenticatorListener.java b/src/main/java/com/rogiel/httpchannel/service/AuthenticatorListener.java
deleted file mode 100644
index c0e8434..0000000
--- a/src/main/java/com/rogiel/httpchannel/service/AuthenticatorListener.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * This file is part of seedbox .
- *
- * seedbox is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * seedbox is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with seedbox. If not, see .
- */
-package com.rogiel.httpchannel.service;
-
-/**
- * This listener keeps an track on the Authentication process.
- *
- * @author Rogiel
- * @since 1.0
- */
-public interface AuthenticatorListener {
-}
diff --git a/src/main/java/com/rogiel/httpchannel/service/DownloadService.java b/src/main/java/com/rogiel/httpchannel/service/DownloadService.java
index b16fb0b..c33f3f1 100644
--- a/src/main/java/com/rogiel/httpchannel/service/DownloadService.java
+++ b/src/main/java/com/rogiel/httpchannel/service/DownloadService.java
@@ -45,7 +45,7 @@ public interface DownloadService extends Service {
* might or might not perform network activity.
*
* @param url
- * the url to be tested.
+ * the {@link URL} to be tested.
* @return true if supported, false otherwise.
*/
boolean matchURL(URL url);
diff --git a/src/main/java/com/rogiel/httpchannel/service/UploadListener.java b/src/main/java/com/rogiel/httpchannel/service/UploadListener.java
deleted file mode 100644
index a73abf5..0000000
--- a/src/main/java/com/rogiel/httpchannel/service/UploadListener.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * This file is part of seedbox .
- *
- * seedbox is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * seedbox is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with seedbox. If not, see .
- */
-package com.rogiel.httpchannel.service;
-
-/**
- * This listener keeps an track on the progress on an {@link Uploader} service.
- *
- * @author Rogiel
- * @since 1.0
- */
-public interface UploadListener {
- long getFilesize();
-
- String getFilename();
-}
diff --git a/src/main/java/com/rogiel/httpchannel/service/UploadService.java b/src/main/java/com/rogiel/httpchannel/service/UploadService.java
index 41ac7e0..65bd3fe 100644
--- a/src/main/java/com/rogiel/httpchannel/service/UploadService.java
+++ b/src/main/java/com/rogiel/httpchannel/service/UploadService.java
@@ -34,7 +34,7 @@ public interface UploadService extends Service {
* the description of the upload. If supported.
* @return the new {@link Uploader} instance
*/
- Uploader getUploader(String description);
+ Uploader getUploader(String filename, long filesize, String description);
/**
* Get the maximum upload file size supported by this service.
@@ -43,6 +43,15 @@ public interface UploadService extends Service {
*/
long getMaximumFilesize();
+ /**
+ * Get the list of all supported extensions. Might return null if
+ * there is no restriction.
+ *
+ * @return the list of supported file extensions. Can return null
+ * if there is not restriction
+ */
+ String[] getSupportedExtensions();
+
/**
* Return the matrix of capabilities for this {@link Uploader}.
*
diff --git a/src/main/java/com/rogiel/httpchannel/service/Uploader.java b/src/main/java/com/rogiel/httpchannel/service/Uploader.java
index 8a6e300..ceb328d 100644
--- a/src/main/java/com/rogiel/httpchannel/service/Uploader.java
+++ b/src/main/java/com/rogiel/httpchannel/service/Uploader.java
@@ -34,5 +34,5 @@ public interface Uploader {
* thrown if something went wrong
* @throws IOException
*/
- UploadChannel upload(UploadListener listener) throws IOException;
+ UploadChannel upload() throws IOException;
}
diff --git a/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java b/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java
index cdcf32d..2d96cd4 100644
--- a/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java
+++ b/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java
@@ -37,7 +37,6 @@ import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
-import com.rogiel.httpchannel.service.AuthenticatorListener;
import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.DownloadChannel;
@@ -47,7 +46,6 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.UploadChannel;
-import com.rogiel.httpchannel.service.UploadListener;
import com.rogiel.httpchannel.service.UploadListenerContentBody;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -103,8 +101,9 @@ public class HotFileService extends
}
@Override
- public Uploader getUploader(String description) {
- return new HotFileUploader();
+ public Uploader getUploader(String filename, long filesize,
+ String description) {
+ return new HotFileUploader(filename, filesize);
}
@Override
@@ -112,6 +111,11 @@ public class HotFileService extends
return 1 * 1024 * 1024 * 1024;
}
+ @Override
+ public String[] getSupportedExtensions() {
+ return null;
+ }
+
@Override
public CapabilityMatrix getUploadCapabilities() {
return new CapabilityMatrix(
@@ -150,10 +154,19 @@ public class HotFileService extends
protected class HotFileUploader implements Uploader,
LinkedUploadChannelCloseCallback {
+ private final String filename;
+ private final long filesize;
+
private Future uploadFuture;
+ public HotFileUploader(String filename, long filesize) {
+ super();
+ this.filename = filename;
+ this.filesize = filesize;
+ }
+
@Override
- public UploadChannel upload(UploadListener listener) throws IOException {
+ public UploadChannel upload() throws IOException {
final String body = HttpClientUtils.get(client,
"http://www.hotfile.com/");
final String url = PatternUtils.find(UPLOAD_URL_PATTERN, body);
@@ -163,7 +176,7 @@ public class HotFileService extends
upload.setEntity(entity);
final LinkedUploadChannel channel = new LinkedUploadChannel(this,
- listener.getFilesize(), listener.getFilename());
+ filesize, filename);
entity.addPart("uploads[]", new UploadListenerContentBody(channel));
@@ -246,8 +259,7 @@ public class HotFileService extends
}
@Override
- public boolean login(AuthenticatorListener listener)
- throws ClientProtocolException, IOException {
+ public boolean login() throws ClientProtocolException, IOException {
final HttpPost login = new HttpPost(
"http://www.hotfile.com/login.php");
final MultipartEntity entity = new MultipartEntity();
@@ -265,8 +277,7 @@ public class HotFileService extends
}
@Override
- public boolean logout(AuthenticatorListener listener)
- throws IOException {
+ public boolean logout() throws IOException {
final HttpPost logout = new HttpPost(
"http://www.megaupload.com/?c=account");
final MultipartEntity entity = new MultipartEntity();
diff --git a/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java b/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java
index e64472e..09c5b3f 100644
--- a/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java
+++ b/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java
@@ -37,7 +37,6 @@ import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
-import com.rogiel.httpchannel.service.AuthenticatorListener;
import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.DownloadChannel;
@@ -47,7 +46,6 @@ import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.UploadChannel;
-import com.rogiel.httpchannel.service.UploadListener;
import com.rogiel.httpchannel.service.UploadListenerContentBody;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -104,14 +102,20 @@ public class MegaUploadService extends
}
@Override
- public Uploader getUploader(String description) {
- return new MegaUploadUploader(description);
+ public Uploader getUploader(String filename, long filesize,
+ String description) {
+ return new MegaUploadUploader(filename, filesize, description);
}
@Override
public long getMaximumFilesize() {
return 1 * 1024 * 1024 * 1024;
}
+
+ @Override
+ public String[] getSupportedExtensions() {
+ return null;
+ }
@Override
public CapabilityMatrix getUploadCapabilities() {
@@ -151,17 +155,22 @@ public class MegaUploadService extends
protected class MegaUploadUploader implements Uploader,
LinkedUploadChannelCloseCallback {
+ private final String filename;
+ private final long filesize;
private final String description;
private Future uploadFuture;
- public MegaUploadUploader(String description) {
+ public MegaUploadUploader(String filename, long filesize,
+ String description) {
+ this.filename = filename;
+ this.filesize = filesize;
this.description = (description != null ? description
: configuration.getDefaultUploadDescription());
}
@Override
- public UploadChannel upload(UploadListener listener) throws IOException {
+ public UploadChannel upload() throws IOException {
final String body = HttpClientUtils.get(client,
"http://www.megaupload.com/multiupload/");
final String url = PatternUtils.find(UPLOAD_URL_PATTERN, body);
@@ -171,7 +180,7 @@ public class MegaUploadService extends
upload.setEntity(entity);
final LinkedUploadChannel channel = new LinkedUploadChannel(this,
- listener.getFilesize(), listener.getFilename());
+ filesize, filename);
entity.addPart("multifile_0",
new UploadListenerContentBody(channel));
@@ -265,7 +274,7 @@ public class MegaUploadService extends
}
@Override
- public boolean login(AuthenticatorListener listener) throws IOException {
+ public boolean login() throws IOException {
final HttpPost login = new HttpPost(
"http://www.megaupload.com/?c=login");
final MultipartEntity entity = new MultipartEntity();
@@ -283,7 +292,7 @@ public class MegaUploadService extends
}
@Override
- public boolean logout(AuthenticatorListener listener) throws IOException {
+ public boolean logout() throws IOException {
final HttpPost logout = new HttpPost(
"http://www.megaupload.com/?c=account");
final MultipartEntity entity = new MultipartEntity();
diff --git a/src/test/java/com/rogiel/httpchannel/service/impl/HotFileServiceTest.java b/src/test/java/com/rogiel/httpchannel/service/impl/HotFileServiceTest.java
index b93de81..d882c97 100644
--- a/src/test/java/com/rogiel/httpchannel/service/impl/HotFileServiceTest.java
+++ b/src/test/java/com/rogiel/httpchannel/service/impl/HotFileServiceTest.java
@@ -45,13 +45,11 @@ import com.rogiel.httpchannel.service.DownloadListener;
import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.UploadChannel;
-import com.rogiel.httpchannel.service.UploadListener;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.UploaderCapability;
import com.rogiel.httpchannel.service.captcha.Captcha;
import com.rogiel.httpchannel.service.config.ServiceConfigurationHelper;
import com.rogiel.httpchannel.service.impl.HotFileService.HotFileServiceConfiguration;
-import com.rogiel.httpchannel.service.impl.MegaUploadService.MegaUploadServiceConfiguration;
public class HotFileServiceTest {
private Service service;
@@ -95,13 +93,13 @@ public class HotFileServiceTest {
@Test
public void testValidAuthenticator() throws IOException {
Assert.assertTrue(((AuthenticationService) service).getAuthenticator(
- new Credential(VALID_USERNAME, VALID_PASSWORD)).login(null));
+ new Credential(VALID_USERNAME, VALID_PASSWORD)).login());
}
@Test
public void testInvalidAuthenticator() throws IOException {
Assert.assertFalse(((AuthenticationService) service).getAuthenticator(
- new Credential(INVALID_USERNAME, INVALID_PASSWORD)).login(null));
+ new Credential(INVALID_USERNAME, INVALID_PASSWORD)).login());
}
@Test
@@ -111,17 +109,9 @@ public class HotFileServiceTest {
((UploadService) service).getUploadCapabilities().has(
UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD));
final UploadChannel channel = ((UploadService) service).getUploader(
- "Upload by httpchannel").upload(new UploadListener() {
- @Override
- public long getFilesize() {
- return new File("simulado_2010_1_res_all.zip").length();
- }
-
- @Override
- public String getFilename() {
- return "simulado_2010_1_res_all.zip";
- }
- });
+ "simulado_2010_1_res_all.zip",
+ new File("simulado_2010_1_res_all.zip").length(), null)
+ .upload();
final FileChannel fileChannel = new FileInputStream(
"simulado_2010_1_res_all.zip").getChannel();
@@ -141,20 +131,12 @@ public class HotFileServiceTest {
UploaderCapability.PREMIUM_ACCOUNT_UPLOAD));
Assert.assertTrue(((AuthenticationService) service).getAuthenticator(
- new Credential(VALID_USERNAME, VALID_PASSWORD)).login(null));
+ new Credential(VALID_USERNAME, VALID_PASSWORD)).login());
final UploadChannel channel = ((UploadService) service).getUploader(
- "Upload by httpchannel").upload(new UploadListener() {
- @Override
- public long getFilesize() {
- return new File("simulado_2010_1_res_all.zip").length();
- }
-
- @Override
- public String getFilename() {
- return "simulado_2010_1_res_all.zip";
- }
- });
+ "simulado_2010_1_res_all.zip",
+ new File("simulado_2010_1_res_all.zip").length(), null)
+ .upload();
final FileChannel fileChannel = new FileInputStream(
"simulado_2010_1_res_all.zip").getChannel();
@@ -195,10 +177,12 @@ public class HotFileServiceTest {
public void testLoggedInDownloader() throws IOException,
MalformedURLException {
Assert.assertTrue(((AuthenticationService) service).getAuthenticator(
- new Credential(VALID_USERNAME, VALID_PASSWORD)).login(null));
+ new Credential(VALID_USERNAME, VALID_PASSWORD)).login());
final DownloadChannel channel = ((DownloadService) service)
- .getDownloader(new URL("http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
+ .getDownloader(
+ new URL(
+ "http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
.download(new DownloadListener() {
@Override
public boolean timer(long time, TimerWaitReason reason) {
@@ -214,7 +198,7 @@ public class HotFileServiceTest {
return null;
}
});
-
+
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
IOUtils.copy(Channels.newInputStream(channel), bout);
System.out.println(bout.size());
diff --git a/src/test/java/com/rogiel/httpchannel/service/impl/MegaUploadServiceTest.java b/src/test/java/com/rogiel/httpchannel/service/impl/MegaUploadServiceTest.java
index 5e62630..0b40f38 100644
--- a/src/test/java/com/rogiel/httpchannel/service/impl/MegaUploadServiceTest.java
+++ b/src/test/java/com/rogiel/httpchannel/service/impl/MegaUploadServiceTest.java
@@ -42,7 +42,6 @@ import com.rogiel.httpchannel.service.DownloadListener;
import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.UploadChannel;
-import com.rogiel.httpchannel.service.UploadListener;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.UploaderCapability;
import com.rogiel.httpchannel.service.captcha.Captcha;
@@ -91,13 +90,13 @@ public class MegaUploadServiceTest {
@Test
public void testValidAuthenticator() throws IOException {
Assert.assertTrue(((AuthenticationService) service).getAuthenticator(
- new Credential(VALID_USERNAME, VALID_PASSWORD)).login(null));
+ new Credential(VALID_USERNAME, VALID_PASSWORD)).login());
}
@Test
public void testInvalidAuthenticator() throws IOException {
Assert.assertFalse(((AuthenticationService) service).getAuthenticator(
- new Credential(INVALID_USERNAME, INVALID_PASSWORD)).login(null));
+ new Credential(INVALID_USERNAME, INVALID_PASSWORD)).login());
}
@Test
@@ -107,17 +106,7 @@ public class MegaUploadServiceTest {
((UploadService) service).getUploadCapabilities().has(
UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD));
final UploadChannel channel = ((UploadService) service).getUploader(
- "Upload by httpchannel").upload(new UploadListener() {
- @Override
- public long getFilesize() {
- return 10;
- }
-
- @Override
- public String getFilename() {
- return "test.bin";
- }
- });
+ "test.bin", 10, "Upload by httpchannel").upload();
final ByteBuffer buffer = ByteBuffer.allocate(10);
buffer.put((byte) 0x00);
buffer.put((byte) 0x00);
@@ -145,20 +134,10 @@ public class MegaUploadServiceTest {
UploaderCapability.PREMIUM_ACCOUNT_UPLOAD));
Assert.assertTrue(((AuthenticationService) service).getAuthenticator(
- new Credential(VALID_USERNAME, VALID_PASSWORD)).login(null));
+ new Credential(VALID_USERNAME, VALID_PASSWORD)).login());
final UploadChannel channel = ((UploadService) service).getUploader(
- "Upload by httpchannel").upload(new UploadListener() {
- @Override
- public long getFilesize() {
- return 10;
- }
-
- @Override
- public String getFilename() {
- return "test.bin";
- }
- });
+ "test.bin", 10, "Upload by httpchannel").upload();
final ByteBuffer buffer = ByteBuffer.allocate(10);
buffer.put((byte) 0x00);
buffer.put((byte) 0x00);