Search in sources :

Example 36 with SerialisationException

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();
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 37 with SerialisationException

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;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) RoaringBitmap(org.roaringbitmap.RoaringBitmap)

Example 38 with SerialisationException

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;
}
Also used : IntegerFreqMap(uk.gov.gchq.gaffer.types.IntegerFreqMap) SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 39 with SerialisationException

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;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)39 IOException (java.io.IOException)12 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 RangeFactoryException (uk.gov.gchq.gaffer.accumulostore.key.exception.RangeFactoryException)4 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Properties (uk.gov.gchq.gaffer.data.element.Properties)3 Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)3 StoreException (uk.gov.gchq.gaffer.store.StoreException)3 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)3 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 Entry (java.util.Map.Entry)2 Key (org.apache.accumulo.core.data.Key)2 Test (org.junit.Test)2 RoaringBitmap (org.roaringbitmap.RoaringBitmap)2 Entity (uk.gov.gchq.gaffer.data.element.Entity)2