Package org.simpleyaml.utils
Class DumperBus
java.lang.Object
java.io.Writer
org.simpleyaml.utils.DumperBus
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceSource for dumping values to this writer. -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDumperBus(DumperBus.Dumper source) DumperBus(DumperBus.Dumper source, int capacity) -
Method Summary
Modifier and TypeMethodDescriptionawait()Consume the queue, blocking and awaiting a new line if the queue is empty.voidclose()Called after dumping all the values.voiddump()Dump source values into this writer in a background thread.voidflush()Append the current characters to the queue as a new line and reset the current line buffer.protected booleanisClosed()protected voidrunThread(org.simpleyaml.utils.DumperBus.Task task) Start a new thread executing a task.source()Get the dumper source where values are read.voidwrite(char[] str, int offset, int len) Append to line a portion of an array of characters.
-
Constructor Details
-
DumperBus
-
DumperBus
-
-
Method Details
-
dump
Dump source values into this writer in a background thread.- Throws:
IOException- if I/O error occurs
-
write
Append to line a portion of an array of characters.New lines are flushed.
- Specified by:
writein classWriter- Parameters:
str- Array of charactersoffset- Offset from which to start writing characterslen- Number of characters to write- Throws:
IndexOutOfBoundsException- ifoffset < 0orlen < 0oroffset+len > str.lengthIOException- if I/O error occurs
-
flush
Append the current characters to the queue as a new line and reset the current line buffer.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException- if I/O error occurs
-
await
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
Called after dumping all the values.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- if I/O error occurs
-
isClosed
protected boolean isClosed() -
source
Get the dumper source where values are read.- Returns:
- the dumper source
-
runThread
Start a new thread executing a task.- Parameters:
task- the task to run- Throws:
IOException- if I/O error occurs
-