ElementSerialisation { public byte[] getPropertiesAsBytesFromColumnQualifier(final String group, final byte[] bytes, final int numProps) throws SerialisationException { if (numProps == 0 || null == bytes || bytes.length == 0) { return HBaseStoreConstants.EMPTY_BYTES; } final SchemaElementDefinition elementDefinition = schema.getElement(group); if (null == elementDefinition) { throw new SerialisationException("No SchemaElementDefinition found for group " + group + ", is this group in your schema or do your table iterators need updating?"); } final int firstDelimiter = CompactRawSerialisationUtils.decodeVIntSize(bytes[0]) + Bytes.toBytes(group).length; if (numProps == elementDefinition.getProperties().size()) { final int length = bytes.length - firstDelimiter; final byte[] propertyBytes = new byte[length]; System.arraycopy(bytes, firstDelimiter, propertyBytes, 0, length); return propertyBytes; } int lastDelimiter = firstDelimiter; final int arrayLength = bytes.length; long currentPropLength; int propIndex = 0; while (propIndex < numProps && lastDelimiter < arrayLength) { final int numBytesForLength = CompactRawSerialisationUtils.decodeVIntSize(bytes[lastDelimiter]); final byte[] length = new byte[numBytesForLength]; System.arraycopy(bytes, lastDelimiter, length, 0, numBytesForLength); try { currentPropLength = CompactRawSerialisationUtils.readLong(length); } catch (final SerialisationException e) { throw new SerialisationException("Exception reading length of property"); } lastDelimiter += numBytesForLength; if (currentPropLength > 0) { lastDelimiter += currentPropLength; } propIndex++; } final int length = lastDelimiter - firstDelimiter; final byte[] propertyBytes = new byte[length]; System.arraycopy(bytes, firstDelimiter, propertyBytes, 0, length); return propertyBytes; } ElementSerialisation(final Schema schema); byte[] getValue(final Element element); byte[] getValue(final String group, final Properties properties); Properties getPropertiesFromValue(final String group, final byte[] value); Element getPartialElement(final String group, final byte[] rowId, final boolean includeMatchedVertex); Element getElement(final Cell cell, final boolean includeMatchedVertex); Properties getProperties(final String group, final Cell cell); byte[] getColumnVisibility(final Element element); byte[] getColumnVisibility(final String group, final Properties properties); byte[] getColumnQualifier(final Element element); byte[] getColumnQualifier(final String group, final Properties properties); Properties getPropertiesFromColumnQualifier(final String group, final byte[] bytes); byte[] getPropertiesAsBytesFromColumnQualifier(final String group, final byte[] bytes, final int numProps); long getTimestamp(final Element element); long getTimestamp(final Properties properties); Properties getPropertiesFromTimestamp(final String group, final long timestamp); byte[] serialiseVertex(final Object vertex); boolean isEntity(final Cell cell); String getGroup(final Cell cell); String getGroup(final byte[] columnQualifier); @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Entity it must be an Edge") Pair<byte[], byte[]> getRowKeys(final Element element); byte[] getRowKey(final Entity entity); Pair<byte[], byte[]> getRowKeys(final Edge edge); Pair<Cell, Cell> getCells(final Element element, final CellCreator kvCreator); Pair<Cell, Cell> getCells(final Element element, final Pair<byte[], byte[]> row, final byte[] cq, final CellCreator kvCreator); Pair<Put, Put> getPuts(final Element element); Pair<Put, Put> getPuts(final Element element, final Pair<byte[], byte[]> row, final byte[] cq); EdgeDirection getSourceAndDestination(final byte[] rowKey, final byte[][] sourceDestValues);  }
@Test public void shouldTruncatePropertyBytesWithEmptyBytes() throws Exception { final byte[] bytes = HBaseStoreConstants.EMPTY_BYTES; final byte[] truncatedBytes = serialisation.getPropertiesAsBytesFromColumnQualifier(TestGroups.EDGE, bytes, 2); assertEquals(0, truncatedBytes.length); }