Class PropertyWriter

java.lang.Object
net.luis.utils.io.data.property.PropertyWriter
All Implemented Interfaces:
AutoCloseable

public class PropertyWriter extends Object implements AutoCloseable
Represents a writer for properties.
  • Field Details

    • config

      private final PropertyConfig config
      The configuration for the property writer.
    • writer

      private final BufferedWriter writer
      The internal io writer for writing the property.
  • Constructor Details

    • PropertyWriter

      public PropertyWriter(@NotNull @NotNull OutputProvider output)
      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 for
      config - The configuration for the properties writer
      Throws:
      NullPointerException - If the output or the configuration is null
  • Method Details

    • writeProperty

      public void writeProperty(@NotNull @NotNull String key, @NotNull @NotNull Object value)
      Writes the given raw property to the underlying output.
      Parameters:
      key - The key of the property
      value - The value of the property
      Throws:
      NullPointerException - If the key or the value is null
      UncheckedIOException - 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 property
      value - The value of the property
      converter - The converter to convert the value to a string
      Throws:
      NullPointerException - If the key, the value or the converter is null
      UncheckedIOException - If an I/O error occurs (optional)
    • writeProperty

      public void writeProperty(@NotNull @NotNull Properties properties)
      Writes the given properties to the underlying output.
      Parameters:
      properties - The properties to write
      Throws:
      NullPointerException - If the properties are null
      UncheckedIOException - If an I/O error occurs (optional)
    • writeProperty

      public void writeProperty(@NotNull @NotNull Property property)
      Writes the given property to the underlying output.
      Parameters:
      property - The property to write
      Throws:
      NullPointerException - If the property is null
      UncheckedIOException - If an I/O error occurs (optional)
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException