summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/filetransfer/Downloader.java
diff options
context:
space:
mode:
authorSimon Rettberg2015-06-05 11:25:50 +0200
committerSimon Rettberg2015-06-05 11:25:50 +0200
commit693392fe6c0022e7ec5060192ee322c7753b0d90 (patch)
tree855245927778c6b069714909929684d1da7d449f /src/main/java/org/openslx/filetransfer/Downloader.java
parentCleanup thrift shandling stuff (diff)
downloadmaster-sync-shared-693392fe6c0022e7ec5060192ee322c7753b0d90.tar.gz
master-sync-shared-693392fe6c0022e7ec5060192ee322c7753b0d90.tar.xz
master-sync-shared-693392fe6c0022e7ec5060192ee322c7753b0d90.zip
Changes for Dozmod v1.1
Diffstat (limited to 'src/main/java/org/openslx/filetransfer/Downloader.java')
-rw-r--r--src/main/java/org/openslx/filetransfer/Downloader.java29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/org/openslx/filetransfer/Downloader.java b/src/main/java/org/openslx/filetransfer/Downloader.java
index 00c6f69..20a50e6 100644
--- a/src/main/java/org/openslx/filetransfer/Downloader.java
+++ b/src/main/java/org/openslx/filetransfer/Downloader.java
@@ -4,9 +4,9 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.net.Socket;
import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocket;
import org.apache.log4j.Logger;
@@ -38,11 +38,20 @@ public class Downloader extends Transfer
* @param socket established connection to peer which requested an upload.
* @throws IOException
*/
- protected Downloader( SSLSocket socket ) throws IOException
+ protected Downloader( Socket socket ) throws IOException
{
super( socket, log );
}
+ /**
+ * Initiate the download. This method does not return until the file transfer finished.
+ *
+ * @param destinationFile destination file name to download to
+ * @param rangeCallback this object's .get() method is called whenever the downloader needs to
+ * know which part of the file to request next. This method should return null if no
+ * more parts are needed, which in turn let's this method return true
+ * @return true on success, false otherwise
+ */
public boolean download( final String destinationFile, final WantRangeCallback callback )
{
RandomAccessFile file = null;
@@ -69,14 +78,20 @@ public class Downloader extends Transfer
};
return download( cb, callback );
} finally {
- if ( file != null )
- try {
- file.close();
- } catch ( IOException e ) {
- }
+ Transfer.safeClose( file );
}
}
+ /**
+ * Initiate the download. This method does not return until the file transfer finished.
+ *
+ * @param dataCallback this object's .dataReceived() method is called whenever a chunk of data is
+ * received
+ * @param rangeCallback this object's .get() method is called whenever the downloader needs to
+ * know which part of the file to request next. This method should return null if no
+ * more parts are needed, which in turn let's this method return true
+ * @return true on success, false otherwise
+ */
public boolean download( DataReceivedCallback dataCallback, WantRangeCallback rangeCallback )
{
if ( shouldGetToken() ) {