java.lang.Object
net.luis.utils.io.data.property.PropertyWriter
- All Implemented Interfaces:
AutoCloseable
Represents a writer for properties.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final PropertyConfig
The configuration for the property writer.private final BufferedWriter
The internal io writer for writing the property. -
Constructor Summary
ConstructorsConstructorDescriptionPropertyWriter
(@NotNull OutputProvider output) Constructs a new property writer for the given output with the default property configuration.PropertyWriter
(@NotNull OutputProvider output, @NotNull PropertyConfig config) Constructs a new property writer for the given output with the given property configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
writeProperty
(@NotNull String key, @NotNull Object value) Writes the given raw property to the underlying output.<T> void
writeProperty
(@NotNull String key, T value, @NotNull Function<T, String> converter) Writes the given raw property to the underlying output.
The value is converted to a string using the given converter.void
writeProperty
(@NotNull Properties properties) Writes the given properties to the underlying output.void
writeProperty
(@NotNull Property property) Writes the given property to the underlying output.
-
Field Details
-
config
The configuration for the property writer. -
writer
The internal io writer for writing the property.
-
-
Constructor Details
-
PropertyWriter
Constructs a new property writer for the given output with the default property configuration.- Parameters:
output
- The output provider to create the writer for- Throws:
NullPointerException
- If the output is null
-
PropertyWriter
public PropertyWriter(@NotNull @NotNull OutputProvider output, @NotNull @NotNull PropertyConfig config) Constructs a new property writer for the given output with the given property configuration.- Parameters:
output
- The output to create the writer forconfig
- The configuration for the properties writer- Throws:
NullPointerException
- If the output or the configuration is null
-
-
Method Details
-
writeProperty
Writes the given raw property to the underlying output.- Parameters:
key
- The key of the propertyvalue
- The value of the property- Throws:
NullPointerException
- If the key or the value is nullUncheckedIOException
- If an I/O error occurs (optional)
-
writeProperty
public <T> void writeProperty(@NotNull @NotNull String key, @NotNull T value, @NotNull @NotNull Function<T, String> converter) Writes the given raw property to the underlying output.
The value is converted to a string using the given converter.- Type Parameters:
T
- The type of the value- Parameters:
key
- The key of the propertyvalue
- The value of the propertyconverter
- The converter to convert the value to a string- Throws:
NullPointerException
- If the key, the value or the converter is nullUncheckedIOException
- If an I/O error occurs (optional)
-
writeProperty
Writes the given properties to the underlying output.- Parameters:
properties
- The properties to write- Throws:
NullPointerException
- If the properties are nullUncheckedIOException
- If an I/O error occurs (optional)
-
writeProperty
Writes the given property to the underlying output.- Parameters:
property
- The property to write- Throws:
NullPointerException
- If the property is nullUncheckedIOException
- If an I/O error occurs (optional)
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-