Interface TextObject

All Known Implementing Classes:
UDMFMap

public interface TextObject
Common elements of all objects that are loaded from text data. This provides a general interface for getting text-based object data.
Author:
Matthew Tropiano
  • Method Details

    • toText

      default String toText()
      Gets the textual representation of this object.
      Returns:
      this object as a String.
    • fromText

      default void fromText(String string) throws IOException
      Reads in the textual representation of this object and sets its fields.
      Parameters:
      string - the string array to read from.
      Throws:
      IOException - if a read error occurs.
    • readText

      void readText(Reader reader) throws IOException
      Reads from an Reader and sets this object's fields.
      Parameters:
      reader - the Reader to read from.
      Throws:
      IOException - if a read error occurs.
    • readFile

      default void readFile(File file) throws IOException
      Reads from a File and sets this object's fields. The charset encoding used is the default platform encoding.
      Parameters:
      file - the File to read from.
      Throws:
      FileNotFoundException - if the file could not be found.
      IOException - if a read error occurs.
      SecurityException - if the file could not be opened due to OS permissions.
      Since:
      2.13.0
      See Also:
    • readFile

      default void readFile(File file, Charset charset) throws IOException
      Reads from a File and sets this object's fields.
      Parameters:
      file - the File to read from.
      charset - the charset encoding to use for reading.
      Throws:
      FileNotFoundException - if the file could not be found.
      IOException - if a read error occurs.
      SecurityException - if the file could not be opened due to OS permissions.
      Since:
      2.13.0
    • writeText

      void writeText(Writer writer) throws IOException
      Writes this object to a Writer.
      Parameters:
      writer - the Writer to write to.
      Throws:
      IOException - if a write error occurs.
    • writeFile

      default void writeFile(File file) throws IOException
      Writes this object to a File. The file's contents are overwritten. The charset encoding used is the default platform encoding.
      Parameters:
      file - the File to write to.
      Throws:
      FileNotFoundException - if the file exists, but is a directory.
      IOException - if a write error occurs.
      SecurityException - if the file could not be written to due to OS permissions.
      Since:
      2.13.0
      See Also:
    • writeFile

      default void writeFile(File file, Charset charset) throws IOException
      Writes this object to a File. The file's contents are overwritten.
      Parameters:
      file - the File to write to.
      charset - the charset encoding to use for writing.
      Throws:
      FileNotFoundException - if the file exists, but is a directory.
      IOException - if a write error occurs.
      SecurityException - if the file could not be written to due to OS permissions.
      Since:
      2.13.0
      See Also:
    • writeFile

      default void writeFile(File file, boolean append) throws IOException
      Writes this object to a File. The charset encoding used is the default platform encoding.
      Parameters:
      file - the File to write to.
      append - if true, the content is written to the end of the file.
      Throws:
      FileNotFoundException - if the file exists, but is a directory.
      IOException - if a write error occurs.
      SecurityException - if the file could not be written to due to OS permissions.
      Since:
      2.13.0
      See Also:
    • writeFile

      default void writeFile(File file, boolean append, Charset charset) throws IOException
      Writes this object to a File.
      Parameters:
      file - the File to write to.
      append - if true, the content is written to the end of the file.
      charset - the charset encoding to use for writing.
      Throws:
      FileNotFoundException - if the file exists, but is a directory.
      IOException - if a write error occurs.
      SecurityException - if the file could not be written to due to OS permissions.
      Since:
      2.13.0
    • create

      static <TO extends TextObject> TO create(Class<TO> toClass, String string) throws IOException
      Creates a single object of a specific class from a string.
      Type Parameters:
      TO - the object type, a subtype of TextObject.
      Parameters:
      toClass - the class to create.
      string - the string.
      Returns:
      an array of length count of the created objects.
      Throws:
      IOException - if an error occurs during the read - most commonly "not enough bytes".
    • read

      static <TO extends TextObject> TO read(Class<TO> toClass, Reader reader) throws IOException
      Creates a single object of a specific class from from an InputStream.
      Type Parameters:
      TO - the object type, a subtype of TextObject.
      Parameters:
      toClass - the class to create.
      reader - the reader.
      Returns:
      an array of length count of the created objects.
      Throws:
      IOException - if an error occurs during the read - most commonly "not enough bytes".