Codota Logo
ToBytesSerialiser
Code IndexAdd Codota 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)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
ScheduledThreadPoolExecutor s =
  • Codota Iconnew ScheduledThreadPoolExecutor(corePoolSize)
  • Codota IconThreadFactory threadFactory;new ScheduledThreadPoolExecutor(corePoolSize, threadFactory)
  • Codota IconString str;new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat(str).build())
  • Smart code suggestions by Codota
}
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

  • Parsing JSON documents to java classes using gson
  • startActivity (Activity)
  • onCreateOptionsMenu (Activity)
  • findViewById (Activity)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • BufferedReader (java.io)
    Reads text from a character-input stream, buffering characters so as to provide for the efficient re
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Collectors (java.util.stream)
  • JFileChooser (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now