src/share/classes/java/util/logging/StreamHandler.java

Print this page




  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();
 140         }
 141         flushAndClose();
 142         output = out;
 143         doneHeader = false;




  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         doWithControlPermission(this::configure);


 107     }
 108 
 109     /**
 110      * Create a <tt>StreamHandler</tt> with a given <tt>Formatter</tt>
 111      * and output stream.
 112      * <p>
 113      * @param out         the target output stream
 114      * @param formatter   Formatter to be used to format output
 115      */
 116     public StreamHandler(OutputStream out, Formatter formatter) {
 117         doWithControlPermission(() -> {
 118             configure();
 119             setFormatter(formatter);
 120             setOutputStream(out);
 121         });
 122     }
 123 
 124     /**
 125      * Change the output stream.
 126      * <P>
 127      * If there is a current output stream then the <tt>Formatter</tt>'s
 128      * tail string is written and the stream is flushed and closed.
 129      * Then the output stream is replaced with the new output stream.
 130      *
 131      * @param out   New output stream.  May not be null.
 132      * @exception  SecurityException  if a security manager exists and if
 133      *             the caller does not have <tt>LoggingPermission("control")</tt>.
 134      */
 135     protected synchronized void setOutputStream(OutputStream out) throws SecurityException {
 136         if (out == null) {
 137             throw new NullPointerException();
 138         }
 139         flushAndClose();
 140         output = out;
 141         doneHeader = false;