summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/filetransfer/Downloader.java
diff options
context:
space:
mode:
authorBjörn Hagemeister2014-07-02 16:22:54 +0200
committerBjörn Hagemeister2014-07-02 16:22:54 +0200
commit2af7714e8672797677628bea1ece6f62bbe75c89 (patch)
treefbaf28cdebd1b9dd5aa01714a0005f6f4422ecf3 /src/main/java/org/openslx/filetransfer/Downloader.java
parentAdd getter for port in Listener (diff)
downloadmaster-sync-shared-2af7714e8672797677628bea1ece6f62bbe75c89.tar.gz
master-sync-shared-2af7714e8672797677628bea1ece6f62bbe75c89.tar.xz
master-sync-shared-2af7714e8672797677628bea1ece6f62bbe75c89.zip
new method for sending error string, usefull for wrong token.
Diffstat (limited to 'src/main/java/org/openslx/filetransfer/Downloader.java')
-rw-r--r--src/main/java/org/openslx/filetransfer/Downloader.java50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/main/java/org/openslx/filetransfer/Downloader.java b/src/main/java/org/openslx/filetransfer/Downloader.java
index 176b874..58e32f9 100644
--- a/src/main/java/org/openslx/filetransfer/Downloader.java
+++ b/src/main/java/org/openslx/filetransfer/Downloader.java
@@ -3,12 +3,10 @@ package org.openslx.filetransfer;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
-import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
@@ -16,8 +14,6 @@ import java.security.cert.CertificateException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
public class Downloader {
// Some instance variables.
@@ -28,6 +24,7 @@ public class Downloader {
private String TOKEN = null;
private String RANGE = null;
private String outputFilename = null;
+ private String ERROR = null;
/***********************************************************************//**
* Constructor for satellite downloader.
@@ -228,10 +225,17 @@ public class Downloader {
RANGE = splitted[1];
System.out.println("RANGE: '" + RANGE + "'");
}
+ else if (splitted[0].equals("ERROR")) {
+ if (splitted[1] != null)
+ ERROR = splitted[1];
+ System.err.println("ERROR: " + ERROR);
+ this.close();
+ return false;
+ }
}
- } catch (IOException e) {
- throw e;
- // return false;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
}
return true;
}
@@ -255,17 +259,37 @@ public class Downloader {
hasRead += ret;
}
- RandomAccessFile file = new RandomAccessFile(new File(outputFilename), "rw");
- file.seek(getStartOfRange());
- file.write(incoming, 0, length);
- file.close();
+ RandomAccessFile file;
+ try {
+ file = new RandomAccessFile(new File(outputFilename), "rw");
+ file.seek(getStartOfRange());
+ file.write(incoming, 0, length);
+ file.close();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
return true;
}
/***********************************************************************//**
+ * Method for sending error Code to server. For example in case of wrong
+ * token, send code for wrong token.
+ * @throws IOException
+ */
+ public void sendErrorCode(String errString) throws IOException {
+ String sendError = "ERROR=" + errString;
+ byte[] data = sendError.getBytes(StandardCharsets.UTF_8);
+ dataToServer.writeByte(data.length);
+ dataToServer.write(data);
+ }
+
+ /***********************************************************************//**
* Method for closing connection, if download has finished.
+ * @throws IOException
*/
- public void close() {
-
+ public void close() throws IOException {
+ this.satelliteSocket.close();
}
}