use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getEdgeFromKey.
protected Edge getEdgeFromKey(final Key key, final Map<String, String> options) throws AccumuloElementConversionException {
final byte[][] result = new byte[3][];
final boolean directed = getSourceAndDestinationFromRowKey(key.getRowData().getBackingArray(), result, options);
String group;
try {
group = new String(key.getColumnFamilyData().getBackingArray(), CommonConstants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new AccumuloElementConversionException(e.getMessage(), e);
}
try {
final Edge edge = new Edge(group, getVertexSerialiser().deserialise(result[0]), getVertexSerialiser().deserialise(result[1]), directed);
addPropertiesToElement(edge, key);
return edge;
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException("Failed to re-create Edge from key", e);
}
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class AbstractCoreKeyAccumuloElementConverter method getPropertiesAsBytesFromColumnQualifier.
@Override
public byte[] getPropertiesAsBytesFromColumnQualifier(final String group, final byte[] bytes, final int numProps) throws AccumuloElementConversionException {
if (numProps == 0 || bytes == null || bytes.length == 0) {
return AccumuloStoreConstants.EMPTY_BYTES;
}
final SchemaElementDefinition elementDefinition = schema.getElement(group);
if (null == elementDefinition) {
throw new AccumuloElementConversionException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?");
}
if (numProps == elementDefinition.getProperties().size()) {
return bytes;
}
int lastDelimiter = 0;
final int arrayLength = bytes.length;
long currentPropLength;
int propIndex = 0;
while (propIndex < numProps && lastDelimiter < arrayLength) {
final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[lastDelimiter]);
final byte[] length = new byte[numBytesForLength];
System.arraycopy(bytes, lastDelimiter, length, 0, numBytesForLength);
try {
currentPropLength = CompactRawSerialisationUtils.readLong(length);
} catch (final SerialisationException e) {
throw new AccumuloElementConversionException("Exception reading length of property", e);
}
lastDelimiter += numBytesForLength;
if (currentPropLength > 0) {
lastDelimiter += currentPropLength;
}
propIndex++;
}
final byte[] propertyBytes = new byte[lastDelimiter];
System.arraycopy(bytes, 0, propertyBytes, 0, lastDelimiter);
return propertyBytes;
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class AvroSerialiser method serialise.
public byte[] serialise(final Object object) throws SerialisationException {
Schema schema = ReflectData.get().getSchema(object.getClass());
DatumWriter<Object> datumWriter = new ReflectDatumWriter<>(schema);
DataFileWriter<Object> dataFileWriter = new DataFileWriter<>(datumWriter);
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try {
dataFileWriter.create(schema, byteOut);
dataFileWriter.append(object);
dataFileWriter.flush();
} catch (final IOException e) {
throw new SerialisationException("Unable to serialise given object of class: " + object.getClass().getName(), e);
} finally {
close(dataFileWriter);
}
return byteOut.toByteArray();
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class AvroSerialiser method deserialise.
public <T> T deserialise(final byte[] bytes, final Class<T> clazz) throws SerialisationException {
DatumReader<T> datumReader = new ReflectDatumReader<>();
DataFileStream<T> in = null;
T ret = null;
try {
in = new DataFileStream<>(new ByteArrayInputStream(bytes), datumReader);
ret = in.next();
} catch (final IOException e) {
throw new SerialisationException("Unable to deserialise object, failed to read input bytes", e);
} finally {
close(in);
}
return ret;
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class IntegerFreqMapSerialiser method serialise.
@Override
public byte[] serialise(final IntegerFreqMap map) throws SerialisationException {
Set<Entry<String, Integer>> entrySet = map.entrySet();
StringBuilder builder = new StringBuilder();
int last = entrySet.size() - 1;
int start = 0;
for (final Entry<String, Integer> entry : entrySet) {
Integer value = entry.getValue();
if (value == null) {
continue;
}
builder.append(entry.getKey() + SEPERATOR + value);
++start;
if (start > last) {
break;
}
builder.append(SEPERATOR);
}
try {
return builder.toString().getBytes(CommonConstants.ISO_8859_1_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new SerialisationException(e.getMessage(), e);
}
}
Aggregations