- logger.info(String.format("Icecast2Sink: Connecting to %s:%d...", server, port));
- final Socket socket = new Socket(server, port);
- logger.info("Icecast2Sink: Connected.");
- final OutputStream socketOutputStream = socket.getOutputStream();
- final InputStream socketInputStream = socket.getInputStream();
-
- sendLine(socketOutputStream, String.format("SOURCE /%s ICE/1.0", mountPoint));
- sendLine(socketOutputStream, String.format("Authorization: Basic %s", generatePassword(password)));
- sendLine(socketOutputStream, String.format("Content-Type: %s", getContentType(source.format())));
- sendLine(socketOutputStream, String.format("ICE-Name: %s", serverName));
- sendLine(socketOutputStream, String.format("ICE-Description: %s", serverDescription));
- sendLine(socketOutputStream, String.format("ICE-Genre: %s", genre));
- sendLine(socketOutputStream, String.format("ICE-Public: %d", publishServer ? 1 : 0));
- sendLine(socketOutputStream, "");
- socketOutputStream.flush();
-
- new Thread(new InputStreamDrainer(socketInputStream)).start();
- new Thread(new Connection(source) {
-
- private long counter;
-
- @Override
- protected int bufferSize() {
- return 4096;
- }
+ Closeables.close(socketOutputStream, true);
+ } catch (IOException e) {
+ /* will never throw. */
+ }
+ }
+
+ @Override
+ public void metadataUpdated(final Metadata metadata) {
+ super.metadataUpdated(metadata);
+ new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ String metadataString = String.format("%s (%s)", metadata.title(), "Sonitus");
+ logger.info(String.format("Updating metadata to %s", metadataString));
+
+ Socket socket = null;
+ OutputStream socketOutputStream = null;
+ try {
+ socket = new Socket(server, port);
+ socketOutputStream = socket.getOutputStream();