aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormakamys <makamys@outlook.com>2022-06-07 19:10:06 +0200
committermakamys <makamys@outlook.com>2022-06-07 19:10:06 +0200
commita5148760dce388602243bbfc43793056ae36d5cd (patch)
treeb099776cdc78ff8fe22dd1e6eaad8ce7e08b3d41 /src
parent8269e36a650e844668dfbafbd1478f5ee8dbde33 (diff)
downloadNeodymium-a5148760dce388602243bbfc43793056ae36d5cd.tar.gz
Neodymium-a5148760dce388602243bbfc43793056ae36d5cd.tar.bz2
Neodymium-a5148760dce388602243bbfc43793056ae36d5cd.zip
Improve Util#intBufferToArray, add Util#floatBufferToArray
Diffstat (limited to 'src')
-rw-r--r--src/main/java/makamys/lodmod/util/Util.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/makamys/lodmod/util/Util.java b/src/main/java/makamys/lodmod/util/Util.java
index 851e6f5..6ca5f86 100644
--- a/src/main/java/makamys/lodmod/util/Util.java
+++ b/src/main/java/makamys/lodmod/util/Util.java
@@ -5,6 +5,7 @@ import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.file.FileSystems;
import java.nio.file.Files;
@@ -62,9 +63,20 @@ public class Util {
}
public static int[] intBufferToArray(IntBuffer buffer) {
- int[] dst = new int[buffer.remaining()];
+ int[] dst = new int[buffer.limit()];
+ int pos = buffer.position();
+ buffer.position(0);
+ buffer.get(dst);
+ buffer.position(pos);
+ return dst;
+ }
+
+ public static float[] floatBufferToArray(FloatBuffer buffer) {
+ float[] dst = new float[buffer.limit()];
+ int pos = buffer.position();
+ buffer.position(0);
buffer.get(dst);
- buffer.flip();
+ buffer.position(pos);
return dst;
}