Class OutputProvider

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

public class OutputProvider extends Object implements AutoCloseable
Output provider for writing data to a file or stream.
This class provides several constructors for different types of output sources.

Primary usage of this class is to provide an output stream for different output sources.
This can be useful for other writers or formatters to keep their constructors clean and simple.

The class is also AutoCloseable, so it can be used in try-with-resources statements.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final OutputStream
    The output stream for writing data.
  • Constructor Summary

    Constructors
    Constructor
    Description
    OutputProvider(@NotNull File file)
    Constructs a new output provider for the given file.
    OutputProvider(@NotNull OutputStream stream)
    Constructs a new output provider for the given output stream.
    OutputProvider(@NotNull String file)
    Constructs a new output provider for the given file.
    OutputProvider(@NotNull String path, @NotNull String fileName)
    Constructs a new output provider for the given path and file name.
    The path and file name are concatenated to a file.
    OutputProvider(@NotNull Path path)
    Constructs a new output provider for the given path.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    @NotNull OutputStream
    Returns the internal output stream for writing data.
    The output stream should not be used directly, it is intended to be passed to other writers or formatters.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • stream

      private final OutputStream stream
      The output stream for writing data.
  • Constructor Details

    • OutputProvider

      public OutputProvider(@NotNull @NotNull String file)
      Constructs a new output provider for the given file.
      Parameters:
      file - The file to write data to
      Throws:
      NullPointerException - If the file is null
      UncheckedIOException - If the file is not found
    • OutputProvider

      public OutputProvider(@NotNull @NotNull String path, @NotNull @NotNull String fileName)
      Constructs a new output provider for the given path and file name.
      The path and file name are concatenated to a file.
      Parameters:
      path - The path to the file
      fileName - The name of the file
      Throws:
      NullPointerException - If the path or file name is null
      UncheckedIOException - If the file is not found
    • OutputProvider

      public OutputProvider(@NotNull @NotNull Path path)
      Constructs a new output provider for the given path.
      Parameters:
      path - The path to the file
      Throws:
      NullPointerException - If the path is null
      UncheckedIOException - If the file is not found
    • OutputProvider

      public OutputProvider(@NotNull @NotNull File file)
      Constructs a new output provider for the given file.
      Parameters:
      file - The file to write data to
      Throws:
      NullPointerException - If the file is null
      UncheckedIOException - If the file is not found
    • OutputProvider

      public OutputProvider(@NotNull @NotNull OutputStream stream)
      Constructs a new output provider for the given output stream.
      Parameters:
      stream - The output stream to write data to
      Throws:
      NullPointerException - If the stream is null
  • Method Details

    • getStream

      @NotNull public @NotNull OutputStream getStream()
      Returns the internal output stream for writing data.
      The output stream should not be used directly, it is intended to be passed to other writers or formatters.
      Returns:
      The output stream
    • close

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