use of org.vertexium.accumulo.StreamingPropertyValueTableDataRef in project vertexium by visallo.
the class DataInDataTableStreamingPropertyValueStorageStrategy method saveStreamingPropertyValue.
@Override
public StreamingPropertyValueRef saveStreamingPropertyValue(ElementMutationBuilder elementMutationBuilder, String rowKey, Property property, StreamingPropertyValue streamingPropertyValue) {
try {
String dataTableRowKey = new DataTableRowKey(rowKey, property).getRowKey();
InputStream in = streamingPropertyValue.getInputStream();
byte[] buffer = new byte[dataInDataTablePartSize];
long offset = 0;
while (true) {
int read = in.read(buffer);
if (read <= 0) {
break;
}
Mutation dataMutation = new Mutation(dataTableRowKey);
Text columnQualifier = new Text(String.format("%08x", offset));
dataMutation.put(DATA_COLUMN_FAMILY, columnQualifier, property.getTimestamp(), new Value(buffer, 0, read));
elementMutationBuilder.saveDataMutation(dataMutation);
offset += read;
}
Mutation dataMutation = new Mutation(dataTableRowKey);
dataMutation.put(METADATA_COLUMN_FAMILY, METADATA_LENGTH_COLUMN_QUALIFIER, property.getTimestamp(), new Value(Longs.toByteArray(offset)));
elementMutationBuilder.saveDataMutation(dataMutation);
return new StreamingPropertyValueTableDataRef(dataTableRowKey, streamingPropertyValue, offset);
} catch (Exception ex) {
throw new VertexiumException("Could not store streaming property value", ex);
}
}
Aggregations