Fix equals().
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / data / Connection.java
index 9377579..169bfa5 100644 (file)
@@ -18,6 +18,8 @@
 package net.pterodactylus.sonitus.data;
 
 import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * A connection reads bytes from a {@link Source} and feeds it to a sink. This
@@ -31,6 +33,9 @@ import java.io.IOException;
  */
 public abstract class Connection implements Runnable {
 
+       /** The logger. */
+       private static final Logger logger = Logger.getLogger(Connection.class.getName());
+
        /** The source to consume. */
        private final Source source;
 
@@ -51,14 +56,22 @@ public abstract class Connection implements Runnable {
        @Override
        public void run() {
                while (true) {
+                       byte[] buffer = null;
+                       try {
+                               buffer = source.get(bufferSize());
+                       } catch (IOException ioe1) {
+                               logger.log(Level.WARNING, "Source died!", ioe1);
+                               break;
+                       }
                        try {
-                               byte[] buffer = source.get(bufferSize());
                                feed(buffer);
                        } catch (IOException ioe1) {
+                               logger.log(Level.WARNING, "Sink died!", ioe1);
                                break;
                        }
                }
                try {
+                       logger.info("Connection finished.");
                        finish();
                } catch (IOException ioe1) {
                        /* well, what can we do? nothing. */