congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
ToBytesSerialiser
Code IndexAdd Tabnine to your IDE (free)

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

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

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 ByteArrayOutputStream appendLengthValueFromObjectToByteStream(final ByteArrayOutputStream byteOut, final ToBytesSerialiser serialiser, final Object object) throws SerialisationException {
  return appendLengthValueFromBytesToByteStream(byteOut, serialiser.serialise(object));
}
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

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;
}
origin: gchq/Gaffer

private void validatePutParams(final ToBytesSerialiser serialiser, final Class supportedClass) throws GafferCheckedException {
  if (null == supportedClass) {
    throw new GafferCheckedException(String.format("Can not add null supportedClass to MultiSerialiserStorage"));
  }
  if (null == serialiser) {
    throw new GafferCheckedException(String.format("Can not add null serialiser to MultiSerialiserStorage"));
  }
  if (!serialiser.canHandle(supportedClass)) {
    throw new GafferCheckedException(String.format("%s does not handle %s", serialiser.getClass(), supportedClass));
  }
}
origin: gchq/Gaffer

private boolean continuesToPreserveOrdering(final ToBytesSerialiser toBytesSerialiser) {
  return preservesObjectOrdering && toBytesSerialiser.preservesObjectOrdering();
}
origin: gchq/Gaffer

private boolean continuesToBeConsistant(final ToBytesSerialiser toBytesSerialiser) {
  return consistent && toBytesSerialiser.isConsistent();
}
origin: uk.gov.gchq.gaffer/serialisation

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;
}
origin: uk.gov.gchq.gaffer/serialisation

private void validatePutParams(final ToBytesSerialiser serialiser, final Class supportedClass) throws GafferCheckedException {
  if (null == supportedClass) {
    throw new GafferCheckedException(String.format("Can not add null supportedClass to MultiSerialiserStorage"));
  }
  if (null == serialiser) {
    throw new GafferCheckedException(String.format("Can not add null serialiser to MultiSerialiserStorage"));
  }
  if (!serialiser.canHandle(supportedClass)) {
    throw new GafferCheckedException(String.format("%s does not handle %s", serialiser.getClass(), supportedClass));
  }
}
origin: uk.gov.gchq.gaffer/serialisation

private boolean continuesToPreserveOrdering(final ToBytesSerialiser toBytesSerialiser) {
  return preservesObjectOrdering && toBytesSerialiser.preservesObjectOrdering();
}
origin: uk.gov.gchq.gaffer/serialisation

private boolean continuesToBeConsistant(final ToBytesSerialiser toBytesSerialiser) {
  return consistent && toBytesSerialiser.isConsistent();
}
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/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

@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);
  }
}
origin: uk.gov.gchq.gaffer/accumulo-store

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);
  }
}
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/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: uk.gov.gchq.gaffer/serialisation

public static ByteArrayOutputStream appendLengthValueFromObjectToByteStream(final ByteArrayOutputStream byteOut, final ToBytesSerialiser serialiser, final Object object) throws SerialisationException {
  return appendLengthValueFromBytesToByteStream(byteOut, serialiser.serialise(object));
}
origin: uk.gov.gchq.gaffer/accumulo-store

@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;
}
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);
}
uk.gov.gchq.gaffer.serialisationToBytesSerialiser

Javadoc

A class that implements this interface is responsible for serialising an object of class T to a byte array, and for deserialising it back again. It must also be able to deal with serialising null values.

Most used methods

  • deserialise
  • 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

  • Reactive rest calls using spring rest template
  • onRequestPermissionsResult (Fragment)
  • runOnUiThread (Activity)
  • getSystemService (Context)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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