Class PF3
java.lang.Object
com.j3d.storage.files.protocol.GenericFileProtocol
com.j3d.storage.files.protocol.proj.ProjectFile
com.j3d.storage.files.protocol.proj.PF3
- All Implemented Interfaces:
FileProtocol
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.j3d.storage.files.protocol.proj.ProjectFile
ProjectFile.PF -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidWrites a special delimiter to indicate the start of an element within a list in the data stream.static voidWrites a special delimiter to indicate the beginning of a list in the data stream.static voidconsumeBeforeElement(DataInputStream dis, String errStr, int index) Consumes and validates the element delimiter from the data stream.static voidconsumeBeginList(DataInputStream dis, String errStr) Consumes and validates the beginning of a list delimiter from the data stream.static voidconsumeEndList(DataInputStream dis, String errStr) Consumes and validates the end of a list delimiter from the data stream.static voidendList(DataOutputStream dos) Writes a special delimiter to indicate the end of a list in the data stream.private static voidifAnyNull(String errStr, String id, String label, int code, SceneObject... objs) Checks if any of the providedSceneObjects are null.private static voidLogs a message to the application's log output.private static PF3.SuperMap<GCurve> readCurves(DataInputStream dis, PF3.SuperMap<GPoint> pointSuperMap, Spinner sp) Reads a list ofGCurveobjects from the providedDataInputStream.<T extends ArrayList>
TReads a file from the specified path and returns its content as an object of type T.readLayers(DataInputStream dis, Spinner sp) Reads a list ofLayerobjects from the providedDataInputStream.private static PF3.SuperMap<GLine> readLines(DataInputStream dis, PF3.SuperMap<GPoint> pointSuperMap, Spinner sp) Reads a list ofGLineobjects from the providedDataInputStream.private static PF3.SuperMap<GPoint> readPoints(DataInputStream dis, Spinner sp) Reads a list ofGPointobjects from the providedDataInputStream.static voidReads and validates a magic number (69) from the data stream for file integrity check.readThings(DataInputStream dis, HashMap<String, Layer> layers, Spinner sp) Reads a list ofThingobjects from the providedDataInputStream.private static PF3.SuperMap<GTri> readTris(DataInputStream dis, PF3.SuperMap<GLine> lines, PF3.SuperMap<GPoint> points, Spinner sp) Reads a list ofGTriobjects from the providedDataInputStream.private static voidwriteCurves(DataOutputStream dos, ArrayList<Pair<UUID, GCurve>> curves) Writes a list ofGCurveobjects to the providedDataOutputStream.<T extends ArrayList>
voidWrites the provided data to a file at the specified path.private voidwriteLayers(DataOutputStream dos, LayerList layers) Writes a list ofLayerobjects to the providedDataOutputStream.private static voidwriteLines(DataOutputStream dos, ArrayList<Pair<UUID, GLine>> lines) Writes a list ofGLineobjects to the providedDataOutputStream.private static voidwritePoints(DataOutputStream dos, ArrayList<Pair<UUID, GPoint>> points) Writes a list ofGPointobjects to the providedDataOutputStream.static voidWrites a magic number (69) to the data stream for file integrity check.private static voidwriteThings(DataOutputStream dos, ArrayList<Pair<String, Thing>> things) Writes a list ofThingobjects to the providedDataOutputStream.private static voidWrites a list ofGTriobjects to the providedDataOutputStream.Methods inherited from class com.j3d.storage.files.protocol.proj.ProjectFile
colToInt, convertibleFromLower, convertibleToHigher, getExtension, getFromVersion, getHeaderReader, getHeaderWriter, getProtocolHeader, getProtocolVersion, handleErr, intToColMethods inherited from class com.j3d.storage.files.protocol.GenericFileProtocol
readHeader, writeHeader
-
Constructor Details
-
PF3
public PF3()
-
-
Method Details
-
writeFile
Description copied from interface:FileProtocolWrites the provided data to a file at the specified path. This should be a direct inverse of the correspondingFileProtocol.readFile(String, String, Spinner)method.- Specified by:
writeFilein interfaceFileProtocol- Overrides:
writeFilein classProjectFile- Type Parameters:
T- The type of the data to be written, which must extend ArrayList.- Parameters:
path- The path to the file to be written.data- The data to be written to the file.
-
readFile
public <T extends ArrayList> T readFile(String path, String name, Spinner throbber) throws Exception Description copied from interface:FileProtocolReads a file from the specified path and returns its content as an object of type T. This should be a direct inverse of the correspondingFileProtocol.writeFile(String, String, ArrayList)method.- Specified by:
readFilein interfaceFileProtocol- Overrides:
readFilein classProjectFile- Type Parameters:
T- The type of the object to be returned.- Parameters:
path- The path to the file to be read.name- The name of the file to be read.throbber- The Spinner instance- Returns:
- The content of the file as an object of type T.
- Throws:
Exception
-
writeLayers
Writes a list ofLayerobjects to the providedDataOutputStream.- Parameters:
dos- TheDataOutputStreamto write to.layers- TheLayerListcontaining the layers to write.- Throws:
IOException- If an I/O error occurs.
-
readLayers
Reads a list ofLayerobjects from the providedDataInputStream.- Parameters:
dis- TheDataInputStreamto read from.sp- TheSpinnerto update progress.- Returns:
- A
HashMapwhere keys are layer names and values areLayerobjects. - Throws:
IOException- If an I/O error occurs or the file is corrupted.
-
writeThings
private static void writeThings(DataOutputStream dos, ArrayList<Pair<String, Thing>> things) throws IOExceptionWrites a list ofThingobjects to the providedDataOutputStream.- Parameters:
dos- TheDataOutputStreamto write to.things- AnArrayListofPairs, where each pair contains the parentUUID(as String) and theThingto write.- Throws:
IOException- If an I/O error occurs.
-
readThings
private static HashMap<String,Thing> readThings(DataInputStream dis, HashMap<String, Layer> layers, Spinner sp) throws IOExceptionReads a list ofThingobjects from the providedDataInputStream.- Parameters:
dis- TheDataInputStreamto read from.layers- AHashMapof existingLayers, used to assign parent layers to things.sp- TheSpinnerto update progress.- Returns:
- A
HashMapwhere keys are thing IDs (as String) and values areThingobjects. - Throws:
IOException- If an I/O error occurs, the file is corrupted, or a parent layer is not found.
-
writeCurves
private static void writeCurves(DataOutputStream dos, ArrayList<Pair<UUID, GCurve>> curves) throws IOExceptionWrites a list ofGCurveobjects to the providedDataOutputStream.- Parameters:
dos- TheDataOutputStreamto write to.curves- AnArrayListofPairs, where each pair contains the parentUUIDand theGCurveto write.- Throws:
IOException- If an I/O error occurs.
-
readCurves
private static PF3.SuperMap<GCurve> readCurves(DataInputStream dis, PF3.SuperMap<GPoint> pointSuperMap, Spinner sp) throws IOException Reads a list ofGCurveobjects from the providedDataInputStream.- Parameters:
dis- TheDataInputStreamto read from.pointSuperMap- APF3.SuperMapcontainingGPointobjects, used to resolve curve points.sp- TheSpinnerto update progress.- Returns:
- A
PF3.SuperMapcontaining the readGCurveobjects, mapped by their ID and parent thing ID. - Throws:
IOException- If an I/O error occurs or the file is corrupted.
-
writeTris
private static void writeTris(DataOutputStream dos, ArrayList<Pair<UUID, GTri>> tris) throws IOExceptionWrites a list ofGTriobjects to the providedDataOutputStream.- Parameters:
dos- TheDataOutputStreamto write to.tris- AnArrayListofPairs, where each pair contains the parentUUIDand theGTrito write.- Throws:
IOException- If an I/O error occurs.
-
readTris
private static PF3.SuperMap<GTri> readTris(DataInputStream dis, PF3.SuperMap<GLine> lines, PF3.SuperMap<GPoint> points, Spinner sp) throws IOException Reads a list ofGTriobjects from the providedDataInputStream.- Parameters:
dis- TheDataInputStreamto read from.lines- APF3.SuperMapcontainingGLineobjects, used to resolve triangle legs.points- APF3.SuperMapcontainingGPointobjects, used to resolve triangle winding points.sp- TheSpinnerto update progress.- Returns:
- A
PF3.SuperMapcontaining the readGTriobjects, mapped by their ID and parent thing ID. - Throws:
IOException- If an I/O error occurs or the file is corrupted.
-
writeLines
private static void writeLines(DataOutputStream dos, ArrayList<Pair<UUID, GLine>> lines) throws IOExceptionWrites a list ofGLineobjects to the providedDataOutputStream.- Parameters:
dos- TheDataOutputStreamto write to.lines- AnArrayListofPairs, where each pair contains the parentUUIDand theGLineto write.- Throws:
IOException- If an I/O error occurs.
-
readLines
private static PF3.SuperMap<GLine> readLines(DataInputStream dis, PF3.SuperMap<GPoint> pointSuperMap, Spinner sp) throws IOException Reads a list ofGLineobjects from the providedDataInputStream.- Parameters:
dis- TheDataInputStreamto read from.pointSuperMap- APF3.SuperMapcontainingGPointobjects, used to resolve line endpoints.sp- TheSpinnerto update progress.- Returns:
- A
PF3.SuperMapcontaining the readGLineobjects, mapped by their ID and parent thing ID. - Throws:
IOException- If an I/O error occurs or the file is corrupted.
-
writePoints
private static void writePoints(DataOutputStream dos, ArrayList<Pair<UUID, GPoint>> points) throws IOExceptionWrites a list ofGPointobjects to the providedDataOutputStream.- Parameters:
dos- TheDataOutputStreamto write to.points- AnArrayListofPairs, where each pair contains the parentUUIDand theGPointto write.- Throws:
IOException- If an I/O error occurs.
-
readPoints
Reads a list ofGPointobjects from the providedDataInputStream.- Parameters:
dis- TheDataInputStreamto read from.sp- TheSpinnerto update progress.- Returns:
- A
PF3.SuperMapcontaining the readGPointobjects, mapped by their ID and parent thing ID. - Throws:
IOException- If an I/O error occurs or the file is corrupted.
-
beginList
Writes a special delimiter to indicate the beginning of a list in the data stream.- Parameters:
dos- TheDataOutputStreamto write to.- Throws:
IOException- If an I/O error occurs.
-
consumeBeginList
Consumes and validates the beginning of a list delimiter from the data stream.- Parameters:
dis- TheDataInputStreamto read from.- Throws:
IOException- If an I/O error occurs or the expected delimiter is not found.
-
endList
Writes a special delimiter to indicate the end of a list in the data stream.- Parameters:
dos- TheDataOutputStreamto write to.- Throws:
IOException- If an I/O error occurs.
-
consumeEndList
Consumes and validates the end of a list delimiter from the data stream.- Parameters:
dis- TheDataInputStreamto read from.- Throws:
IOException- If an I/O error occurs or the expected delimiter is not found.
-
beforeElement
Writes a special delimiter to indicate the start of an element within a list in the data stream.- Parameters:
dos- TheDataOutputStreamto write to.- Throws:
IOException- If an I/O error occurs.
-
consumeBeforeElement
public static void consumeBeforeElement(DataInputStream dis, String errStr, int index) throws IOException Consumes and validates the element delimiter from the data stream.- Parameters:
dis- TheDataInputStreamto read from.- Throws:
IOException- If an I/O error occurs or the expected delimiter is not found.
-
writeSixNine
Writes a magic number (69) to the data stream for file integrity check.- Parameters:
dos- TheDataOutputStreamto write to.- Throws:
IOException- If an I/O error occurs.
-
readSixNine
Reads and validates a magic number (69) from the data stream for file integrity check.- Parameters:
dis- TheDataInputStreamto read from.- Throws:
IOException- If an I/O error occurs or the expected magic number is not found.
-
msg
Logs a message to the application's log output.- Parameters:
message- The message string to be logged.
-
ifAnyNull
private static void ifAnyNull(String errStr, String id, String label, int code, SceneObject... objs) Checks if any of the providedSceneObjects are null. If a null object is found, it handles aProjectFileExceptionindicating a corrupted file. This is typically used during file reading to ensure all referenced objects exist.- Parameters:
errStr- A string describing the type of object being checked (e.g., "tri", "curve").id- The ID of the main object that references the potentially null objects.label- A string describing the type of referenced object (e.g., "point", "line").code- The error code to associate with theProjectFileException.objs- A variable argument list ofSceneObjects to check for null.
-