import net.pterodactylus.sonitus.data.ConnectException;
import net.pterodactylus.sonitus.data.Connection;
-import net.pterodactylus.sonitus.data.Format;
import net.pterodactylus.sonitus.data.Metadata;
import net.pterodactylus.sonitus.data.Sink;
import net.pterodactylus.sonitus.data.Source;
this.source = source;
try {
- logger.info(String.format("Icecast2Sink: Connecting to %s:%d...", server, port));
+ logger.info(String.format("Connecting to %s:%d...", server, port));
final Socket socket = new Socket(server, port);
- logger.info("Icecast2Sink: Connected.");
+ logger.info("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("Content-Type: %s", getContentType(source.metadata())));
sendLine(socketOutputStream, String.format("ICE-Name: %s", serverName));
sendLine(socketOutputStream, String.format("ICE-Description: %s", serverDescription));
sendLine(socketOutputStream, String.format("ICE-Genre: %s", genre));
@Override
protected void finish() throws IOException {
Closeables.close(socketOutputStream, true);
- Closeables.close(socket, true);
+ if (socket != null) {
+ socket.close();
+ }
}
}).start();
} finally {
try {
Closeables.close(socketOutputStream, true);
- Closeables.close(socket, true);
+ if (socket != null) {
+ socket.close();
+ }
} catch (IOException ioe1) {
- /* ignore, will not happen. */
+ /* ignore. */
}
}
}
}
/**
- * Returns a MIME type for the given format. Currently only Vorbis, MP3, and
+ * Returns a MIME type for the given metadata. Currently only Vorbis, MP3, and
* PCM formats are recognized.
*
- * @param format
- * The format to get a MIME type for
- * @return The MIME type of the format
+ * @param metadata
+ * The metadata to get a MIME type for
+ * @return The MIME type of the metadata
*/
- private static String getContentType(Format format) {
- String encoding = format.encoding();
+ private static String getContentType(Metadata metadata) {
+ String encoding = metadata.encoding();
if ("Vorbis".equalsIgnoreCase(encoding)) {
return "audio/ogg";
}