congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ToBytesSerialiser.deserialise
Code IndexAdd Tabnine to your IDE (free)

How to use
deserialise
method
in
uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser

Best Java code snippets using uk.gov.gchq.gaffer.serialisation.ToBytesSerialiser.deserialise (Showing top 18 results out of 315)

origin: gchq/Gaffer

private static <T> T getValue(final ToBytesSerialiser<T> serialiser, final byte[] valueBytes) throws SerialisationException {
  if (0 == valueBytes.length) {
    return serialiser.deserialiseEmpty();
  }
  return serialiser.deserialise(valueBytes);
}
origin: gchq/Gaffer

/**
 * @param allBytes The bytes to be decoded into characters
 * @param offset   The index of the first byte to decode
 * @param length   The number of bytes to decode
 * @return T the deserialised object
 * @throws SerialisationException issues during deserialisation
 */
default T deserialise(final byte[] allBytes, final int offset, final int length) throws SerialisationException {
  final byte[] selection = new byte[length];
  try {
    System.arraycopy(allBytes, offset, selection, 0, length);
  } catch (final NullPointerException e) {
    throw new SerialisationException(String.format("Deserialising with giving range caused ArrayIndexOutOfBoundsException. byte[].size:%d startPos:%d length:%d", allBytes.length, 0, length), e);
  }
  return deserialise(selection);
}
origin: gchq/Gaffer

public static <T> ObjectCarriage<T> deserialiseNextObject(final ToBytesSerialiser<T> serialiser, final int currentCarriage, final byte[] bytes) throws SerialisationException {
  int rtn = currentCarriage;
  int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[rtn]);
  int currentPropLength = getCurrentPropLength(bytes, rtn, numBytesForLength);
  int from = rtn += numBytesForLength;
  int to = rtn += currentPropLength;
  T object = serialiser.deserialise(Arrays.copyOfRange(bytes, from, to));
  return new ObjectCarriage<T>(object, rtn);
}
origin: uk.gov.gchq.gaffer/accumulo-store

private Object getDeserialisedObject(final ToBytesSerialiser serialiser, final byte[] bytes, final int from, final int length) throws SerialisationException {
  //Don't initialise with  #deserialiseEmpty() as this might initialise an complex empty structure to be immediately overwritten e.g. TreeSet<String>
  Object deserialisedObject;
  if (length > 0) {
    deserialisedObject = serialiser.deserialise(bytes, from, length);
  } else {
    deserialisedObject = serialiser.deserialiseEmpty();
  }
  return deserialisedObject;
}
origin: gchq/Gaffer

@Override
public Object deserialise(final byte[] bytes) throws SerialisationException {
  try {
    byte keyByte = bytes[0];
    ToBytesSerialiser serialiser = nullCheck(supportedSerialisers.getSerialiserFromKey(keyByte));
    return serialiser.deserialise(bytes, 1, bytes.length - 1);
  } catch (final SerialisationException e) {
    //re-throw SerialisationException
    throw e;
  } catch (final Exception e) {
    //wraps other exceptions.
    throw new SerialisationException(e.getMessage(), e);
  }
}
origin: uk.gov.gchq.gaffer/serialisation

private static <T> T getValue(final ToBytesSerialiser<T> serialiser, final byte[] valueBytes) throws SerialisationException {
  if (0 == valueBytes.length) {
    return serialiser.deserialiseEmpty();
  }
  return serialiser.deserialise(valueBytes);
}
origin: gchq/Gaffer

private void test(final long value) throws SerialisationException {
  final byte[] b = serialiser.serialise(value);
  final Object o = ((ToBytesSerialiser) serialiser).deserialise(b, 0, b.length);
  assertEquals(Long.class, o.getClass());
  assertEquals(value, o);
  final ByteArrayOutputStream stream = new ByteArrayOutputStream();
  CompactRawSerialisationUtils.write(value, new DataOutputStream(stream));
  final long result = CompactRawSerialisationUtils.read(new DataInputStream(new ByteArrayInputStream(stream.toByteArray())));
  assertEquals(result, value);
}
origin: uk.gov.gchq.gaffer/accumulo-store

