Package com.igormaznitsa.jbbp.utils
Class JBBPTextWriter
java.lang.Object
java.io.Writer
java.io.FilterWriter
com.igormaznitsa.jbbp.utils.JBBPTextWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
the Writer allows to make text describes some bin data, it supports output of
commentaries and values, also it is possible to register own extras to
process complex data and cases. The Class is not thread safe.
- Since:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe Interface describes some extras for the writer which can make extra-work. -
Field Summary
Fields inherited from class java.io.FilterWriter
out -
Constructor Summary
ConstructorsConstructorDescriptionThe Default constructor.JBBPTextWriter(Writer out) Constructor to wrap a writer,JBBPTextWriter(Writer out, JBBPByteOrder byteOrder) Constructor to wrap a writer with defined byte order.JBBPTextWriter(Writer out, JBBPByteOrder byteOrder, String lineSeparator, int radix, String valuePrefix, String startValueLinePrefix, String commentPrefix, String hrPrefix, String valueDelimiter) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionAddExtras(JBBPTextWriter.Extra... extras) Add extras to context.append(char c) append(CharSequence csq) append(CharSequence csq, int start, int end) Print objects which marked by Bin annotation or successors of JBBPAbstractField.BR()Make new line.Byte(byte[] values) Print byte array.Byte(byte[] array, int off, int len) Print values from byte array.Byte(int value) Print byte value.Print byte array defined as string.final JBBPTextWriterByteOrder(JBBPByteOrder order) Set byte order.voidclose()Close()Close the wrapped writer.Print comments.DelExtras(JBBPTextWriter.Extra... extras) Remove extras from contextDisable print comments.Double(double value) Print double value.Double(double[] values) Print array of double values.Double(double[] values, int off, int len) Print values from double arrayEnable print comments.Float(float value) Print float value.Float(float[] values) Print array of float values.Float(float[] values, int off, int len) Print values from float arrayvoidflush()Flush()Flush buffers in wrapped writer.Get the current byte order.intgetLine()Get the current line number.intGet the current line position.Get the current line separator.intgetRadix()get the current radix.Get the wrapped writer.HR()Print horizontal rule.Decrease indent.IndentDec(int count) Decrease indent.Increase indent.IndentInc(int count) Increase indent.Int(int value) Print integer valueInt(int[] values) Print integer array.Int(int[] values, int off, int len) Print values from integer array.booleanCheck that comment mode is active.booleanCheck that line start mode is active.booleanisValues()Check that value mode is active.Long(long value) Print long valueLong(long[] values) Print values from long array.Long(long[] values, int off, int len) print values from long array.protected static Stringstatic JBBPTextWriterAuxiliary method allows to build writer over StringWriter with system-depended next line and hex radix.Print objects.Print objects from array.protected voidprintAbstractFieldObject(String postText, JBBPAbstractField field) final JBBPTextWriterRadix(int radix) Set radix.final JBBPTextWriterSetCommentPrefix(String text) Set prefix to be printed as comment start.Change parameters for horizontal rule.SetMaxValuesPerLine(int value) Set max number of values to be printed in one line.SetTabSpaces(int numberOfSpacesPerTab) Set number of spaces per tab.final JBBPTextWriterSetValueLinePrefix(String text) Set prefix to be printed before start of values on every line.final JBBPTextWriterSetValuePostfix(String text) Set postfix to be printed after every value.final JBBPTextWriterSetValuePrefix(String text) Set prefix to be printed before every value.final JBBPTextWriterSetValueSeparator(String text) Set delimiter to be printed between values.Short(int value) Print short value.Short(short[] values) Print array of short values.Short(short[] values, int off, int len) Print values from short arrayPrint char codes of string as short array.Space(int numberOfSpaces) Print number of spaces.Print string values.Tab()Print tab as space chars.toString()UInt(int value) Print unsigned integer valueUInt(int[] values) Print unsigned integer array.UInt(int[] values, int off, int len) Print values from unsigned integer array.voidwrite(char[] cbuf) voidwrite(char[] cbuf, int off, int len) voidwrite(int c) voidvoidMethods inherited from class java.io.Writer
nullWriter
-
Constructor Details
-
JBBPTextWriter
public JBBPTextWriter()The Default constructor. A StringWriter will be used inside. -
JBBPTextWriter
Constructor to wrap a writer,- Parameters:
out- a writer to be wrapped, must not be null.
-
JBBPTextWriter
Constructor to wrap a writer with defined byte order.- Parameters:
out- a writer to be wrapped, must not be null.byteOrder- a byte order to be used, it must not be null.
-
JBBPTextWriter
public JBBPTextWriter(Writer out, JBBPByteOrder byteOrder, String lineSeparator, int radix, String valuePrefix, String startValueLinePrefix, String commentPrefix, String hrPrefix, String valueDelimiter) Constructor.- Parameters:
out- a writer to be wrapper, must not be null.byteOrder- byte order to be used for converting, must not be null.lineSeparator- line separator, must not be null.radix- radix, must be 2..36.valuePrefix- prefix before each value, can be null.startValueLinePrefix- prefix before the first value on line, can be null.commentPrefix- prefix before comments, can be null.hrPrefix- prefix for horizontal rulevalueDelimiter- delimiter between values, can be null
-
-
Method Details
-
makeStrWriter
Auxiliary method allows to build writer over StringWriter with system-depended next line and hex radix. The Method allows fast instance create.- Returns:
- the text writer instance, must not be null
- Since:
- 1.4.0
-
makeFieldComment
-
getWrappedWriter
Get the wrapped writer.- Returns:
- the wrapped writer
-
getByteOrder
Get the current byte order.- Returns:
- the current byte order.
-
getRadix
public int getRadix()get the current radix.- Returns:
- the current radix
-
getLineSeparator
Get the current line separator.- Returns:
- the current line separator as string
-
EnableComments
Enable print comments.- Returns:
- the context
-
DisableComments
Disable print comments.- Returns:
- the context
-
Str
Print string values.- Parameters:
str- array of string values, must not be null but may contain nulls- Returns:
- the context
- Throws:
IOException- it will be thrown for error
-
Byte
Print byte value.- Parameters:
value- a byte value- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Byte
Print byte array defined as string.- Parameters:
value- string which codes should be printed as byte array.- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error
-
Byte
Print byte array.- Parameters:
values- a byte array, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Byte
Print values from byte array.- Parameters:
array- source byte array, must not be nulloff- the offset of the first element in arraylen- number of bytes to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
isLineStart
public boolean isLineStart()Check that line start mode is active.- Returns:
- true if mode is line start, false otherwise
-
isComments
public boolean isComments()Check that comment mode is active.- Returns:
- true if comment mode is active, false otherwise
-
isValues
public boolean isValues()Check that value mode is active.- Returns:
- true if value mode is active, false otherwise
-
SetValueLinePrefix
Set prefix to be printed before start of values on every line.- Parameters:
text- string to be used as value line prefix, can be null- Returns:
- the context
-
SetValuePrefix
Set prefix to be printed before every value.- Parameters:
text- string to be used as value prefix, can be null- Returns:
- the context
-
SetValuePostfix
Set postfix to be printed after every value.- Parameters:
text- string to be used as value postfix, can be null- Returns:
- the context
-
SetCommentPrefix
Set prefix to be printed as comment start.- Parameters:
text- string to be used as comment start, can be null- Returns:
- the context
-
SetValueSeparator
Set delimiter to be printed between values.- Parameters:
text- string to be used as separator between values.- Returns:
- the context
-
AddExtras
Add extras to context.- Parameters:
extras- extras to be added to context, must not be null- Returns:
- the context
-
DelExtras
Remove extras from context- Parameters:
extras- extras to be removed, must not be null- Returns:
- the context
-
SetMaxValuesPerLine
Set max number of values to be printed in one line.- Parameters:
value- max number of values to be presented on line, 0 or negative to turn off checking- Returns:
- the context
-
SetTabSpaces
Set number of spaces per tab.- Parameters:
numberOfSpacesPerTab- number of spaces, must be greater than zero- Returns:
- the context
-
ByteOrder
Set byte order.- Parameters:
order- new byte order, must not be null- Returns:
- the context
-
Radix
Set radix.- Parameters:
radix- new radix value, must be 2..36- Returns:
- the context
-
Short
Print short value.- Parameters:
value- short value to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Float
Print float value.- Parameters:
value- float value to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors- Since:
- 1.4.0
-
Double
Print double value.- Parameters:
value- double value to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors- Since:
- 1.4.0
-
Short
Print char codes of string as short array.- Parameters:
value- string which codes should be printed, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown if any transport error
-
Short
Print array of short values.- Parameters:
values- array of short values, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Float
Print array of float values.- Parameters:
values- array of float values, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors- Since:
- 1.4.0
-
Double
Print array of double values.- Parameters:
values- array of double values, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors- Since:
- 1.4.0
-
Short
Print values from short array- Parameters:
values- short value array, must not be nulloff- offset to the first elementlen- number of elements to print- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error
-
Float
Print values from float array- Parameters:
values- float value array, must not be nulloff- offset to the first elementlen- number of elements to print- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error- Since:
- 1.4.0
-
Double
Print values from double array- Parameters:
values- double value array, must not be nulloff- offset to the first elementlen- number of elements to print- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error- Since:
- 1.4.0
-
Int
Print integer value- Parameters:
value- value to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error
-
UInt
Print unsigned integer value- Parameters:
value- value to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error- Since:
- 2.0.4
-
Int
Print integer array.- Parameters:
values- integer array to be printed, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error
-
UInt
Print unsigned integer array.- Parameters:
values- unsigned integer array to be printed, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error- Since:
- 2.0.4
-
Int
Print values from integer array.- Parameters:
values- integer array, must not be nulloff- offset to the first element in arraylen- number of elements to print- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error
-
UInt
Print values from unsigned integer array.- Parameters:
values- unsigned integer array, must not be nulloff- offset to the first element in arraylen- number of elements to print- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error- Since:
- 2.0.4
-
IndentInc
Increase indent.- Returns:
- the context
-
IndentInc
Increase indent.- Parameters:
count- number of indents- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error
-
IndentDec
Decrease indent.- Returns:
- the context
-
IndentDec
Decrease indent.- Parameters:
count- number of indents- Returns:
- the context
- Throws:
IOException- it will be thrown for transport error
-
Long
Print long value- Parameters:
value- value to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Long
Print values from long array.- Parameters:
values- array to be printed, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Long
print values from long array.- Parameters:
values- array to be printed, must not be nulloff- offset to the first element to printlen- number of elements to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
BR
Make new line.- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
SetHR
Change parameters for horizontal rule.- Parameters:
prefix- the prefix to be printed before rule, it can be nulllength- the length in symbols.ch- symbol to draw- Returns:
- the context
-
HR
Print horizontal rule. If comments are disabled then only next line will be added.- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors- See Also:
-
Comment
Print comments. Wilt aligning of line start for multi-line comment. Comments will be printed only if they are allowed.- Parameters:
comment- array of string to be printed as comment lines.- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors- See Also:
-
toString
-
Obj
Print objects.- Parameters:
objId- object id which will be provided to a converter as extra infoobj- objects to be converted and printed, must not be null- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Obj
Print objects from array.- Parameters:
objId- object id which will be provided to a converter as extra infoarray- array of objects, must not be nulloff- offset to the first element to be printedlen- number of elements to be printed- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Bin
Print objects which marked by Bin annotation or successors of JBBPAbstractField. NB! Keep in mind that values of fields will be processed for their attributes before printing and for instance a bit field with inversion will be shown as inverted one.- Parameters:
objs- array of object marked by Bin annotation or successors of JBBPAbstractField- Returns:
- the context
- Throws:
IOException- it will be thrown if transport errors
-
printAbstractFieldObject
protected void printAbstractFieldObject(String postText, JBBPAbstractField field) throws IOException - Throws:
IOException
-
Close
Close the wrapped writer.- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterWriter- Throws:
IOException
-
Flush
Flush buffers in wrapped writer.- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterWriter- Throws:
IOException
-
Tab
Print tab as space chars.- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
Space
Print number of spaces.- Parameters:
numberOfSpaces- number of spaces to print- Returns:
- the context
- Throws:
IOException- it will be thrown for transport errors
-
getLine
public int getLine()Get the current line number.- Returns:
- the current line number, the first one is zero
-
getLinePosition
public int getLinePosition()Get the current line position.- Returns:
- the current line position, the first one is zero
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classWriter- Throws:
IOException
-
write
- Overrides:
writein classFilterWriter- Throws:
IOException
-
write
- Overrides:
writein classFilterWriter- Throws:
IOException
-
write
- Overrides:
writein classFilterWriter- Throws:
IOException
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter- Throws:
IOException
-