src/share/classes/java/util/logging/SocketHandler.java
Print this page
@@ -81,55 +81,33 @@
public class SocketHandler extends StreamHandler {
private Socket sock;
private String host;
private int port;
- // Private method to configure a SocketHandler from LogManager
- // properties and/or default values as specified in the class
- // javadoc.
- private void configure() {
- LogManager manager = LogManager.getLogManager();
- String cname = getClass().getName();
-
- setLevel(manager.getLevelProperty(cname +".level", Level.ALL));
- setFilter(manager.getFilterProperty(cname +".filter", null));
- setFormatter(manager.getFormatterProperty(cname +".formatter", new XMLFormatter()));
- try {
- setEncoding(manager.getStringProperty(cname +".encoding", null));
- } catch (Exception ex) {
- try {
- setEncoding(null);
- } catch (Exception ex2) {
- // doing a setEncoding with null should always work.
- // assert false;
- }
- }
- port = manager.getIntProperty(cname + ".port", 0);
- host = manager.getStringProperty(cname + ".host", null);
- }
-
-
/**
* Create a <tt>SocketHandler</tt>, using only <tt>LogManager</tt> properties
* (or their defaults).
* @throws IllegalArgumentException if the host or port are invalid or
* are not specified as LogManager properties.
* @throws IOException if we are unable to connect to the target
* host and port.
*/
public SocketHandler() throws IOException {
- // We are going to use the logging defaults.
- sealed = false;
- configure();
+ // configure with specific defaults for SocketHandler
+ super(Level.ALL, new XMLFormatter(), null);
+
+ LogManager manager = LogManager.getLogManager();
+ String cname = getClass().getName();
+ port = manager.getIntProperty(cname + ".port", 0);
+ host = manager.getStringProperty(cname + ".host", null);
try {
connect();
} catch (IOException ix) {
System.err.println("SocketHandler: connect failed to " + host + ":" + port);
throw ix;
}
- sealed = true;
}
/**
* Construct a <tt>SocketHandler</tt> using a specified host and port.
*
@@ -144,15 +122,16 @@
* @throws IllegalArgumentException if the host or port are invalid.
* @throws IOException if we are unable to connect to the target
* host and port.
*/
public SocketHandler(String host, int port) throws IOException {
- sealed = false;
- configure();
- sealed = true;
+ // configure with specific defaults for SocketHandler
+ super(Level.ALL, new XMLFormatter(), null);
+
this.port = port;
this.host = host;
+
connect();
}
private void connect() throws IOException {
// Check the arguments are valid.
@@ -165,11 +144,11 @@
// Try to open a new socket.
sock = new Socket(host, port);
OutputStream out = sock.getOutputStream();
BufferedOutputStream bout = new BufferedOutputStream(out);
- setOutputStream(bout);
+ setOutputStreamPrivileged(bout);
}
/**
* Close this output stream.
*