@Override
public Properties getPropertiesFromColumnVisibility(final String group, final byte[] columnVisibility) {
  final Properties properties = new Properties();
  final SchemaElementDefinition elementDefinition = getSchemaElementDefinition(group);
  if (null != schema.getVisibilityProperty()) {
    final TypeDefinition propertyDef = elementDefinition.getPropertyTypeDef(schema.getVisibilityProperty());
    if (null != propertyDef) {
      final ToBytesSerialiser serialiser = (ToBytesSerialiser) propertyDef.getSerialiser();
      try {
        if (null == columnVisibility || columnVisibility.length == 0) {
          final Object value = serialiser.deserialiseEmpty();
          if (null != value) {
            properties.put(schema.getVisibilityProperty(), value);
          }
        } else {
          properties.put(schema.getVisibilityProperty(), serialiser.deserialise(columnVisibility));
        }
      } catch (final SerialisationException e) {
        throw new AccumuloElementConversionException(e.getMessage(), e);
      }
    }
  }
  return properties;
}
origin: uk.gov.gchq.gaffer/serialisation

/**
 * @param allBytes The bytes to be decoded into characters
 * @param offset   The index of the first byte to decode
 * @param length   The number of bytes to decode
 * @return T the deserialised object
 * @throws SerialisationException issues during deserialisation
 */
default T deserialise(final byte[] allBytes, final int offset, final int length) throws SerialisationException {
  final byte[] selection = new byte[length];
  try {
    System.arraycopy(allBytes, offset, selection, 0, length);
  } catch (final NullPointerException e) {
    throw new SerialisationException(String.format("Deserialising with giving range caused ArrayIndexOutOfBoundsException. byte[].size:%d startPos:%d length:%d", allBytes.length, 0, length), e);
  }
  return deserialise(selection);
}
origin: uk.gov.gchq.gaffer/serialisation

public static <T> ObjectCarriage<T> deserialiseNextObject(final ToBytesSerialiser<T> serialiser, final int currentCarriage, final byte[] bytes) throws SerialisationException {
  int rtn = currentCarriage;
  int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[rtn]);
  int currentPropLength = getCurrentPropLength(bytes, rtn, numBytesForLength);
  int from = rtn += numBytesForLength;
  int to = rtn += currentPropLength;
  T object = serialiser.deserialise(Arrays.copyOfRange(bytes, from, to));
  return new ObjectCarriage<T>(object, rtn);
}
origin: uk.gov.gchq.gaffer/spark-library

  @Override
  public T read(final Kryo kryo, final Input input, final Class<T> type) {
    final int serialisedLength = input.readInt();
    final byte[] serialised = input.readBytes(serialisedLength);
    try {
      return serialiser.deserialise(serialised);
    } catch (final SerialisationException e) {
      throw new GafferRuntimeException("Exception deserialising "
          + type.getSimpleName()
          + " to a byte array", e);
    }
  }
}
origin: uk.gov.gchq.gaffer/serialisation

@Override
public Object deserialise(final byte[] bytes) throws SerialisationException {
  try {
    byte keyByte = bytes[0];
    ToBytesSerialiser serialiser = nullCheck(supportedSerialisers.getSerialiserFromKey(keyByte));
    return serialiser.deserialise(bytes, 1, bytes.length - 1);
  } catch (final SerialisationException e) {
    //re-throw SerialisationException
    throw e;
  } catch (final Exception e) {
    //wraps other exceptions.
    throw new SerialisationException(e.getMessage(), e);
  }
}
origin: uk.gov.gchq.gaffer/accumulo-store

@SuppressWarnings("unchecked")
@Override
protected EntityId getEntityId(final byte[] row) {
  try {
    return new EntitySeed(((ToBytesSerialiser) schema.getVertexSerialiser())
        .deserialise(ByteArrayEscapeUtils.unEscape(Arrays.copyOfRange(row, 0,
            row.length - 2))));
  } catch (final SerialisationException e) {
    throw new AccumuloElementConversionException("Failed to create EntityId from Accumulo row key", e);
  }
}
origin: uk.gov.gchq.gaffer/accumulo-store

