Add finish() method to Connection.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 16 Mar 2013 00:28:18 +0000 (01:28 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 16 Mar 2013 00:28:18 +0000 (01:28 +0100)
src/main/java/net/pterodactylus/sonitus/data/Connection.java
src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java
src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java

index b8bee32..762ba02 100644 (file)
@@ -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;
+
 }
index c3ab508..3b2b6b1 100644 (file)
@@ -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) {
 
index 5d1ebbc..2ef61e0 100644 (file)
@@ -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) {