Package org.bytemechanics.commons.io
Class YAMLPropertyWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.FilterWriter
-
- org.bytemechanics.commons.io.YAMLPropertyWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class YAMLPropertyWriter extends FilterWriter
Property writer to yaml- Author:
- afarre
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classYAMLPropertyWriter.PropertyInput propertyprotected static classYAMLPropertyWriter.YamlEntryInternal class to store each property tree name with the key and value
-
Field Summary
-
Fields inherited from class java.io.FilterWriter
out
-
-
Constructor Summary
Constructors Constructor Description YAMLPropertyWriter(Writer _writer)Default constructor with ignoreListLength set trueYAMLPropertyWriter(Writer _writer, boolean _ignoreListLength)Constructor capable to define ignoreListLength value
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappend(int _depth, String _name, String _value, boolean _isList)Append to the underlaying stream the correct yaml format for the given fieldsvoidappend(YAMLPropertyWriter.Property _property)Write down the given propertyprotected voidappend(YAMLPropertyWriter.YamlEntry _yamlEntry)Write down the given yaml entryprotected intcalculateTabs()Accumulate the current entryPathCache tabulation considering that each list counts doubleprotected booleanfilterLength(YAMLPropertyWriter.Property _property)Return true if ignoreListLength is disabled or the property is not length (ends with [*].length)protected Stream<YAMLPropertyWriter.YamlEntry>splitPath(YAMLPropertyWriter.Property _property)Divide the given _property into a stream of YamlEntryvoidwrite(Stream<YAMLPropertyWriter.Property> _stream)Write down all stream elements until end of stream IMPORTANT: its mandatory to provide the stream ordered, otherwise will have unexpected results
-
-
-
Constructor Detail
-
YAMLPropertyWriter
public YAMLPropertyWriter(Writer _writer)
Default constructor with ignoreListLength set true- Parameters:
_writer- parent reader
-
YAMLPropertyWriter
public YAMLPropertyWriter(Writer _writer, boolean _ignoreListLength)
Constructor capable to define ignoreListLength value- Parameters:
_writer- parent reader_ignoreListLength- ignore list length and do not append it
-
-
Method Detail
-
append
protected final void append(int _depth, String _name, String _value, boolean _isList) throws IOExceptionAppend to the underlaying stream the correct yaml format for the given fields- Parameters:
_depth- number of tabs to use (double space)_name- key name_value- value_isList- flag to indicate if is a list- Throws:
IOException- if something happens
-
calculateTabs
protected int calculateTabs()
Accumulate the current entryPathCache tabulation considering that each list counts double- Returns:
- number of tabs in entryPathCache counting lists as double
-
append
protected void append(YAMLPropertyWriter.YamlEntry _yamlEntry)
Write down the given yaml entry- Parameters:
_yamlEntry- property to append
-
filterLength
protected final boolean filterLength(YAMLPropertyWriter.Property _property)
Return true if ignoreListLength is disabled or the property is not length (ends with [*].length)- Parameters:
_property- property to validate- Returns:
- true if and only if ignoreListLength is disabled or the property is not length
-
splitPath
protected Stream<YAMLPropertyWriter.YamlEntry> splitPath(YAMLPropertyWriter.Property _property)
Divide the given _property into a stream of YamlEntry- Parameters:
_property- property to convert- Returns:
- stream of YamlEntry corresponding to the given _property
-
write
public void write(Stream<YAMLPropertyWriter.Property> _stream)
Write down all stream elements until end of stream IMPORTANT: its mandatory to provide the stream ordered, otherwise will have unexpected results- Parameters:
_stream- stream of properties to append
-
append
public void append(YAMLPropertyWriter.Property _property)
Write down the given property- Parameters:
_property- property to append
-
-