@Override public Object getValue() { if (this.value == null) { return null; } return KryoManager.deserialize(this.value); }
@Override public Object deserialize(final byte[] serialForm) { return KryoManager.deserialize(serialForm); }
public Object getValue() { return KryoManager.deserialize(this.value); }
public Indexer<?> getIndexer() { if (this.indexerData == null) { return null; } else { byte[] serialForm = Base64.getDecoder().decode(this.indexerData); return KryoManager.deserialize(serialForm); } }
public static IBranchMetadata getMetadata(final TuplTransaction tx, final String name) { checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); checkNotNull(name, "Precondition violation - argument 'name' must not be NULL!"); byte[] loadedValue = tx.load(NAME, name); if (loadedValue == null) { return null; } return KryoManager.deserialize(loadedValue); }
/** * Returns the map from keyspace name to matrix map name for the given branch. * * @param tx * The transaction to work on. Must not be <code>null</code>, must be open. * @param branchName * The name of the branch to get the keyspace-to-matrix-name map for. Must not be <code>null</code>, must * refer to an existing branch. * * @return The metadata for all known keyspaces in the given branch. * * @throws ChronoDBBranchingException * Thrown if there is no branch with the given name. */ public static Set<KeyspaceMetadata> getKeyspaceMetadata(final TuplTransaction tx, final String branchName) throws ChronoDBBranchingException { checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); checkNotNull(branchName, "Precondition violation - argument 'branchName' must not be NULL!"); assertBranchExists(tx, branchName); byte[] keyspaceToMetadata = tx.load(NAME, branchName); if (keyspaceToMetadata == null) { return Sets.newHashSet(); } Map<String, KeyspaceMetadata> map = KryoManager.deserialize(keyspaceToMetadata); return Sets.newHashSet(map.values()); }
keyspaceToMetadata = KryoManager.deserialize(keyspaceToMatrixBinary);
public static Set<IBranchMetadata> values(final TuplTransaction tx) { checkNotNull(tx, "Precondition violation - argument 'tx' must not be NULL!"); Set<IBranchMetadata> resultSet = Sets.newHashSet(); Cursor cursor = tx.newCursorOn(NAME); try { cursor.first(); if (cursor.key() == null) { // index is empty, return empty result set return resultSet; } while (cursor.key() != null) { byte[] value = cursor.value(); if (value != null) { IBranchMetadata branchMetadata = KryoManager.deserialize(value); resultSet.add(branchMetadata); } cursor.next(); } return resultSet; } catch (IOException ioe) { throw new ChronosIOException("Failed to load branch metadata! See root cause for details.", ioe); } finally { if (cursor != null) { cursor.reset(); } } }
@Test public void canSerializeAndDeserialize() { Person johnDoe = new Person("John", "Doe"); byte[] bytes = KryoManager.serialize(johnDoe); assertNotNull(bytes); Person deserialized = KryoManager.deserialize(bytes); assertEquals(johnDoe, deserialized); }
@Test @SuppressWarnings("unchecked") public void canSerializeAndDeserializeMultipleTrees() { ImmutableMap<String, String> map = ImmutableMaps.newHashArrayMappedTreeMap(); ImmutableMap<String, String> map1 = map.put("Hello", "World"); ImmutableMap<String, String> map2 = map.put("Foo", "Bar"); ImmutableMap<String, String> map3 = map.put("Number", "42"); List<ImmutableMap<String, String>> allVersions = Lists.newArrayList(map, map1, map2, map3); byte[] bytes = KryoManager.serialize(allVersions); List<ImmutableMap<String, String>> allVersions2 = KryoManager.deserialize(bytes); assertNotNull(allVersions2); assertEquals(allVersions, allVersions2); }
@Test public void canSerializeAndDeserializeSingleTree() { ImmutableMap<String, String> map = ImmutableMaps.newHashArrayMappedTreeMap(); map = map.put("Hello", "World"); map = map.put("Foo", "Bar"); map = map.put("Number", "42"); byte[] bytes = KryoManager.serialize(map); ImmutableMap<String, String> map2 = KryoManager.deserialize(bytes); assertNotNull(map2); assertEquals(map.entrySet(), map2.entrySet()); for (Entry<String, String> entry : map.entrySet()) { assertEquals(entry.getValue(), map2.get(entry.getKey())); } for (Entry<String, String> entry : map2.entrySet()) { assertEquals(entry.getValue(), map.get(entry.getKey())); } }