Package com.irurueta.geometry.io
Class Loader
java.lang.Object
com.irurueta.geometry.io.Loader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
LoaderBinary,LoaderOBJ,LoaderPLY,LoaderSTL
Abstract class defining the interface for file loaders.
Specific implementations must be done for each file format to be supported.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault limit of bytes to keep mapped in memory.protected FileFile to be read.private longLimit of bytes to keep mapped in memory.protected LoaderListenerListener in charge of notifying when the decoding starts, ends or progress events.protected booleanBoolean indicating that this instance is locked because decoding is being done.protected AbstractFileReaderAndWriterInstance in charge of reading data from file. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedLoader()Default Constructor.protectedLoader(LoaderListener listener) Constructor.protectedConstructor.protectedLoader(File f, LoaderListener listener) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes file provided to this loader.longGet 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 MeshFormatReturns mesh format this instance is capable of loading.booleanhasFile()Indicates whether a file to be loaded has already been set.booleanisLocked()Determines whether this instance is locked.abstract booleanisReady()Determines whether enough parameters have been set so that the loading process can start.abstract booleanDetermines if provided file is a valid file that can be read by this loader.abstract LoaderIteratorload()Starts the loading process of provided file.voidSets file to be loaded.voidsetFileSizeLimitToKeepInMemory(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).voidsetListener(LoaderListener listener) Sets listener of this instance.protected voidsetLocked(boolean locked) Sets the lock value of this instance so that no parameters cannot be changed until this instance is unlocked.
-
Field Details
-
DEFAULT_FILE_SIZE_LIMIT_TO_KEEP_IN_MEMORY
public static final long DEFAULT_FILE_SIZE_LIMIT_TO_KEEP_IN_MEMORYDefault limit of bytes to keep mapped in memory.- See Also:
-
reader
Instance in charge of reading data from file. -
locked
protected boolean lockedBoolean indicating that this instance is locked because decoding is being done. -
listener
Listener in charge of notifying when the decoding starts, ends or progress events. -
file
File to be read. -
fileSizeLimitToKeepInMemory
private long fileSizeLimitToKeepInMemoryLimit 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
Constructor.- Parameters:
f- file to be read.- Throws:
IOException- raised if provided file does not exist or an I/O exception occurs.
-
Loader
Constructor.- Parameters:
listener- listener to notify start, end and progress events.
-
Loader
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
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
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
Closes file provided to this loader.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- 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
Returns listener of this instance. A listener notifies of start, end and progress change events.- Returns:
- listener of this instance.
-
setListener
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
Returns mesh format this instance is capable of loading.- Returns:
- Mesh format.
-
isValidFile
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
public abstract LoaderIterator load() throws LockedException, NotReadyException, IOException, LoaderExceptionStarts 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.
-