Improve RenderMetaDataFile constructors

This commit is contained in:
James Seibel
2023-02-18 08:55:28 -06:00
parent b16ae15f94
commit 1916ad49c4
2 changed files with 33 additions and 5 deletions
@@ -173,7 +173,17 @@ public class RenderFileHandler implements ILodRenderSourceProvider
RenderMetaDataFile newMetaFile;
try
{
newMetaFile = new RenderMetaDataFile(this, pos);
File renderMetaFile = this.computeRenderFilePath(pos);
boolean renderFileExists = renderMetaFile.exists();
if (renderFileExists)
{
newMetaFile = RenderMetaDataFile.createFromExistingFile(this, renderMetaFile);
}
else
{
newMetaFile = RenderMetaDataFile.createNewFileForPos(this, pos);
}
}
catch (IOException e)
{
@@ -50,8 +50,19 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
/** Creates a new metaFile */
public RenderMetaDataFile(RenderFileHandler fileHandler, DhSectionPos pos) throws IOException
//=============//
// constructor //
//=============//
/**
* NOTE: should only be used if there is NOT an existing file.
* @throws IOException if a file already exists for this position
*/
public static RenderMetaDataFile createNewFileForPos(RenderFileHandler fileHandler, DhSectionPos pos) throws IOException
{
return new RenderMetaDataFile(fileHandler, pos);
}
private RenderMetaDataFile(RenderFileHandler fileHandler, DhSectionPos pos) throws IOException
{
super(fileHandler.computeRenderFilePath(pos), pos);
this.fileHandler = fileHandler;
@@ -59,8 +70,15 @@ public class RenderMetaDataFile extends AbstractMetaDataFile
this.doesFileExist = this.path.exists();
}
/** Uses the existing metaFile */
public RenderMetaDataFile(RenderFileHandler fileHandler, File path) throws IOException
/**
* NOTE: should only be used if there IS an existing file.
* @throws IOException if no file exists for this position
*/
public static RenderMetaDataFile createFromExistingFile(RenderFileHandler fileHandler, File path) throws IOException
{
return new RenderMetaDataFile(fileHandler, path);
}
private RenderMetaDataFile(RenderFileHandler fileHandler, File path) throws IOException
{
super(path);
this.fileHandler = fileHandler;