Class Loader

java.lang.Object
com.irurueta.geometry.io.Loader
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
LoaderBinary, LoaderOBJ, LoaderPLY, LoaderSTL

public abstract class Loader extends Object implements Closeable
Abstract class defining the interface for file loaders. Specific implementations must be done for each file format to be supported.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Default limit of bytes to keep mapped in memory.
    protected File
    File to be read.
    private long
    Limit of bytes to keep mapped in memory.
    protected LoaderListener
    Listener in charge of notifying when the decoding starts, ends or progress events.
    protected boolean
    Boolean indicating that this instance is locked because decoding is being done.
    Instance in charge of reading data from file.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Default Constructor.
    protected
    Constructor.
    protected
    Constructor.
    protected
    Loader(File f, LoaderListener listener)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes file provided to this loader.
    long
    Get maximum size (in bytes) to determine whether a file is completely cached in memory (if lower than maximum size), or if it is just streamed (if greater than maximum size).
    Returns listener of this instance.
    abstract MeshFormat
    Returns mesh format this instance is capable of loading.
    boolean
    Indicates whether a file to be loaded has already been set.
    boolean
    Determines whether this instance is locked.
    abstract boolean
    Determines whether enough parameters have been set so that the loading process can start.
    abstract boolean
    Determines if provided file is a valid file that can be read by this loader.
    Starts the loading process of provided file.
    void
    Sets file to be loaded.
    void
    setFileSizeLimitToKeepInMemory(long fileSizeLimitToKeepInMemory)
    Sets maximum size (in bytes) to determine whether a file is completely cached in memory (if lower than maximum size), or if it is just streamed (if greater than maximum size).
    void
    Sets listener of this instance.
    protected void
    setLocked(boolean locked)
    Sets the lock value of this instance so that no parameters cannot be changed until this instance is unlocked.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_FILE_SIZE_LIMIT_TO_KEEP_IN_MEMORY

      public static final long DEFAULT_FILE_SIZE_LIMIT_TO_KEEP_IN_MEMORY
      Default limit of bytes to keep mapped in memory.
      See Also:
    • reader

      protected AbstractFileReaderAndWriter reader
      Instance in charge of reading data from file.
    • locked

      protected boolean locked
      Boolean indicating that this instance is locked because decoding is being done.
    • listener

      protected LoaderListener listener
      Listener in charge of notifying when the decoding starts, ends or progress events.
    • file

      protected File file
      File to be read.
    • fileSizeLimitToKeepInMemory

      private long fileSizeLimitToKeepInMemory
      Limit of bytes to keep mapped in memory. If provided file exceeds this value, then it is not mapped into memory.
  • Constructor Details

    • Loader

      protected Loader()
      Default Constructor.
    • Loader

      protected Loader(File f) throws IOException
      Constructor.
      Parameters:
      f - file to be read.
      Throws:
      IOException - raised if provided file does not exist or an I/O exception occurs.
    • Loader

      protected Loader(LoaderListener listener)
      Constructor.
      Parameters:
      listener - listener to notify start, end and progress events.
    • Loader

      protected Loader(File f, LoaderListener listener) throws IOException
      Constructor.
      Parameters:
      f - file to be read.
      listener - listener to notify start, end and progress events.
      Throws:
      IOException - raised if provided file does not exist or an I/O exception occurs.
  • Method Details

    • getFileSizeLimitToKeepInMemory

      public long getFileSizeLimitToKeepInMemory()
      Get maximum size (in bytes) to determine whether a file is completely cached in memory (if lower than maximum size), or if it is just streamed (if greater than maximum size).
      Returns:
      Maximum size to determine whether file is cached in memory or not.
    • setFileSizeLimitToKeepInMemory

      public void setFileSizeLimitToKeepInMemory(long fileSizeLimitToKeepInMemory) throws LockedException
      Sets maximum size (in bytes) to determine whether a file is completely cached in memory (if lower than maximum size), or if it is just streamed (if greater than maximum size).
      Parameters:
      fileSizeLimitToKeepInMemory - maximum size to determine whether file is cached in memory or not.
      Throws:
      LockedException - if loader is locked because it is currently processing a file.
    • hasFile

      public boolean hasFile()
      Indicates whether a file to be loaded has already been set.
      Returns:
      True if file has already been provided, false otherwise.
    • setFile

      public void setFile(File f) throws LockedException, IOException
      Sets file to be loaded.
      Parameters:
      f - file to be loaded.
      Throws:
      LockedException - raised if this instance is loaded because a file is already being loaded.
      IOException - raised if provided file does not exist or if an I/O exception occurs.
    • close

      public void close() throws IOException
      Closes file provided to this loader.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error occurs.
    • isLocked

      public boolean isLocked()
      Determines whether this instance is locked. A loader remains locked while decoding of a file is being done. This instance will remain locked once the loading process starts until it finishes either successfully or not. While this instance remains locked no parameters can be changed, otherwise a LockedException will be raised.
      Returns:
      True if instance is locked, false otherwise.
    • setLocked

      protected void setLocked(boolean locked)
      Sets the lock value of this instance so that no parameters cannot be changed until this instance is unlocked.
      Parameters:
      locked - value that determines whether this instance is locked or not.
    • getListener

      public LoaderListener getListener()
      Returns listener of this instance. A listener notifies of start, end and progress change events.
      Returns:
      listener of this instance.
    • setListener

      public void setListener(LoaderListener listener) throws LockedException
      Sets listener of this instance. A listener notifies of start, end and progress change events.
      Parameters:
      listener - listener of this instance.
      Throws:
      LockedException - Raised if this instance is already locked.
    • isReady

      public abstract boolean isReady()
      Determines whether enough parameters have been set so that the loading process can start.
      Returns:
      True if this instance is ready to start loading a file, false otherwise.
    • getMeshFormat

      public abstract MeshFormat getMeshFormat()
      Returns mesh format this instance is capable of loading.
      Returns:
      Mesh format.
    • isValidFile

      public abstract boolean isValidFile() throws LockedException, IOException
      Determines if provided file is a valid file that can be read by this loader.
      Returns:
      true if file is valid, false otherwise.
      Throws:
      LockedException - raised if this instance is already locked.
      IOException - if an I/O error occurs.
    • load

      Starts the loading process of provided file. This method returns a LoaderIterator to start the iterative process to load a file in small chunks of data.
      Returns:
      a loader iterator to read the file in a step-by-step process.
      Throws:
      LockedException - raised if this instance is already locked.
      NotReadyException - raised if this instance is not yet ready.
      IOException - if an I/O error occurs.
      LoaderException - if file is corrupted or cannot be interpreted.