- public void connect(Source source) throws ConnectException {
- checkNotNull(source, "source must not be null");
-
- this.source = source;
- try {
- 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.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));
- 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;
- }
-
- @Override
- protected void feed(byte[] buffer) throws IOException {
- socketOutputStream.write(buffer);
- socketOutputStream.flush();
- counter += buffer.length;
- logger.finest(String.format("Wrote %d Bytes.", counter));
- }