So, my problem has basically two sub-problems.
I want to create my custom file type, probably with UTF-8 encoding. I think I can do that only by saving a file with prefered extension with some method I don't know yet to set encoding to UTF-8, or anything that would fit.
My extension would be ".molb".
Now, the problem is that I need to write 3d Objects, such as Spheres and Cylinders to that file, and when I open the file, to be recognized and added to my Universe in some way.
Some articles were suggesting Serializing objects and using FileBuffers, but none actually helped me understand how can I apply this to my own problem.
To clarify, I will give the following example: This image shows some objects (a cylinder and a sphere) that should be saved in a form or another, in a file so when that file is opened, the objects appear with the saved atributes (position, color, orientation etc).Also my file would contain an Array storing the xyz positions of the spheres
if your classes implement Serializable
you can write them to file very simply.
DataOutputStream os = new DataOutputStream(new FileOutputStream("myfile.molb"));
os.writeObject(sphare);
os.close();
This file is binary. You do not have to care about encoding.
If however you want to serialize your object using XML, JSON or other text format you will probably want to open wrap stream with writer using other constructor that accepts encoding: new OutputStreamWriter(new FileOutputStream("my.txt"), "UTF-8)"
.
You will also have to add some annotations (e.g. JAXB or Jakson) to enable object-to-xml (or json) serialization.