ch.qos.logback.core.FileAppender.getOutputStream()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中ch.qos.logback.core.FileAppender.getOutputStream()方法的一些代码示例,展示了FileAppender.getOutputStream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileAppender.getOutputStream()方法的具体详情如下:
包路径:ch.qos.logback.core.FileAppender
类名称:FileAppender
方法名:getOutputStream

FileAppender.getOutputStream介绍

暂无

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

private void safeWrite(E event) throws IOException {
 ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
 FileChannel fileChannel = resilientFOS.getChannel();
 if (fileChannel == null) {
  return;
 }
 FileLock fileLock = null;
 try {
  fileLock = fileChannel.lock();
  long position = fileChannel.position();
  long size = fileChannel.size();
  if (size != position) {
   fileChannel.position(size);
  }
  super.writeOut(event);
 } finally {
  if (fileLock != null) {
   fileLock.release();
  }
 }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/ch.qos.logback.core

private void safeWrite(E event) throws IOException {
 ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
 FileChannel fileChannel = resilientFOS.getChannel();
 if (fileChannel == null) {
  return;
 }
 FileLock fileLock = null;
 try {
  fileLock = fileChannel.lock();
  long position = fileChannel.position();
  long size = fileChannel.size();
  if (size != position) {
   fileChannel.position(size);
  }
  super.writeOut(event);
 } finally {
  if (fileLock != null) {
   fileLock.release();
  }
 }
}

代码示例来源:origin: ch.qos.logback/core

private void safeWrite(E event) throws IOException {
 ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
 FileChannel fileChannel = resilientFOS.getChannel();
 if (fileChannel == null) {
  return;
 }
 FileLock fileLock = null;
 try {
  fileLock = fileChannel.lock();
  long position = fileChannel.position();
  long size = fileChannel.size();
  if (size != position) {
   fileChannel.position(size);
  }
  super.writeOut(event);
 } finally {
  if (fileLock != null) {
   fileLock.release();
  }
 }
}

代码示例来源:origin: de.huxhorn.lilith/de.huxhorn.lilith.logback.encoder.core

private boolean isSupposedToGenerateHeader()
{
  if(parent instanceof FileAppender)
  {
    FileAppender fileAppender = (FileAppender) parent;
    if(!fileAppender.isAppend())
    {
      return true;
    }
    OutputStream outputStream = fileAppender.getOutputStream();
    if(outputStream instanceof ResilientFileOutputStream)
    {
      ResilientFileOutputStream fileOutputStream = (ResilientFileOutputStream) outputStream;
      File file = fileOutputStream.getFile();
      if(file.length() != 0)
      {
        // appending and file with already existing content => no header.
        return false;
      }
    }
  }
  return true;
}

代码示例来源:origin: tony19/logback-android

private void safeWrite(E event) throws IOException {
 ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
 FileChannel fileChannel = resilientFOS.getChannel();
 if (fileChannel == null) {
  return;
 }
 // Clear any current interrupt (see LOGBACK-875)
 boolean interrupted = Thread.interrupted();
 FileLock fileLock = null;
 try {
  fileLock = fileChannel.lock();
  long position = fileChannel.position();
  long size = fileChannel.size();
  if (size != position) {
   fileChannel.position(size);
  }
  super.writeOut(event);
 } catch (IOException e) {
  // Mainly to catch FileLockInterruptionExceptions (see LOGBACK-875)
  resilientFOS.postIOFailure(e);
 } finally {
  if (fileLock != null && fileLock.isValid()) {
   fileLock.release();
  }
  // Re-interrupt if we started in an interrupted state (see LOGBACK-875)
  if (interrupted) {
   Thread.currentThread().interrupt();
  }
 }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

private void safeWrite(E event) throws IOException {
  ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
  FileChannel fileChannel = resilientFOS.getChannel();
  if (fileChannel == null) {
    return;
  }
  // Clear any current interrupt (see LOGBACK-875)
  boolean interrupted = Thread.interrupted();
  FileLock fileLock = null;
  try {
    fileLock = fileChannel.lock();
    long position = fileChannel.position();
    long size = fileChannel.size();
    if (size != position) {
      fileChannel.position(size);
    }
    super.writeOut(event);
  } catch (IOException e) {
    // Mainly to catch FileLockInterruptionExceptions (see LOGBACK-875)
    resilientFOS.postIOFailure(e);
  } finally {
    if (fileLock != null && fileLock.isValid()) {
      fileLock.release();
    }
    // Re-interrupt if we started in an interrupted state (see LOGBACK-875)
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }
}

代码示例来源:origin: Nextdoor/bender

private void safeWrite(E event) throws IOException {
  ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
  FileChannel fileChannel = resilientFOS.getChannel();
  if (fileChannel == null) {
    return;
  }
  // Clear any current interrupt (see LOGBACK-875)
  boolean interrupted = Thread.interrupted();
  FileLock fileLock = null;
  try {
    fileLock = fileChannel.lock();
    long position = fileChannel.position();
    long size = fileChannel.size();
    if (size != position) {
      fileChannel.position(size);
    }
    super.writeOut(event);
  } catch (IOException e) {
    // Mainly to catch FileLockInterruptionExceptions (see LOGBACK-875)
    resilientFOS.postIOFailure(e);
  } finally {
    if (fileLock != null && fileLock.isValid()) {
      fileLock.release();
    }
    // Re-interrupt if we started in an interrupted state (see LOGBACK-875)
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }
}

代码示例来源:origin: com.hynnet/logback-core

private void safeWrite(E event) throws IOException {
 ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
 FileChannel fileChannel = resilientFOS.getChannel();
 if (fileChannel == null) {

代码示例来源:origin: io.virtdata/virtdata-lib-realer

private void safeWrite(E event) throws IOException {
  ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) getOutputStream();
  FileChannel fileChannel = resilientFOS.getChannel();
  if (fileChannel == null) {
    return;
  }
  // Clear any current interrupt (see LOGBACK-875)
  boolean interrupted = Thread.interrupted();
  FileLock fileLock = null;
  try {
    fileLock = fileChannel.lock();
    long position = fileChannel.position();
    long size = fileChannel.size();
    if (size != position) {
      fileChannel.position(size);
    }
    super.writeOut(event);
  } catch (IOException e) {
    // Mainly to catch FileLockInterruptionExceptions (see LOGBACK-875)
    resilientFOS.postIOFailure(e);
  } finally {
    if (fileLock != null && fileLock.isValid()) {
      fileLock.release();
    }
    // Re-interrupt if we started in an interrupted state (see LOGBACK-875)
    if (interrupted) {
      Thread.currentThread().interrupt();
    }
  }
}

代码示例来源:origin: tony19/logback-android

private void closeLogFileOnPurpose() throws IOException {
  ResilientFileOutputStream resilientFOS = (ResilientFileOutputStream) fa
   .getOutputStream();
  FileChannel fileChannel = resilientFOS.getChannel();
  fileChannel.close();
 }
}

代码示例来源:origin: tony19/logback-android

@Test
public void unlazyAppenderOpensFileAtStart() {
 String filename = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "testing.txt";
 File file = new File(filename);
 if (file.exists()) file.delete();
 FileAppender<Object> fa = getFileAppender(filename);
 fa.setLazy(false);
 assertNull("stream is not null", fa.getOutputStream());
 fa.start();
 assertTrue("expected ResilientFileOutputStream; actual " + fa.getOutputStream().getClass().getSimpleName(), fa.getOutputStream() instanceof ResilientFileOutputStream);
 assertTrue("file does not exist", file.exists());
}

代码示例来源:origin: tony19/logback-android

@Test
public void lazyAppenderDoesNotOpenFileAtStart() {
 String filename = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "testing.txt";
 File file = new File(filename);
 if (file.exists()) file.delete();
 FileAppender<Object> fa = getFileAppender(filename);
 fa.setLazy(true);
 assertNull("stream is not null", fa.getOutputStream());
 fa.start();
 assertTrue("expected NOPOutputStream; actual " + fa.getOutputStream().getClass().getSimpleName(), fa.getOutputStream() instanceof NOPOutputStream);
 assertFalse("file does not exist", file.exists());
}

相关文章