diff options
author | Björn Hagemeister | 2014-07-10 15:52:27 +0200 |
---|---|---|
committer | Björn Hagemeister | 2014-07-10 15:52:27 +0200 |
commit | 60df6d9e884163f4eeb2d60b0ec0ccf20600825b (patch) | |
tree | 6139c280f63e914739ee0d6fa61f46e581687af4 | |
parent | Checking if socket is null before closing. (diff) | |
download | master-sync-shared-60df6d9e884163f4eeb2d60b0ec0ccf20600825b.tar.gz master-sync-shared-60df6d9e884163f4eeb2d60b0ec0ccf20600825b.tar.xz master-sync-shared-60df6d9e884163f4eeb2d60b0ec0ccf20600825b.zip |
Removed unnessecary TODOs and comments.
4 files changed, 32 insertions, 39 deletions
diff --git a/src/main/java/org/openslx/filetransfer/ClassTest.java b/src/main/java/org/openslx/filetransfer/ClassTest.java index 14fa519..998e3c7 100644 --- a/src/main/java/org/openslx/filetransfer/ClassTest.java +++ b/src/main/java/org/openslx/filetransfer/ClassTest.java @@ -14,8 +14,6 @@ * If master receives token "D" --> start Uploader(socket) */ -// TODO Björn Hagemeister. SSLConfiguration! - package org.openslx.filetransfer; import java.io.File; diff --git a/src/main/java/org/openslx/filetransfer/Downloader.java b/src/main/java/org/openslx/filetransfer/Downloader.java index 2d99c2a..b34401b 100644 --- a/src/main/java/org/openslx/filetransfer/Downloader.java +++ b/src/main/java/org/openslx/filetransfer/Downloader.java @@ -25,7 +25,7 @@ public class Downloader private String RANGE = null; private String outputFilename = null; private String ERROR = null; - + private static Logger log = Logger.getLogger( Downloader.class ); /***********************************************************************/ @@ -39,7 +39,6 @@ public class Downloader public Downloader( String ip, int port, SSLContext context ) { try { - // TODO: Remove old code, that's why we have git.. ;) // create socket. sslSocketFactory = context.getSocketFactory(); @@ -115,8 +114,8 @@ public class Downloader } catch ( IOException e ) { e.printStackTrace(); readMetaData(); - if (ERROR != null) { - if (ERROR == "timeout") { + if ( ERROR != null ) { + if ( ERROR == "timeout" ) { log.info( "Socket timeout occured ... close connection." ); this.close(); } @@ -151,8 +150,8 @@ public class Downloader } catch ( IOException e ) { e.printStackTrace(); readMetaData(); - if (ERROR != null) { - if (ERROR == "timeout") { + if ( ERROR != null ) { + if ( ERROR == "timeout" ) { log.info( "Socket timeout occured ... close connection." ); this.close(); } @@ -283,9 +282,9 @@ public class Downloader return false; } } - } catch (SocketTimeoutException ste) { + } catch ( SocketTimeoutException ste ) { ste.printStackTrace(); - sendErrorCode("timeout"); + sendErrorCode( "timeout" ); log.info( "Socket Timeout occured in Downloader." ); this.close(); } catch ( Exception e ) { @@ -306,8 +305,7 @@ public class Downloader RandomAccessFile file = null; try { int length = getDiffOfRange(); - byte[] incoming = new byte[ 4000 ]; // TODO: größe Problematisch, abchecken. - + byte[] incoming = new byte[ 4000 ]; int hasRead = 0; file = new RandomAccessFile( new File( outputFilename ), "rw" ); file.seek( getStartOfRange() ); @@ -334,7 +332,7 @@ public class Downloader this.close(); return false; } finally { - if (file != null) { + if ( file != null ) { try { file.close(); } catch ( IOException e ) { @@ -374,12 +372,14 @@ public class Downloader public void close() { try { - if (satelliteSocket != null) { + if ( satelliteSocket != null ) { this.satelliteSocket.close(); satelliteSocket = null; } - if (dataFromServer != null) dataFromServer.close(); - if (dataToServer != null) dataToServer.close(); + if ( dataFromServer != null ) + dataFromServer.close(); + if ( dataToServer != null ) + dataToServer.close(); } catch ( IOException e ) { e.printStackTrace(); } diff --git a/src/main/java/org/openslx/filetransfer/Listener.java b/src/main/java/org/openslx/filetransfer/Listener.java index f00f4bc..d325212 100644 --- a/src/main/java/org/openslx/filetransfer/Listener.java +++ b/src/main/java/org/openslx/filetransfer/Listener.java @@ -5,11 +5,7 @@ import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSocket; -import org.apache.log4j.BasicConfigurator; import org.apache.log4j.Logger; -import org.slf4j.LoggerFactory; - -// TODO: (all files) apply formatting using strg+shift+f *after* importing scheme from ./extras/ public class Listener extends Thread { @@ -54,7 +50,6 @@ public class Listener extends Thread while ( !isInterrupted() ) { SSLSocket connectionSocket = (SSLSocket)welcomeSocket.accept(); connectionSocket.setSoTimeout( 2000 ); // 2 second timeout enough? Maybe even use a small thread pool for handling accepted connections - // TODO: Handle SocketTimeoutException for all reads and writes in Downloader and Uploader byte[] b = new byte[ 1 ]; int length = connectionSocket.getInputStream().read( b ); @@ -62,7 +57,7 @@ public class Listener extends Thread System.out.println( "Length (Listener): " + length ); if ( b[0] == U ) { - log.info( "recognized U --> starting Downloader" ); // TODO: Use Logger (see masterserver code for example) + log.info( "recognized U --> starting Downloader" ); // --> start Downloader(socket). Downloader d = new Downloader( connectionSocket ); incomingEvent.incomingDownloader( d ); diff --git a/src/main/java/org/openslx/filetransfer/Uploader.java b/src/main/java/org/openslx/filetransfer/Uploader.java index 716c26b..db41658 100644 --- a/src/main/java/org/openslx/filetransfer/Uploader.java +++ b/src/main/java/org/openslx/filetransfer/Uploader.java @@ -95,7 +95,7 @@ public class Uploader byte[] data = sendToken.getBytes( StandardCharsets.UTF_8 ); dataToServer.writeByte( data.length ); dataToServer.write( data ); - } catch ( SocketTimeoutException ste) { + } catch ( SocketTimeoutException ste ) { ste.printStackTrace(); log.info( "Socket timeout occured ... close connection." ); this.close(); @@ -103,8 +103,8 @@ public class Uploader } catch ( IOException e ) { e.printStackTrace(); readMetaData(); - if (ERROR != null) { - if (ERROR == "timeout") { + if ( ERROR != null ) { + if ( ERROR == "timeout" ) { log.info( "Socket timeout occured ... close connection." ); this.close(); } @@ -149,8 +149,8 @@ public class Uploader } catch ( IOException e ) { e.printStackTrace(); readMetaData(); - if (ERROR != null) { - if (ERROR == "timeout") { + if ( ERROR != null ) { + if ( ERROR == "timeout" ) { log.info( "Socket timeout occured ... close connection." ); this.close(); } @@ -274,9 +274,9 @@ public class Uploader return false; } } - } catch (SocketTimeoutException ste) { + } catch ( SocketTimeoutException ste ) { ste.printStackTrace(); - sendErrorCode("timeout"); + sendErrorCode( "timeout" ); log.info( "Socket timeout occured ... close connection" ); this.close(); } catch ( Exception e ) { @@ -296,15 +296,14 @@ public class Uploader { RandomAccessFile file = null; try { - file = new RandomAccessFile( new File( filename ), "r" ); + file = new RandomAccessFile( new File( filename ), "r" ); if ( getStartOfRange() == -1 ) { - file.close(); return false; } file.seek( getStartOfRange() ); - byte[] data = new byte[ 255 ]; // TODO: problematische Größe. + byte[] data = new byte[ 255 ]; int hasRead = 0; int length = getDiffOfRange(); System.out.println( "diff of Range: " + length ); @@ -318,8 +317,7 @@ public class Uploader hasRead += ret; dataToServer.write( data, 0, ret ); } - file.close(); - } catch ( SocketTimeoutException ste) { + } catch ( SocketTimeoutException ste ) { ste.printStackTrace(); sendErrorCode( "timeout" ); log.info( "Socket timeout occured ... close connection." ); @@ -328,8 +326,8 @@ public class Uploader } catch ( IOException ioe ) { ioe.printStackTrace(); readMetaData(); - if (ERROR != null) { - if (ERROR == "timeout") { + if ( ERROR != null ) { + if ( ERROR == "timeout" ) { log.info( "Socket timeout occured ... close connection." ); this.close(); } @@ -378,12 +376,14 @@ public class Uploader public void close() { try { - if (satelliteSocket != null) { + if ( satelliteSocket != null ) { this.satelliteSocket.close(); satelliteSocket = null; } - if (dataFromServer != null) dataFromServer.close(); - if (dataToServer != null) dataToServer.close(); + if ( dataFromServer != null ) + dataFromServer.close(); + if ( dataToServer != null ) + dataToServer.close(); } catch ( IOException e ) { e.printStackTrace(); } |