82 // javadoc. 83 private void configure() { 84 LogManager manager = LogManager.getLogManager(); 85 String cname = getClass().getName(); 86 87 setLevel(manager.getLevelProperty(cname +".level", Level.INFO)); 88 setFilter(manager.getFilterProperty(cname +".filter", null)); 89 setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter())); 90 try { 91 setEncoding(manager.getStringProperty(cname +".encoding", null)); 92 } catch (Exception ex) { 93 try { 94 setEncoding(null); 95 } catch (Exception ex2) { 96 // doing a setEncoding with null should always work. 97 // assert false; 98 } 99 } 100 } 101 102 /** 103 * Create a <tt>StreamHandler</tt>, with no current output stream. 104 */ 105 public StreamHandler() { 106 sealed = false; 107 configure(); 108 sealed = true; 109 } 110 111 /** 112 * Create a <tt>StreamHandler</tt> with a given <tt>Formatter</tt> 113 * and output stream. 114 * <p> 115 * @param out the target output stream 116 * @param formatter Formatter to be used to format output 117 */ 118 public StreamHandler(OutputStream out, Formatter formatter) { 119 sealed = false; 120 configure(); 121 setFormatter(formatter); 122 setOutputStream(out); 123 sealed = true; 124 } 125 126 /** 127 * Change the output stream. 128 * <P> 129 * If there is a current output stream then the <tt>Formatter</tt>'s 130 * tail string is written and the stream is flushed and closed. 131 * Then the output stream is replaced with the new output stream. 132 * 133 * @param out New output stream. May not be null. 134 * @exception SecurityException if a security manager exists and if 135 * the caller does not have <tt>LoggingPermission("control")</tt>. 136 */ 137 protected synchronized void setOutputStream(OutputStream out) throws SecurityException { 138 if (out == null) { 139 throw new NullPointerException(); | 82 // javadoc. 83 private void configure() { 84 LogManager manager = LogManager.getLogManager(); 85 String cname = getClass().getName(); 86 87 setLevel(manager.getLevelProperty(cname +".level", Level.INFO)); 88 setFilter(manager.getFilterProperty(cname +".filter", null)); 89 setFormatter(manager.getFormatterProperty(cname +".formatter", new SimpleFormatter())); 90 try { 91 setEncoding(manager.getStringProperty(cname +".encoding", null)); 92 } catch (Exception ex) { 93 try { 94 setEncoding(null); 95 } catch (Exception ex2) { 96 // doing a setEncoding with null should always work. 97 // assert false; 98 } 99 } 100 } 101 102 // Package private support for security checking. When isSealed 103 // returns true, we access check updates to the class. 104 // Initially the value is false, but we set to true at end of 105 // each constructor... 106 private final boolean sealed; 107 108 @Override 109 boolean isSealed() { 110 return sealed; 111 } 112 113 /** 114 * Create a <tt>StreamHandler</tt>, with no current output stream. 115 */ 116 public StreamHandler() { 117 configure(); 118 sealed = true; 119 } 120 121 /** 122 * Create a <tt>StreamHandler</tt> with a given <tt>Formatter</tt> 123 * and output stream. 124 * <p> 125 * @param out the target output stream 126 * @param formatter Formatter to be used to format output 127 */ 128 public StreamHandler(OutputStream out, Formatter formatter) { 129 configure(); 130 setFormatter(formatter); 131 setOutputStream(out); 132 sealed = true; 133 } 134 135 /** 136 * Change the output stream. 137 * <P> 138 * If there is a current output stream then the <tt>Formatter</tt>'s 139 * tail string is written and the stream is flushed and closed. 140 * Then the output stream is replaced with the new output stream. 141 * 142 * @param out New output stream. May not be null. 143 * @exception SecurityException if a security manager exists and if 144 * the caller does not have <tt>LoggingPermission("control")</tt>. 145 */ 146 protected synchronized void setOutputStream(OutputStream out) throws SecurityException { 147 if (out == null) { 148 throw new NullPointerException(); |