Class DumperBus

java.lang.Object
java.io.Writer
org.simpleyaml.utils.DumperBus
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class DumperBus extends Writer
Every line written to this writer will be enqueued on flush with a fixed capacity.

Those lines can be awaited and consumed.

This is an asynchronous blocking implementation. Different threads can write and read on this writer.

  • Constructor Details

  • Method Details

    • dump

      public void dump() throws IOException
      Dump source values into this writer in a background thread.
      Throws:
      IOException - if I/O error occurs
    • write

      public void write(char[] str, int offset, int len) throws IOException
      Append to line a portion of an array of characters.

      New lines are flushed.

      Specified by:
      write in class Writer
      Parameters:
      str - Array of characters
      offset - Offset from which to start writing characters
      len - Number of characters to write
      Throws:
      IndexOutOfBoundsException - if offset < 0 or len < 0 or offset+len > str.length
      IOException - if I/O error occurs
    • flush

      public void flush() throws IOException
      Append the current characters to the queue as a new line and reset the current line buffer.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
      Throws:
      IOException - if I/O error occurs
    • await

      public String await() throws IOException
      Consume the queue, blocking and awaiting a new line if the queue is empty.
      Returns:
      the next line in the queue, may be null for the end of the file
      Throws:
      IOException - if I/O error occurs
    • close

      public void close() throws IOException
      Called after dumping all the values.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException - if I/O error occurs
    • isClosed

      protected boolean isClosed()
    • source

      public DumperBus.Dumper source()
      Get the dumper source where values are read.
      Returns:
      the dumper source
    • runThread

      protected void runThread(org.simpleyaml.utils.DumperBus.Task task) throws IOException
      Start a new thread executing a task.
      Parameters:
      task - the task to run
      Throws:
      IOException - if I/O error occurs