Class ProjectFile
java.lang.Object
com.j3d.storage.files.protocol.GenericFileProtocol
com.j3d.storage.files.protocol.proj.ProjectFile
- All Implemented Interfaces:
FileProtocol
ProjectFile is an abstract base class for J3D project file protocols.
It defines the common interface and properties for reading and writing
project files (typically .j3p files) of different versions.
Concrete implementations, such as PF1, PF2 or PF3,
handle the specific serialization and deserialization logic for their respective
file formats.
This class also provides utility methods for retrieving specific protocol versions based on an integer identifier.
- Author:
- Lehlogonolo Poole
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Set<ProjectFile.PF> private final Set<ProjectFile.PF> private final Stringprivate final Stringprivate final int -
Constructor Summary
ConstructorsConstructorDescriptionProjectFile(int version, Set<ProjectFile.PF> convertibleTo, Set<ProjectFile.PF> convertibleFrom) Da default constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic intConverts aColorobject to its integer ARGB representation.Returns a set ofFileProtocolinstances from which this protocol can be converted (downgraded or upgraded from).Returns a set ofFileProtocolinstances to which this protocol can be converted (upgraded).The protocol's extensionstatic ProjectFilegetFromVersion(int version) Gets a Consumer that reads the protocol-specific header information from a DataInputStream.Gets a Consumer that writes the protocol-specific header information to a DataOutputStream.Gets the protocol header string that uniquely identifies this specific file protocol.intGets the version number of the protocol.static voidhandleErr(ProjectFile vers, Exception err, BiConsumer<Integer, ProjectFile> loadable) Handles errors that occur during file loading, particularlyUnsupportedVersionExceptionwhich indicates an attempt to load an older version of a project file.static ColorintToCol(int col) Converts an integer RGB representation back to aColorobject.<T extends ArrayList>
TReads a file from the specified path and returns its content as an object of type T.<T extends ArrayList>
voidWrites the provided data to a file at the specified path.Methods inherited from class com.j3d.storage.files.protocol.GenericFileProtocol
readHeader, writeHeader
-
Field Details
-
VERSION
private final int VERSION -
HEADER
- See Also:
-
EXTENSION
- See Also:
-
convertibleTo
-
convertibleFrom
-
-
Constructor Details
-
ProjectFile
public ProjectFile(int version, Set<ProjectFile.PF> convertibleTo, Set<ProjectFile.PF> convertibleFrom) Da default constructor- Parameters:
version- The version of this project file protocolconvertibleTo- The set of FileProtocol that this can be upgraded to.convertibleFrom- The set of FileProtocol that can upgrade to this.
-
-
Method Details
-
colToInt
Converts aColorobject to its integer ARGB representation. The integer includes the alpha component.- Parameters:
col- TheColorobject to convert.- Returns:
- The integer representation of the color, including alpha.
-
intToCol
Converts an integer RGB representation back to aColorobject. The integer is expected to include the alpha component (ARGB format).- Parameters:
col- The integer representation of the colour.- Returns:
- A new
Colorobject.
-
getProtocolHeader
Description copied from interface:FileProtocolGets the protocol header string that uniquely identifies this specific file protocol.- Specified by:
getProtocolHeaderin interfaceFileProtocol- Returns:
- The protocol header.
-
getProtocolVersion
public int getProtocolVersion()Description copied from interface:FileProtocolGets the version number of the protocol.- Specified by:
getProtocolVersionin interfaceFileProtocol- Returns:
- The protocol version.
-
getExtension
Description copied from interface:FileProtocolThe protocol's extension- Specified by:
getExtensionin interfaceFileProtocol- Returns:
- The protocol's extension
-
convertibleToHigher
Description copied from interface:FileProtocolReturns a set ofFileProtocolinstances to which this protocol can be converted (upgraded). These are typically newer versions of the protocol.- Specified by:
convertibleToHigherin interfaceFileProtocol- Returns:
- A set of higher version protocols this protocol can convert to.
-
convertibleFromLower
Description copied from interface:FileProtocolReturns a set ofFileProtocolinstances from which this protocol can be converted (downgraded or upgraded from). These are typically older versions of the protocol that can be read and converted into this protocol.- Specified by:
convertibleFromLowerin interfaceFileProtocol- Returns:
- A set of lower version protocols that can be converted to this protocol.
-
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- 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
-
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- 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.
-
getHeaderWriter
Description copied from interface:FileProtocolGets a Consumer that writes the protocol-specific header information to a DataOutputStream.- Specified by:
getHeaderWriterin interfaceFileProtocol- Returns:
- A Consumer that writes the header.
-
getHeaderReader
Description copied from interface:FileProtocolGets a Consumer that reads the protocol-specific header information from a DataInputStream.- Specified by:
getHeaderReaderin interfaceFileProtocol- Returns:
- A Consumer that reads the header.
- Throws:
IOException- If an I/O error occurs.
-
getFromVersion
-
handleErr
public static void handleErr(ProjectFile vers, Exception err, BiConsumer<Integer, ProjectFile> loadable) Handles errors that occur during file loading, particularlyUnsupportedVersionExceptionwhich indicates an attempt to load an older version of a project file.- Parameters:
vers- The currentProjectFileinstance being used for loading.err- The exception that occurred during loading.loadable- ABiConsumerthat accepts the current protocol version and the convertible protocol if anUnsupportedVersionExceptionis caught and a conversion is possible.
-