public static <T> byte[] getValueBytes(final ToBytesSerialiser<T> serialiser, final T value) throws SerialisationException { final byte[] valueBytes; if (null == serialiser) { valueBytes = EMPTY_BYTES; } else if (null == value) { valueBytes = serialiser.serialiseNull(); } else { valueBytes = serialiser.serialise(value); } return valueBytes; }
public static ByteArrayOutputStream appendLengthValueFromObjectToByteStream(final ByteArrayOutputStream byteOut, final ToBytesSerialiser serialiser, final Object object) throws SerialisationException { return appendLengthValueFromBytesToByteStream(byteOut, serialiser.serialise(object)); }
@Override public byte[] serialise(final Object object) throws SerialisationException { try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { byte key = supportedSerialisers.getKeyFromValue(object); byte[] bytes = nullCheck(supportedSerialisers.getSerialiserFromKey(key)).serialise(object); stream.write(key); stream.write(bytes); return stream.toByteArray(); } catch (final SerialisationException e) { //re-throw SerialisationException throw e; } catch (final Exception e) { //wraps other exceptions. throw new SerialisationException(e.getMessage(), e); } }
public static <T> byte[] getValueBytes(final ToBytesSerialiser<T> serialiser, final T value) throws SerialisationException { final byte[] valueBytes; if (null == serialiser) { valueBytes = EMPTY_BYTES; } else if (null == value) { valueBytes = serialiser.serialiseNull(); } else { valueBytes = serialiser.serialise(value); } return valueBytes; }
public static ByteArrayOutputStream appendLengthValueFromObjectToByteStream(final ByteArrayOutputStream byteOut, final ToBytesSerialiser serialiser, final Object object) throws SerialisationException { return appendLengthValueFromBytesToByteStream(byteOut, serialiser.serialise(object)); }
protected void serialiseSizeAndPropertyValue(final String propertyName, final SchemaElementDefinition elementDefinition, final Properties properties, final ByteArrayOutputStream stream) { try { final TypeDefinition typeDefinition = elementDefinition.getPropertyTypeDef(propertyName); final ToBytesSerialiser serialiser = (null == typeDefinition) ? null : (ToBytesSerialiser) typeDefinition.getSerialiser(); byte[] bytes; if (null == serialiser) { bytes = AccumuloStoreConstants.EMPTY_BYTES; } else { Object value = properties.get(propertyName); //serialiseNull could be different to AccumuloStoreConstants.EMPTY_BYTES bytes = (null == value) ? serialiser.serialiseNull() : serialiser.serialise(value); } writeBytes(bytes, stream); } catch (final IOException e) { throw new AccumuloElementConversionException("Failed to write serialised property to ByteArrayOutputStream" + propertyName, e); } }
@Override public void write(final Kryo kryo, final Output output, final T obj) { final byte[] serialised; try { serialised = serialiser.serialise(obj); } catch (final SerialisationException e) { throw new GafferRuntimeException("Exception serialising " + obj.getClass().getSimpleName() + " to a byte array", e); } output.writeInt(serialised.length); output.writeBytes(serialised); }
@Override public byte[] buildColumnVisibility(final String group, final Properties properties) { byte[] rtn = AccumuloStoreConstants.EMPTY_BYTES; final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group); if (null != schema.getVisibilityProperty()) { final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty()); if (null != propertyDef) { final Object property = properties.get(schema.getVisibilityProperty()); final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser(); if (null != property) { try { rtn = serialiser.serialise(property); } catch (final SerialisationException e) { throw new AccumuloElementConversionException(e.getMessage(), e); } } else { rtn = serialiser.serialiseNull(); } } } return rtn; }
@Override public byte[] serialise(final Object object) throws SerialisationException { try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { byte key = supportedSerialisers.getKeyFromValue(object); byte[] bytes = nullCheck(supportedSerialisers.getSerialiserFromKey(key)).serialise(object); stream.write(key); stream.write(bytes); return stream.toByteArray(); } catch (final SerialisationException e) { //re-throw SerialisationException throw e; } catch (final Exception e) { //wraps other exceptions. throw new SerialisationException(e.getMessage(), e); } }
@Override public byte[] serialiseVertex(final Object vertex) { try { return ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(vertex)); } catch (final SerialisationException e) { throw new AccumuloElementConversionException( "Failed to serialise given identifier object for use in the bloom filter", e); } }
protected byte[] getSerialisedDestination(final Edge edge) { try { return ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(edge.getDestination())); } catch (final SerialisationException e) { throw new AccumuloElementConversionException("Failed to serialise Edge Destination", e); } }
protected byte[] getSerialisedSource(final Edge edge) { try { return ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(edge.getSource())); } catch (final SerialisationException e) { throw new AccumuloElementConversionException("Failed to serialise Edge Source", e); } }
@Override protected byte[] getRowKeyFromEntity(final Entity entity) { try { return ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(entity.getVertex()), ByteArrayEscapeUtils.DELIMITER, ByteEntityPositions.ENTITY); } catch (final SerialisationException e) { throw new AccumuloElementConversionException("Failed to serialise Entity Identifier", e); } }
@Override protected byte[] getRowKeyFromEntity(final Entity entity) { // No Delimiters but need to escape bytes // because later we check how many delimiter characters there are try { return ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(entity.getVertex())); } catch (final SerialisationException e) { throw new AccumuloElementConversionException("Failed to serialise Entity Identifier", e); } }
protected Key getKeyFromEdgeId(final Object source, final Object destination, final boolean directed, final boolean endKey) throws RangeFactoryException { final ToBytesSerialiser vertexSerialiser = (ToBytesSerialiser) schema.getVertexSerialiser(); final byte directionFlag = directed ? ByteEntityPositions.CORRECT_WAY_DIRECTED_EDGE : ByteEntityPositions.UNDIRECTED_EDGE; byte[] sourceValue; try { sourceValue = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(source)); } catch (final SerialisationException e) { throw new RangeFactoryException("Failed to serialise Edge Source", e); } byte[] destinationValue; try { destinationValue = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(destination)); } catch (final SerialisationException e) { throw new RangeFactoryException("Failed to serialise Edge Destination", e); } byte[] key = getKey(endKey, directionFlag, sourceValue, destinationValue); return new Key(key, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, AccumuloStoreConstants.EMPTY_BYTES, Long.MAX_VALUE); }
serialisedVertex = ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(vertex)); } catch (final SerialisationException e) { throw new RangeFactoryException("Failed to serialise identifier", e);
source = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(sourceVal)); } catch (final SerialisationException e) { throw new RangeFactoryException("Failed to serialise Edge Source", e); destination = ByteArrayEscapeUtils.escape(vertexSerialiser.serialise(destVal)); } catch (final SerialisationException e) { throw new RangeFactoryException("Failed to serialise Edge Destination", e);
serialisedVertex = ByteArrayEscapeUtils.escape(((ToBytesSerialiser) schema.getVertexSerialiser()).serialise(vertex)); } catch (final SerialisationException e) { throw new RangeFactoryException("Failed to serialise identifier", e);