1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-05 23:22:51 +00:00

Modularize in maven projects the httpchannel library

This commit creates several maven modules for each segment of the
library. Now it is possible to include only individual services to the
classpath instead of the full library.
This commit is contained in:
2011-10-07 01:41:53 -03:00
parent f39d3100c4
commit 1c8db5cf36
74 changed files with 135 additions and 99 deletions

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

15
.gitignore vendored
View File

@@ -1 +1,14 @@
/target
# Eclipse project files and folders
.project
.metadata
.classpath
.settings/
# Locally stored "Eclipse launch configurations"
*.launch
# Maven target directory
target/
# Find bugs configuration file
/.fbprefs

View File

@@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>seedbox-httpchannel</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View File

@@ -1,13 +0,0 @@
#Sun Sep 11 18:22:22 BRT 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7

View File

@@ -1,5 +0,0 @@
#Tue Sep 13 15:42:20 BRT 2011
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@@ -1,8 +0,0 @@
#Sun Aug 14 13:30:10 BRT 2011
activeProfiles=
eclipse.preferences.version=1
fullBuildGoals=process-test-resources
resolveWorkspaceProjects=true
resourceFilterGoals=process-resources resources\:testResources
skipCompilerPlugin=true
version=1

10
httpchannel-api/pom.xml Normal file
View File

@@ -0,0 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-api</artifactId>
</project>

View File

