如何将字节数组数据导入DoubleBuffer [英] How to get a byte array data into DoubleBuffer
问题描述
我想从字节数组中提取一组坐标到DoubleBuffer。
I would like to extract a set of coordinates from a byte array into a DoubleBuffer.
下面是我如何从main中提取一组坐标的示例字节数组到另一个字节数组。
Below is an example of how I extract a set of coordinates from the main byte array into another byte array.
byte intPoints[] = new byte[4];
byte geomCoords[];
...
is = new ByteArrayInputStream(stmt.column_bytes(0)); //reads the polygon from db
...
is.read(intPoints); //intPoints now holds the number of points in the polygon
//After this is read the actual coordinate list is next
//Set the size of geomCoords to hold all coordinates,
//There are 2 coordinates per point and each coordinate is a double value(8 bytes)
geomCoords = new byte[ByteBuffer.wrap(intPoints).order(endian).getInt() * 2 * 8];
is.read(geomCoords); //geomCoords now holds all the coordinates for the polygon
我的问题是:
如何将geomCoords字节数组转换为DoubleBuffer?
$
或
我可以在不创建geomCoords的情况下将此数据导入DoubleBuffer吗?速度和效率是关键,所以任何捷径或优化都是最受欢迎的!
My questions are:
How can I get geomCoords byte array into a DoubleBuffer?
Or
Can I get this data into a DoubleBuffer without the creation of geomCoords? Speed and efficiency is key, so any shortcut or optimization is most welcome!
推荐答案
如果你知道字节中的8个字节缓冲区确实是双打,然后只需
If you know that the 8 bytes in the bytes buffer are indeed Doubles, then simply
DoubleBuffer dbls = new ByteBuffer(geomCoords).asDoubleBuffer();
现在可以用 dbls.get(); 提取每个点code>
这篇关于如何将字节数组数据导入DoubleBuffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!