use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class RoaringBitmapSerialiser method serialise.
@Override
public byte[] serialise(final Object object) throws SerialisationException {
RoaringBitmap value = (RoaringBitmap) object;
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
try {
value.serialize(out);
} catch (final IOException e) {
throw new SerialisationException(e.getMessage(), e);
}
return byteOut.toByteArray();
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class RoaringBitmapSerialiser method deserialise.
@Override
public Object deserialise(final byte[] bytes) throws SerialisationException {
RoaringBitmap value = new RoaringBitmap();
byte[] convertedBytes = RoaringBitmapUtils.upConvertSerialisedForm(bytes);
ByteArrayInputStream byteIn = new ByteArrayInputStream(convertedBytes);
DataInputStream in = new DataInputStream(byteIn);
try {
value.deserialize(in);
} catch (final IOException e) {
throw new SerialisationException(e.getMessage(), e);
}
return value;
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class IntegerFreqMapSerialiser method deserialise.
@Override
public IntegerFreqMap deserialise(final byte[] bytes) throws SerialisationException {
IntegerFreqMap freqMap = new IntegerFreqMap();
if (bytes.length == 0) {
return freqMap;
}
String stringMap;
try {
stringMap = new String(bytes, CommonConstants.ISO_8859_1_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new SerialisationException(e.getMessage(), e);
}
if (stringMap.isEmpty()) {
//No values so return the empty map
return freqMap;
}
String[] keyValues = stringMap.split(SEPERATOR_REGEX);
if (keyValues.length % 2 != 0) {
throw new SerialisationException("Uneven number of entries found for serialised frequency map, unable to deserialise.");
}
for (int i = 0; i < keyValues.length - 1; i += 2) {
freqMap.put(keyValues[i], Integer.parseInt(keyValues[i + 1]));
}
return freqMap;
}
use of uk.gov.gchq.gaffer.exception.SerialisationException in project Gaffer by gchq.
the class TypeSubTypeValueSerialiser method deserialise.
@Override
public TypeSubTypeValue deserialise(final byte[] bytes) throws SerialisationException {
int lastDelimiter = 0;
TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue();
for (int i = 0; i < bytes.length; i++) {
if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
if (i > 0) {
try {
typeSubTypeValue.setType(new String(ByteArrayEscapeUtils.unEscape(Arrays.copyOfRange(bytes, lastDelimiter, i)), CommonConstants.UTF_8));
} catch (UnsupportedEncodingException e) {
throw new SerialisationException("Failed to deserialise the Type from TypeSubTypeValue Object", e);
}
}
lastDelimiter = i + 1;
break;
}
}
for (int i = lastDelimiter; i < bytes.length; i++) {
if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
if (i > lastDelimiter) {
try {
typeSubTypeValue.setSubType(new String(ByteArrayEscapeUtils.unEscape(Arrays.copyOfRange(bytes, lastDelimiter, i)), CommonConstants.UTF_8));
} catch (UnsupportedEncodingException e) {
throw new SerialisationException("Failed to deserialise the SubType from TypeSubTypeValue Object", e);
}
}
lastDelimiter = i + 1;
break;
}
}
if (bytes.length > lastDelimiter) {
try {
typeSubTypeValue.setValue(new String(ByteArrayEscapeUtils.unEscape(Arrays.copyOfRange(bytes, lastDelimiter, bytes.length)), CommonConstants.UTF_8));
} catch (UnsupportedEncodingException e) {
throw new SerialisationException("Failed to deserialise the Value from TypeSubTypeValue Object", e);
}
}
return typeSubTypeValue;
}
Aggregations