protected EdgeId getEdgeId(final byte[] row, final boolean includeMatchedVertex) {
  final byte[][] result = new byte[2][];
  final EdgeDirection direction = getSourceAndDestinationFromRowKey(row, result);
  final EdgeId.MatchedVertex matchedVertex;
  if (!includeMatchedVertex) {
    matchedVertex = null;
  } else if (EdgeDirection.DIRECTED_REVERSED == direction) {
    matchedVertex = EdgeId.MatchedVertex.DESTINATION;
  } else {
    matchedVertex = EdgeId.MatchedVertex.SOURCE;
  }
  try {
    return new EdgeSeed(((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[0]),
        ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[1]), direction.isDirected(), matchedVertex);
  } catch (final SerialisationException e) {
    throw new AccumuloElementConversionException("Failed to create EdgeId from Accumulo row key", e);
  }
}
origin: uk.gov.gchq.gaffer/accumulo-store

@Override
protected EntityId getEntityId(final byte[] row) {
  try {
    return new EntitySeed(((ToBytesSerialiser) schema.getVertexSerialiser())
        .deserialise(ByteArrayEscapeUtils.unEscape(row)));
  } catch (final SerialisationException e) {
    throw new AccumuloElementConversionException("Failed to create EntityId from Accumulo row key", e);
  }
}
origin: uk.gov.gchq.gaffer/accumulo-store

@Override
protected Entity getEntityFromKey(final Key key, final byte[] row) {
  try {
    final Entity entity = new Entity(getGroupFromKey(key), ((ToBytesSerialiser) schema.getVertexSerialiser())
        .deserialise(ByteArrayEscapeUtils.unEscape(row)));
    addPropertiesToElement(entity, key);
    return entity;
  } catch (final SerialisationException e) {
    throw new AccumuloElementConversionException("Failed to re-create Entity from key", e);
  }
}
origin: uk.gov.gchq.gaffer/accumulo-store

@Override
protected Entity getEntityFromKey(final Key key, final byte[] row) {
  try {
    final Entity entity = new Entity(getGroupFromKey(key), ((ToBytesSerialiser) schema.getVertexSerialiser())
        .deserialise(ByteArrayEscapeUtils.unEscape(row, 0, row.length - 2)));
    addPropertiesToElement(entity, key);
    return entity;
  } catch (final SerialisationException e) {
    throw new AccumuloElementConversionException("Failed to re-create Entity from key", e);
  }
}
origin: uk.gov.gchq.gaffer/accumulo-store

@SuppressWarnings("WeakerAccess")
protected Edge getEdgeFromKey(final Key key, final byte[] row, final boolean includeMatchedVertex) {
  final byte[][] result = new byte[2][];
  final EdgeDirection direction = getSourceAndDestinationFromRowKey(row, result);
  final EdgeId.MatchedVertex matchedVertex;
  if (!includeMatchedVertex) {
    matchedVertex = null;
  } else if (EdgeDirection.DIRECTED_REVERSED == direction) {
    matchedVertex = EdgeId.MatchedVertex.DESTINATION;
  } else {
    matchedVertex = EdgeId.MatchedVertex.SOURCE;
  }
  final String group = getGroupFromColumnFamily(key.getColumnFamilyData().getBackingArray());
  try {
    final Edge edge = new Edge(group, ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[0]),
        ((ToBytesSerialiser) schema.getVertexSerialiser()).deserialise(result[1]), direction.isDirected(), matchedVertex, null);
    addPropertiesToElement(edge, key);
    return edge;
  } catch (final SerialisationException e) {
    throw new AccumuloElementConversionException("Failed to re-create Edge from key", e);
  }
}
uk.gov.gchq.gaffer.serialisationToBytesSerialiserdeserialise

Popular methods of ToBytesSerialiser

  • serialise
  • deserialiseEmpty
    Handle an empty byte array and reconstruct an appropriate representation in T form.
  • serialiseNull
    Handle an incoming null value and generate an appropriate byte array representation.
  • canHandle
  • isConsistent
  • preservesObjectOrdering
    Indicates whether the serialisation process preserves the ordering of the T, i.e. if x and y are obj

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setContentView (Activity)
  • scheduleAtFixedRate (Timer)
  • getExternalFilesDir (Context)
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Reference (javax.naming)
  • JFrame (javax.swing)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now