Introduction
The java rcfiletyperegistry example is extracted from the most popular open source projects, you can refer to the following example for usage.
Programming language: Java
Namespace/package name: ivorius.reccomplex.files
Example#1File:
StructureSaveHandler.javaProject:
skydark/RecurrentComplex
public boolean deleteGenericStructure(String structureName, boolean activeFolder) {
try {
File parent = RCFileTypeRegistry.getStructuresDirectory(activeFolder);
return parent != null
&& (new File(parent, structureName + "." + FILE_SUFFIX).delete()
|| /* Legacy */ new File(parent, structureName + ".zip").delete());
} catch (Throwable e) {
RecurrentComplex.logger.error("Error when deleting structure", e);
}
return false;
}
Example#2File:
StructureSaveHandler.javaProject:
skydark/RecurrentComplex
public boolean saveGenericStructure(
GenericStructureInfo info, String structureName, boolean activeFolder) {
File parent = RCFileTypeRegistry.getStructuresDirectory(activeFolder);
if (parent != null) {
String json = registry.createJSONFromStructure(info);
if (RecurrentComplex.USE_ZIP_FOR_STRUCTURE_FILES) {
File newFile = new File(parent, structureName + "." + FILE_SUFFIX);
boolean failed = false;
try {
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(newFile));
addZipEntry(zipOutputStream, STRUCTURE_INFO_JSON_FILENAME, json.getBytes());
addZipEntry(
zipOutputStream,
WORLD_DATA_NBT_FILENAME,
CompressedStreamTools.compress(info.worldDataCompound));
zipOutputStream.close();
} catch (Exception ex) {
RecurrentComplex.logger.error("Could not write structure to zip file", ex);
failed = true;
}
return !failed && newFile.exists();
} else {
File newFile = new File(parent, structureName + ".json");
boolean failed = false;
try {
FileUtils.writeStringToFile(newFile, json);
} catch (Exception e) {
RecurrentComplex.logger.error("Could not write structure zip to folder", e);
failed = true;
}
return !failed && newFile.exists();
}
}
return false;
}