commit 40d2489525ed0e8de251ccc3c845026adfa454a5
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Mon Dec 1 23:35:13 2025 +0100

    new package 'platform' and implementations of ready/writing a file.

diff --git a/src/main/java/org/distorted/library/mesh/MeshBase.kt b/src/main/java/org/distorted/library/mesh/MeshBase.kt
index 7487290..b84e63e 100644
--- a/src/main/java/org/distorted/library/mesh/MeshBase.kt
+++ b/src/main/java/org/distorted/library/mesh/MeshBase.kt
@@ -26,14 +26,13 @@ import org.distorted.library.effect.VertexEffect
 import org.distorted.library.effectqueue.EffectQueue
 import org.distorted.library.main.DistortedLibrary
 import org.distorted.library.main.InternalBuffer
+import org.distorted.library.platform.FileReader
+import org.distorted.library.platform.FileWriter
 import org.distorted.library.program.DistortedProgram
 import org.distorted.library.type.Static4D
 import org.distorted.library.uniformblock.UniformBlockAssociation
 import org.distorted.library.uniformblock.UniformBlockCenter
 
-import java.io.DataInputStream
-import java.io.DataOutputStream
-import java.io.IOException
 import java.nio.ByteBuffer
 import java.nio.ByteOrder
 
@@ -914,7 +913,7 @@ abstract class MeshBase
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
     // Return the number of bytes read.
