if (i > 0) { try { typeSubTypeValue.setType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the Type from TypeSubTypeValue Object", e); if (i > lastDelimiter) { try { typeSubTypeValue.setSubType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the SubType from TypeSubTypeValue Object", e); typeSubTypeValue.setValue(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, bytes.length), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the Value from TypeSubTypeValue Object", e);
@Override public TypeValue deserialise(final byte[] bytes) throws SerialisationException { int lastDelimiter = 0; TypeValue typeValue = new TypeValue(); for (int i = 0; i < bytes.length; i++) { if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) { if (i > 0) { try { typeValue.setType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the Type from TypeValue Object", e); } } lastDelimiter = i + 1; break; } } if (bytes.length > lastDelimiter) { try { typeValue.setValue(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, bytes.length), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the Value from TypeValue Object", e); } } return typeValue; }
key = new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise a key from a FreqMap", e); final Long value = longSerialiser.deserialise(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i)); freqMap.put(key, value); key = null; final Long value = longSerialiser.deserialise(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, bytes.length)); freqMap.put(key, value);
@Test public void testCanSerialiseDeserialiseCorrectlyAndBeEscaped() throws SerialisationException { TypeValue typeValue = new TypeValue("testType", "testValue"); byte[] bytes = ByteArrayEscapeUtils.escape(serialiser.serialise(typeValue)); String serialisedForm = new String(bytes); assertEquals("testType\1\1testValue", serialisedForm); TypeValue deSerialisedTypeValue = serialiser.deserialise(ByteArrayEscapeUtils .unEscape(bytes)); assertEquals(typeValue.getType(), deSerialisedTypeValue.getType()); assertEquals(typeValue.getValue(), deSerialisedTypeValue.getValue()); assertEquals(typeValue, deSerialisedTypeValue); }
@Test public void testCanSerialiseDeserialiseCorrectlyAndBeEscaped() throws SerialisationException { TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue("testType", "testSubType", "testValue"); byte[] bytes = ByteArrayEscapeUtils.escape(serialiser.serialise(typeSubTypeValue)); String serialisedForm = new String(bytes); assertEquals("testType\1\1testSubType\1\1testValue", serialisedForm); TypeSubTypeValue deSerialisedTypeSubTypeValue = serialiser .deserialise(ByteArrayEscapeUtils.unEscape(bytes)); assertEquals(typeSubTypeValue.getType(), deSerialisedTypeSubTypeValue.getType()); assertEquals(typeSubTypeValue.getSubType(), deSerialisedTypeSubTypeValue.getSubType()); assertEquals(typeSubTypeValue.getValue(), deSerialisedTypeSubTypeValue.getValue()); assertEquals(typeSubTypeValue, deSerialisedTypeSubTypeValue); }
@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); } }
@Override public TypeValue deserialise(final byte[] bytes) throws SerialisationException { int lastDelimiter = 0; TypeValue typeValue = new TypeValue(); for (int i = 0; i < bytes.length; i++) { if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) { if (i > 0) { try { typeValue.setType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the Type from TypeValue Object", e); } } lastDelimiter = i + 1; break; } } if (bytes.length > lastDelimiter) { try { typeValue.setValue(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, bytes.length), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the Value from TypeValue Object", e); } } return typeValue; }
if (i > 0) { try { typeSubTypeValue.setType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the Type from TypeSubTypeValue Object", e); if (i > lastDelimiter) { try { typeSubTypeValue.setSubType(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the SubType from TypeSubTypeValue Object", e); typeSubTypeValue.setValue(new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, bytes.length), CommonConstants.UTF_8)); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise the Value from TypeSubTypeValue Object", e);
key = new String(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i), CommonConstants.UTF_8); } catch (final UnsupportedEncodingException e) { throw new SerialisationException("Failed to deserialise a key from a FreqMap", e); final Long value = longSerialiser.deserialise(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, i)); freqMap.put(key, value); key = null; final Long value = longSerialiser.deserialise(ByteArrayEscapeUtils.unEscape(bytes, lastDelimiter, bytes.length)); freqMap.put(key, value);
@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); } }
@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); } }
@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); } }