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.net;
SyslogOutputStream is a wrapper around the java.net.DatagramSocket class so that it behaves like an java.io.OutputStream.
public class SyslogOutputStream extends OutputStream {

  
The maximum length after which we discard the existing string buffer and start anew.
  private static final int MAX_LEN = 1024;
  private InetAddress address;
  private DatagramSocket ds;
  final private int port;
  public SyslogOutputStream(String syslogHostint portthrows UnknownHostException,
      SocketException {
    this. = InetAddress.getByName(syslogHost);
    this. = port;
    this. = new DatagramSocket();
  }
  public void write(byte[] byteArrayint offsetint lenthrows IOException {
    .write(byteArrayoffsetlen);
  }
  public void flush() throws IOException {
    byte[] bytes = .toByteArray();
    DatagramPacket packet = new DatagramPacket(bytesbytes.length,
        );
    // clean up for next round
    if (.size() > ) {
       = new ByteArrayOutputStream();
    } else {
      .reset();
    }
    
    // after a failure, it can happen that bytes.length is zero
    // in that case, there is no point in sending out an empty message/
    if(bytes.length == 0) {
      return;
    }
    if (this. != null) {
      .send(packet);
    }
  
  }
  public void close() {
     = null;
     = null;
  }
  public int getPort() {
    return ;
  }
  public void write(int bthrows IOException {
    .write(b);
  }
New to GrepCode? Check out our FAQ X