@@ -0,0 +1,1957 @@
+package net.kencochrane.raven.connection;%0A%0Aimport net.kencochrane.raven.event.LoggedEvent;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.OutputStream;%0Aimport java.net.DatagramPacket;%0Aimport java.net.DatagramSocket;%0Aimport java.net.InetSocketAddress;%0Aimport java.net.SocketException;%0Aimport java.nio.charset.Charset;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0A/**%0A * Connection to a Sentry server through an UDP connection.%0A */%0Apublic class UdpConnection extends AbstractConnection %7B%0A    private static final Logger logger = Logger.getLogger(UdpConnection.class.getCanonicalName());%0A    private DatagramSocket socket;%0A    private Charset charset = Charset.defaultCharset();%0A%0A    public UdpConnection(Dsn dsn) %7B%0A        super(dsn);%0A        openSocket();%0A    %7D%0A%0A    @Override%0A    public void send(LoggedEvent event) %7B%0A        try %7B%0A            ByteArrayOutputStream baos = new ByteArrayOutputStream();%0A            writeHeader(baos);%0A            baos.flush();%0A            baos.close();%0A%0A            byte%5B%5D message = baos.toByteArray();%0A            DatagramPacket packet = new DatagramPacket(message, message.length);%0A            socket.send(packet);%0A        %7D catch (IOException e) %7B%0A            logger.log(Level.SEVERE,%0A                    %22An exception occurred while trying to establish a connection to the sentry server%22);%0A        %7D%0A    %7D%0A%0A    private void writeHeader(OutputStream os) throws IOException %7B%0A        os.write(getAuthHeader().getBytes(charset));%0A        os.write(%22%5Cn%5Cn%22.getBytes(charset));%0A    %7D%0A%0A    private void openSocket() %7B%0A        try %7B%0A            socket = new DatagramSocket();%0A            socket.connect(new InetSocketAddress(getDsn().getHost(), getDsn().getPort()));%0A        %7D catch (SocketException e) %7B%0A            throw new IllegalStateException(%22The UDP connection couldn't be used, impossible to send anything %22 +%0A                    %22to sentry%22, e);%0A        %7D%0A    %7D%0A%7D%0A

Create UDP connections