X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fdata%2FConnection.java;h=8ea1a55a40bb3f74f1177367ade7160bad1e47ff;hb=ee261ec959322c6d1969aff67319559ba1480859;hp=b8bee320bc8f434341e17e4ca395f1195f97d1c0;hpb=3c80e17df7d3404a853c8782de55467be48d6ba1;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/data/Connection.java b/src/main/java/net/pterodactylus/sonitus/data/Connection.java index b8bee32..8ea1a55 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Connection.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Connection.java @@ -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; @@ -54,10 +59,17 @@ public abstract class Connection implements Runnable { try { byte[] buffer = source.get(bufferSize()); feed(buffer); - } catch (IOException e) { - return; + } 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. */ + } } // @@ -82,4 +94,12 @@ public abstract class Connection implements Runnable { */ protected abstract void feed(byte[] buffer) throws IOException; + /** + * Notifies the sink that the source does not deliver any more data. + * + * @throws IOException + * if an I/O error occurs + */ + protected abstract void finish() throws IOException; + }