Class InputProvider

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

public class InputProvider extends Object implements AutoCloseable
Input provider for reading data from a file or stream.
This class provides several constructors for different input sources.

Primary usage of this class is to provide an input stream for different input sources.
This can be useful for other readers or parsers 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 InputStream
    The input stream for reading data.
  • Constructor Summary

    Constructors
    Constructor
    Description
    InputProvider(@NotNull File file)
    Constructs a new input provider for the given file.
    InputProvider(@NotNull InputStream stream)
    Constructs a new input provider for the given input stream.
    InputProvider(@NotNull String file)
    Constructs a new input provider for the given file.
    InputProvider(@NotNull String path, @NotNull String fileName)
    Constructs a new input provider for the given path and file name.
    The path and file name are concatenated to a file.
    InputProvider(@NotNull Path path)
    Constructs a new input provider for the given path.
    InputProvider(@NotNull ResourceLocation location)
    Constructs a new input provider for the given resource location.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    @NotNull InputStream
    Returns the internal input stream for reading data.
    The input stream should not be used directly, it is intended to be passed to other readers or parsers.

    Methods inherited from class java.lang.Object

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

    • stream

      private final InputStream stream
      The input stream for reading data.
  • Constructor Details

    • InputProvider

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

      public InputProvider(@NotNull @NotNull String path, @NotNull @NotNull String fileName)
      Constructs a new input 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
    • InputProvider

      public InputProvider(@NotNull @NotNull Path path)
      Constructs a new input 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
    • InputProvider

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

      public InputProvider(@NotNull @NotNull ResourceLocation location)
      Constructs a new input provider for the given resource location.
      Parameters:
      location - The resource location to read data from
      Throws:
      NullPointerException - If the resource location is null
      UncheckedIOException - If the resource could not be opened
    • InputProvider

      public InputProvider(@NotNull @NotNull InputStream stream)
      Constructs a new input provider for the given input stream.
      Parameters:
      stream - The input stream to read data from
      Throws:
      NullPointerException - If the input stream is null
  • Method Details

    • getStream

      @NotNull public @NotNull InputStream getStream()
      Returns the internal input stream for reading data.
      The input stream should not be used directly, it is intended to be passed to other readers or parsers.
      Returns:
      The input stream
    • close

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