From 3b2756c528ffa628472cf0b33a440d545607102d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 16 Mar 2013 01:28:18 +0100 Subject: [PATCH] Add finish() method to Connection. --- src/main/java/net/pterodactylus/sonitus/data/Connection.java | 8 ++++++++ .../net/pterodactylus/sonitus/data/filter/ExternalFilter.java | 5 +++++ src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/src/main/java/net/pterodactylus/sonitus/data/Connection.java b/src/main/java/net/pterodactylus/sonitus/data/Connection.java index b8bee32..762ba02 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Connection.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Connection.java @@ -82,4 +82,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; + } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java index c3ab508..3b2b6b1 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java @@ -116,6 +116,11 @@ public abstract class ExternalFilter implements Filter { protected void feed(byte[] buffer) throws IOException { processInput.write(buffer); } + + @Override + protected void finish() throws IOException { + processInput.close(); + } }).start(); } catch (IOException ioe1) { diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java index 5d1ebbc..2ef61e0 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java @@ -64,6 +64,11 @@ public class AudioSink implements Sink { sourceDataLine.write(buffer, 0, buffer.length); logger.finest(String.format("AudioSink: Wrote %d Bytes.", buffer.length)); } + + @Override + protected void finish() { + sourceDataLine.stop(); + } }).start(); } catch (LineUnavailableException lue1) { -- 2.7.4