use of de.fhg.igd.mongomvcc.helper.FloatArrayInputStream in project mongomvcc by igd-geo.
the class DefaultConvertStrategy method convert.
@Override
public long convert(Object data) {
GridFSInputFile file;
if (data instanceof byte[]) {
file = _gridFS.createFile((byte[]) data);
file.put(BINARY_TYPE, BYTEARRAY);
} else if (data instanceof float[]) {
file = _gridFS.createFile(new FloatArrayInputStream((float[]) data));
file.put(BINARY_TYPE, FLOATARRAY);
} else if (data instanceof InputStream) {
file = _gridFS.createFile((InputStream) data);
file.put(BINARY_TYPE, INPUTSTREAM);
} else if (data instanceof ByteBuffer) {
ByteBuffer bb = (ByteBuffer) data;
byte[] buf;
if (bb.hasArray()) {
buf = bb.array();
} else {
bb.rewind();
buf = new byte[bb.remaining()];
bb.get(buf);
}
file = _gridFS.createFile(buf);
file.put(BINARY_TYPE, BYTEBUFFER);
} else if (data instanceof FloatBuffer) {
FloatBuffer bb = (FloatBuffer) data;
float[] buf;
if (bb.hasArray()) {
buf = bb.array();
} else {
bb.rewind();
buf = new float[bb.remaining()];
bb.get(buf);
}
file = _gridFS.createFile(new FloatArrayInputStream(buf));
file.put(BINARY_TYPE, FLOATBUFFER);
} else {
return 0;
}
long oid = _counter.getNextId();
file.put(MongoDBVLargeCollection.OID, oid);
_convertedFiles.add(file);
return oid;
}
Aggregations