如何将字节数组数据导入DoubleBuffer

时间:2013-06-30 15:27:52

标签: java bytearray

我想从字节数组中提取一组坐标到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吗?速度和效率是关键,因此欢迎任何捷径或优化!

1 个答案:

答案 0 :(得分:0)

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

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

现在可以使用dbls.get();

提取每个点