donaldp 2003/02/26 00:20:20 Modified: src/java/org/apache/log/output/net DatagramOutputTarget.java Log: Add mechanism via which to set the encoding which will be used to write out packets. Submitted By: [EMAIL PROTECTED] Revision Changes Path 1.10 +27 -2 avalon-logkit/src/java/org/apache/log/output/net/DatagramOutputTarget.java Index: DatagramOutputTarget.java =================================================================== RCS file: /home/cvs/avalon-logkit/src/java/org/apache/log/output/net/DatagramOutputTarget.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- DatagramOutputTarget.java 9 Feb 2003 23:33:25 -0000 1.9 +++ DatagramOutputTarget.java 26 Feb 2003 08:20:19 -0000 1.10 @@ -71,25 +71,34 @@ public class DatagramOutputTarget extends AbstractOutputTarget { + ///Default encoding of datagram + private static final String DEFAULT_ENCODING = "US-ASCII"; + ///Socket on which to send datagrams private DatagramSocket m_socket; + ///The encoding to use when creating byte array from string + private String m_encoding; + /** * Create a output target with end point specified by address and port. * * @param address the address endpoint * @param port the address port * @param formatter the message formatter + * @param encoding the encoding to use when encoding string * @exception IOException if an error occurs */ public DatagramOutputTarget( final InetAddress address, final int port, - final Formatter formatter ) + final Formatter formatter, + final String encoding ) throws IOException { super( formatter ); m_socket = new DatagramSocket(); m_socket.connect( address, port ); + m_encoding = encoding; open(); } @@ -98,6 +107,22 @@ * * @param address the address endpoint * @param port the address port + * @param formatter the message formatter + * @exception IOException if an error occurs + */ + public DatagramOutputTarget( final InetAddress address, + final int port, + final Formatter formatter ) + throws IOException + { + this( address, port, formatter, DEFAULT_ENCODING ); + } + + /** + * Create a output target with end point specified by address and port. + * + * @param address the address endpoint + * @param port the address port * @exception IOException if an error occurs */ public DatagramOutputTarget( final InetAddress address, final int port ) @@ -113,10 +138,10 @@ */ protected void write( final String stringData ) { - final byte[] data = stringData.getBytes(); try { + final byte[] data = stringData.getBytes( m_encoding ); final DatagramPacket packet = new DatagramPacket( data, data.length ); m_socket.send( packet ); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]