/** * Writes events to this index, reusing the connection. * This method passes an output stream connected to the index to the * {@code run} method of the {@code ReceiverBehavior} object, then handles * setting up and tearing down the socket. * <p> * For an example of how to use this method, see * <a href="http://dev.splunk.com/view/SP-CAAAEJ2" target="_blank">How to * get data into Splunk</a> on * <a href="http://dev.splunk.com/view/SP-CAAAEJ2" * target="_blank">dev.splunk.com</a>. * * @param behavior The body of a {@code try} block as an anonymous * implementation of the {@code ReceiverBehavior} interface. */ public void attachWith(ReceiverBehavior behavior) throws IOException { Socket socket = null; OutputStream output = null; try { socket = attach(); output = socket.getOutputStream(); behavior.run(output); output.flush(); } finally { if (output != null) { output.close(); } if (socket != null) { socket.close(); } } }