java - 如何将字节数组数据放入DoubleBuffer

标签 java arrays

我想从字节数组中提取一组坐标到 DoubleBuffer 中。

下面是如何将一组坐标从主字节数组提取到另一个字节数组的示例。

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 中吗?速度和效率是关键,因此任何捷径或优化都是最受欢迎的!

最佳答案

如果你知道字节缓冲区中的 8 个字节确实是 Doubles,那么只需

DoubleBuffer dbls = new ByteBuffer(geomCoords).asDoubleBuffer();

现在每个点都可以用 dbls.get(); 来提取

关于java - 如何将字节数组数据放入DoubleBuffer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17391944/

相关文章:

java - 如何在 Java 类中实现运算符

java - 我收到一个StackOverflowError,它递归调用相同的错误

VB.NET:将 CSV 文件读入二维数组

javascript - 处理完成后如何使用异步nodejs中的回调清除数组?

java - 获取 HashMap 中的前 10 个值

java - JMS 和 JPA - 事务服务最佳实践

java - html 代码表不起作用

使用 C 结构体定制订单

php - 如何在php数组中找到对象并将其删除?

java - 查找二维数组的可能组合