Search in sources :

Example 1 with CarbonException

use of com.peterphi.carbon.exception.CarbonException in project stdlib by petergeneric.

the class CarbonClientImpl method serialise.

private static byte[] serialise(Element element) {
    try {
        final ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
        new XMLOutputter().output(element, bos);
        return bos.toByteArray();
    } catch (IOException e) {
        throw new CarbonException(e.getMessage(), e);
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) CarbonException(com.peterphi.carbon.exception.CarbonException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with CarbonException

use of com.peterphi.carbon.exception.CarbonException in project stdlib by petergeneric.

the class CarbonClientImpl method send.

private String send(byte[] data) throws CarbonException {
    try {
        log.trace("Connecting to Carbon...");
        final Socket socket = createSocket();
        final CarbonSocketAPI api = new CarbonSocketAPI(socket);
        return api.send(data);
    } catch (CarbonException e) {
        throw e;
    } catch (Exception e) {
        throw new CarbonException(e);
    }
}
Also used : CarbonSocketAPI(com.peterphi.carbon.message.CarbonSocketAPI) CarbonException(com.peterphi.carbon.exception.CarbonException) Socket(java.net.Socket) CarbonException(com.peterphi.carbon.exception.CarbonException) CarbonConnectException(com.peterphi.carbon.exception.CarbonConnectException) JDOMException(org.jdom2.JDOMException) IOException(java.io.IOException)

Aggregations

CarbonException (com.peterphi.carbon.exception.CarbonException)2 IOException (java.io.IOException)2 CarbonConnectException (com.peterphi.carbon.exception.CarbonConnectException)1 CarbonSocketAPI (com.peterphi.carbon.message.CarbonSocketAPI)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Socket (java.net.Socket)1 JDOMException (org.jdom2.JDOMException)1 XMLOutputter (org.jdom2.output.XMLOutputter)1