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
*/
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;
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. */
+ }
}
//
*/
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;
+
}