Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2011, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.encoder;
 
 
 
 public class LayoutWrappingEncoder<E> extends EncoderBase<E> {
 
   protected Layout<E> layout;

  
The charset to use when converting a String into bytes.

By default this property has the value null</null> which corresponds to the system's default charset.

 
   private Charset charset;
 
   private boolean immediateFlush = true;


  
Sets the immediateFlush option. The default value for immediateFlush is 'true'. If set to true, the doEncode() method will immediately flush the underlying OutputStream. Although immediate flushing is safer, it also significantly degrades logging throughput.

Since:
1.0.3
 
   public void setImmediateFlush(boolean immediateFlush) {
     this. = immediateFlush;
   }
 
 
   public boolean isImmediateFlush() {
     return ;
   }
 
 
   public Layout<E> getLayout() {
     return ;
   }
 
   public void setLayout(Layout<E> layout) {
     this. = layout;
   }
 
   public Charset getCharset() {
     return ;
   }

  
Set the charset to use when converting the string returned by the layout into bytes.

By default this property has the value null</null> which corresponds to the system's default charset.

Parameters:
charset
 
   public void setCharset(Charset charset) {
     this. = charset;
   }
 
   public void init(OutputStream osthrows IOException {
     super.init(os);
     writeHeader();
   }
 
   void writeHeader() throws IOException {
     if ( != null && ( != null)) {
       StringBuilder sb = new StringBuilder();
       appendIfNotNull(sb.getFileHeader());
       if (sb.length() > 0) {
         sb.append(.);
         // If at least one of file header or presentation header were not
         // null, then append a line separator.
         // This should be useful in most cases and should not hurt.
         .write(convertToBytes(sb.toString()));
         .flush();
      }
    }
  }
  public void close() throws IOException {
    writeFooter();
  }
  void writeFooter() throws IOException {
    if ( != null &&  != null) {
      StringBuilder sb = new StringBuilder();
      if (sb.length() > 0) {
        .flush();
      }
    }
  }
  private byte[] convertToBytes(String s) {
    if ( == null) {
      return s.getBytes();
    } else {
      try {
        return s.getBytes(.name());
      } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(
                "An existing charset cannot possibly be unsupported.");
      }
    }
  }
  public void doEncode(E eventthrows IOException {
    String txt = .doLayout(event);
    if ()
      .flush();
  }
  public boolean isStarted() {
    return false;
  }
  public void start() {
     = true;
  }
  public void stop() {
     = false;
    if( != null) {
      try {
        .flush();
      } catch (IOException e) {
      }
    }
  }
  private void appendIfNotNull(StringBuilder sbString s) {
    if (s != null) {
      sb.append(s);
    }
  }
New to GrepCode? Check out our FAQ X