-    fun read(stream: DataInputStream): Int
+    fun read(reader: FileReader): Int
     {
         var buffer = ByteArray(BYTES_PER_FLOAT*4)
         val version: Int
@@ -926,7 +925,7 @@ abstract class MeshBase
         //////////////////////////////////////////////////////////////////////////////////////////
         try
         {
-            stream.read(buffer)
+            reader.read(buffer)
             val byteBuf = ByteBuffer.wrap(buffer)
 
             version = byteBuf.getInt(0)
@@ -968,7 +967,7 @@ abstract class MeshBase
 
             try
             {
-                stream.read(buffer)
+                reader.read(buffer)
             }
             catch (e: Exception)
             {
@@ -1094,57 +1093,50 @@ abstract class MeshBase
     /**
      * Write the Mesh to a File.
      */
-    fun write(stream: DataOutputStream)
+    fun write(writer: FileWriter)
     {
         var tex: TexComponent
 
         val numTex = mTexComponent.size
         val numEff = mEffComponent.size
 
-        try
-        {
-            stream.writeInt(2) // version
-            stream.writeInt(numVertices)
-            stream.writeInt(numTex)
-            stream.writeInt(numEff)
+        writer.writeInt(2) // version
+        writer.writeInt(numVertices)
+        writer.writeInt(numTex)
+        writer.writeInt(numEff)
 
-            for (i in 0 until numTex)
-            {
-                tex = mTexComponent[i]
-
-                stream.writeFloat(tex.mEndIndex.toFloat())
-                stream.writeFloat(tex.mTextureMap.get0())
-                stream.writeFloat(tex.mTextureMap.get1())
-                stream.writeFloat(tex.mTextureMap.get2())
-                stream.writeFloat(tex.mTextureMap.get3())
-            }
-
-            for (i in 0 until numEff)
-            {
-                stream.writeFloat(mEffComponent[i].toFloat())
-            }
+        for (i in 0 until numTex)
+        {
+            tex = mTexComponent[i]
 
-            val centers = if (useCenters) mUBC!!.backingArray else FloatArray(4*numEff)
+            writer.writeFloat(tex.mEndIndex.toFloat())
+            writer.writeFloat(tex.mTextureMap.get0())
+            writer.writeFloat(tex.mTextureMap.get1())
+            writer.writeFloat(tex.mTextureMap.get2())
+            writer.writeFloat(tex.mTextureMap.get3())
+        }
 
-            for (i in 0 until numEff)
-            {
-                stream.writeFloat(centers[4*i])
-                stream.writeFloat(centers[4*i+1])
-                stream.writeFloat(centers[4*i+2])
-            }
+        for (i in 0 until numEff)
+        {
+            writer.writeFloat(mEffComponent[i].toFloat())
+        }
 
-            val vertBuf1 = ByteBuffer.allocate(VERT1_SIZE*numVertices)
-            vertBuf1.asFloatBuffer().put(mVertAttribs1)
-            val vertBuf2 = ByteBuffer.allocate(VERT2_SIZE*numVertices)
-            vertBuf2.asFloatBuffer().put(mVertAttribs2)
+        val centers = if (useCenters) mUBC!!.backingArray else FloatArray(4*numEff)
 
-            stream.write(vertBuf1.array())
-            stream.write(vertBuf2.array())
-        }
-        catch (ex: IOException)
+        for (i in 0 until numEff)
         {
-            DistortedLibrary.logMessage("MeshBase: IOException trying to write a mesh: $ex")
+            writer.writeFloat(centers[4*i])
+            writer.writeFloat(centers[4*i+1])
+            writer.writeFloat(centers[4*i+2])
         }
+
+        val vertBuf1 = ByteBuffer.allocate(VERT1_SIZE*numVertices)
+        vertBuf1.asFloatBuffer().put(mVertAttribs1)
+        val vertBuf2 = ByteBuffer.allocate(VERT2_SIZE*numVertices)
+        vertBuf2.asFloatBuffer().put(mVertAttribs2)
+
+        writer.write(vertBuf1.array())
+        writer.write(vertBuf2.array())
     }
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/mesh/MeshFile.kt b/src/main/java/org/distorted/library/mesh/MeshFile.kt
index 415f24a..bc6f7db 100644
--- a/src/main/java/org/distorted/library/mesh/MeshFile.kt
+++ b/src/main/java/org/distorted/library/mesh/MeshFile.kt
@@ -20,7 +20,7 @@
 
 package org.distorted.library.mesh
 
-import java.io.DataInputStream
+import org.distorted.library.platform.FileReader
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
@@ -38,9 +38,9 @@ class MeshFile : MeshBase
      *
      * File format: as written by MeshBase.write().
      */
-    constructor(stream: DataInputStream) : super()
+    constructor(reader: FileReader) : super()
     {
-        numBytes = read(stream)
+        numBytes = read(reader)
     }
 
     ///////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/main/java/org/distorted/library/platform/FileReader.kt b/src/main/java/org/distorted/library/platform/FileReader.kt
new file mode 100644
index 0000000..e767382
--- /dev/null
+++ b/src/main/java/org/distorted/library/platform/FileReader.kt
@@ -0,0 +1,26 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2025 Leszek Koltunski  leszek@koltunski.pl                                          //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// This library is free software; you can redistribute it and/or                                 //
+// modify it under the terms of the GNU Lesser General Public                                    //
+// License as published by the Free Software Foundation; either                                  //
+// version 2.1 of the License, or (at your option) any later version.                            //
+//                                                                                               //
+// This library is distributed in the hope that it will be useful,                               //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
+// Lesser General Public License for more details.                                               //
+//                                                                                               //
+// You should have received a copy of the GNU Lesser General Public                              //
+// License along with this library; if not, write to the Free Software                           //
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.platform
+
+interface FileReader
+{
+    fun read(arr: ByteArray)
+}
\ No newline at end of file
diff --git a/src/main/java/org/distorted/library/platform/FileReaderImplementation.kt b/src/main/java/org/distorted/library/platform/FileReaderImplementation.kt
new file mode 100644
index 0000000..60a4478
--- /dev/null
+++ b/src/main/java/org/distorted/library/platform/FileReaderImplementation.kt
@@ -0,0 +1,33 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2025 Leszek Koltunski  leszek@koltunski.pl                                          //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// This library is free software; you can redistribute it and/or                                 //
+// modify it under the terms of the GNU Lesser General Public                                    //
+// License as published by the Free Software Foundation; either                                  //
+// version 2.1 of the License, or (at your option) any later version.                            //
+//                                                                                               //
+// This library is distributed in the hope that it will be useful,                               //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
+// Lesser General Public License for more details.                                               //
+//                                                                                               //
+// You should have received a copy of the GNU Lesser General Public                              //
+// License along with this library; if not, write to the Free Software                           //
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.platform
+
+import java.io.DataInputStream
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class FileReaderImplementation(val input: DataInputStream) : FileReader
+{
+    override fun read(arr: ByteArray)
+    {
+        input.read(arr)
+    }
+}
diff --git a/src/main/java/org/distorted/library/platform/FileWriter.kt b/src/main/java/org/distorted/library/platform/FileWriter.kt
new file mode 100644
index 0000000..679eb15
--- /dev/null
+++ b/src/main/java/org/distorted/library/platform/FileWriter.kt
@@ -0,0 +1,28 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2025 Leszek Koltunski  leszek@koltunski.pl                                          //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// This library is free software; you can redistribute it and/or                                 //
+// modify it under the terms of the GNU Lesser General Public                                    //
+// License as published by the Free Software Foundation; either                                  //
+// version 2.1 of the License, or (at your option) any later version.                            //
+//                                                                                               //
+// This library is distributed in the hope that it will be useful,                               //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
+// Lesser General Public License for more details.                                               //
+//                                                                                               //
+// You should have received a copy of the GNU Lesser General Public                              //
+// License along with this library; if not, write to the Free Software                           //
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.platform
+
+interface FileWriter
+{
+    fun writeInt(a: Int)
+    fun writeFloat(a: Float)
+    fun write(a: ByteArray)
+}
\ No newline at end of file
diff --git a/src/main/java/org/distorted/library/platform/FileWriterImplementation.kt b/src/main/java/org/distorted/library/platform/FileWriterImplementation.kt
new file mode 100644
index 0000000..3f62041
--- /dev/null
+++ b/src/main/java/org/distorted/library/platform/FileWriterImplementation.kt
@@ -0,0 +1,43 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2025 Leszek Koltunski  leszek@koltunski.pl                                          //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// This library is free software; you can redistribute it and/or                                 //
+// modify it under the terms of the GNU Lesser General Public                                    //
+// License as published by the Free Software Foundation; either                                  //
+// version 2.1 of the License, or (at your option) any later version.                            //
+//                                                                                               //
+// This library is distributed in the hope that it will be useful,                               //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                             //
+// Lesser General Public License for more details.                                               //
+//                                                                                               //
+// You should have received a copy of the GNU Lesser General Public                              //
+// License along with this library; if not, write to the Free Software                           //
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.platform
+
+import java.io.DataOutputStream
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class FileWriterImplementation(val output: DataOutputStream) : FileWriter
+{
+    override fun writeInt(a : Int)
+    {
+        output.writeInt(a)
+    }
+
+    override fun writeFloat(a : Float)
+    {
+        output.writeFloat(a)
+    }
+
+    override fun write(a : ByteArray)
+    {
+        output.write(a)
+    }
+}