@@ -36,6 +36,7 @@ public class CapabilityMatrix<T> {
* @param matrix
* all the capabilities this service support
*/
@SafeVarargs
public CapabilityMatrix(T... matrix) {
this.matrix = matrix;
}

View File

@@ -33,6 +33,8 @@ public interface Downloader {
*
* @param listener
* the listener to keep a track on the download progress
* @param position
* the download start position. If seek is supported by service.
*
* @return the {@link DownloadChannel} instance
* @throws IOException
@@ -44,6 +46,7 @@ public interface Downloader {
* if the download limit has been exceed, most times thrown when
* downloading as a non-premium user
*/
DownloadChannel download(DownloadListener listener) throws IOException,
DownloadLinkNotFoundException, DownloadLimitExceededException;
DownloadChannel download(DownloadListener listener, long position)
throws IOException, DownloadLinkNotFoundException,
DownloadLimitExceededException;
}

View File

@@ -21,12 +21,10 @@ import java.io.OutputStream;
import java.nio.channels.Channels;
import java.nio.channels.WritableByteChannel;
import org.apache.http.entity.mime.content.AbstractContentBody;
import org.apache.http.entity.mime.content.ContentBody;
import com.rogiel.httpchannel.service.Uploader;
import com.rogiel.httpchannel.util.ThreadUtils;
/**
* {@link ContentBody} used to upload files in {@link Uploader} implementations.
@@ -53,7 +51,10 @@ public class LinkedUploadChannelContentBody extends AbstractContentBody {
channel.linkChannel(outputChannel);
while (channel.isOpen() && outputChannel.isOpen()) {
ThreadUtils.sleep(500);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}

View File

@@ -0,0 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-hotfile</artifactId>
</project>

View File

@@ -48,8 +48,8 @@ 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.LinkedUploadChannelContentBody;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannelContentBody;
import com.rogiel.httpchannel.service.config.ServiceConfiguration;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.impl.HotFileService.HotFileServiceConfiguration;
@@ -198,7 +198,7 @@ public class HotFileService extends
}
@Override
public DownloadChannel download(DownloadListener listener)
public DownloadChannel download(DownloadListener listener, long position)
throws IOException {
final HTMLPage page = getAsPage(url.toString());

View File

@@ -82,7 +82,7 @@ public class HotFileServiceTest {
final Properties properties = new Properties();
properties.load(new FileInputStream(
"src/test/resources/config/hotfile.properties"));
"src/test/resources/login.properties"));
VALID_USERNAME = properties.getProperty("username");
VALID_PASSWORD = properties.getProperty("password");
}
@@ -161,7 +161,7 @@ public class HotFileServiceTest {
.getDownloader(
new URL(
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
.download(null);
.download(null, 0);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
IOUtils.copy(Channels.newInputStream(channel), bout);
System.out.println(bout.size());
@@ -177,7 +177,7 @@ public class HotFileServiceTest {
.getDownloader(
new URL(
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
.download(null);
.download(null, 0);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
IOUtils.copy(Channels.newInputStream(channel), bout);

View File

@@ -0,0 +1 @@
/login.properties

View File

@@ -0,0 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-megaupload</artifactId>
</project>

View File

@@ -222,7 +222,7 @@ public class MegaUploadService extends
}
@Override
public DownloadChannel download(DownloadListener listener)
public DownloadChannel download(DownloadListener listener, long position)
throws IOException {
HttpResponse response = get(url.toString());
@@ -255,7 +255,7 @@ public class MegaUploadService extends
final String downloadUrl = page
.getLink(DOWNLOAD_DIRECT_LINK_PATTERN);
if (downloadUrl != null && downloadUrl.length() > 0) {
final HttpResponse downloadResponse = get(downloadUrl);
final HttpResponse downloadResponse = get(downloadUrl, position);
if (downloadResponse.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN
|| downloadResponse.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
downloadResponse.getEntity().getContent().close();

View File

@@ -83,7 +83,7 @@ public class MegaUploadServiceTest {
final Properties properties = new Properties();
properties.load(new FileInputStream(
"src/test/resources/config/megaupload.properties"));
"src/test/resources/login.properties"));
VALID_USERNAME = properties.getProperty("username");
VALID_PASSWORD = properties.getProperty("password");
}
@@ -166,7 +166,7 @@ public class MegaUploadServiceTest {
// return true;
return true;
}
});
}, 0);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
IOUtils.copy(Channels.newInputStream(channel), bout);
System.out.println(bout.size());
@@ -186,7 +186,7 @@ public class MegaUploadServiceTest {
System.out.println("Waiting " + time);
return true;
}
});
}, 0);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
IOUtils.copy(Channels.newInputStream(channel), bout);
System.out.println(bout.size());
@@ -208,6 +208,6 @@ public class MegaUploadServiceTest {
System.out.println("Waiting " + time);
return false;
}
});
}, 0);
}
}

View File

@@ -0,0 +1 @@
/login.properties

View File

@@ -0,0 +1,3 @@
This is a simple upload test file.
This is for testing purposes only.

View File

@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service</artifactId>
<packaging>pom</packaging>
<modules>
<module>httpchannel-service-megaupload</module>
<module>httpchannel-service-hotfile</module>
</modules>
<dependencies>
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-util</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

17
httpchannel-util/pom.xml Normal file
View File

@@ -0,0 +1,17 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-util</artifactId>
<dependencies>
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-api</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@@ -72,6 +72,14 @@ public abstract class AbstractHttpService<T extends ServiceConfiguration>
return client.execute(request);
}
protected HttpResponse get(String url, long rangeStart)
throws ClientProtocolException, IOException {
final HttpGet request = new HttpGet(url);
if (rangeStart >= 0)
request.addHeader("Range", "bytes=" + rangeStart + "-");
return client.execute(request);
}
protected String getAsString(String url) throws ClientProtocolException,
IOException {
return HttpClientUtils.toString(get(url));

View File

@@ -1,4 +1,5 @@
/*
* This file is part of seedbox <github.com/seedbox>.
*
* seedbox is free software: you can redistribute it and/or modify

View File

@@ -224,6 +224,9 @@ public class HTMLPage {
}
public int findIntegerInScript(final Pattern pattern, int n) {
String found = findInScript(pattern, n);
if(found == null)
return 0;
return Integer.parseInt(findInScript(pattern, n));
}

View File

@@ -1,10 +0,0 @@
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
log4j.logger.httpclient.wire.header=DEBUG
log4j.logger.org.apache.commons.httpclient=DEBUG

View File

@@ -1,8 +1,8 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rogiel.seedbox</groupId>
<artifactId>seedbox-httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel</artifactId>
<version>1.0.0</version>
<name>Seedbox - HTTP Channel library</name>
<description>Library capable of downloading and uploading files from free servers using channels.</description>
@@ -78,5 +78,9 @@
</dependency>
</dependencies>
<modules>
<module>httpchannel-api</module>
<module>httpchannel-service</module>
<module>httpchannel-util</module>
</modules>
<packaging>pom</packaging>
</project>

View File

@@ -1 +0,0 @@
/config

View File

@@ -1,9 +0,0 @@
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%c] %m%n
log4j.logger.org.apache.http.impl.conn=DEBUG
log4j.logger.org.apache.http.impl.client=DEBUG
log4j.logger.org.apache.http.client=DEBUG