@Override public void writeTo(ObjectOutput output) throws IOException { MarshallUtil.marshallEnum(commandType, output); output.writeObject(query); MarshallUtil.marshallUUID(lazyQueryId, output, true); output.writeInt(docIndex); }
@Override public void readFrom(ObjectInput input) throws IOException, ClassNotFoundException { commandType = MarshallUtil.unmarshallEnum(input, CQCommandType::valueOf); queryDefinition = (QueryDefinition) input.readObject(); queryId = MarshallUtil.unmarshallUUID(input, true); docIndex = input.readInt(); }
public static void writeTo(ObjectOutput output, XidImpl xid) throws IOException { output.writeInt(xid.formatId); MarshallUtil.marshallByteArray(xid.rawId, output); }
@Override public void writeObject(ObjectOutput output, ClusteredLockValue object) throws IOException { MarshallUtil.marshallString(object.requestId, output); output.writeObject(object.owner); MarshallUtil.marshallEnum(object.state, output); }
@Test public void testEnum() throws IOException { ObjectInputOutput io = new ObjectInputOutput(); MarshallUtil.marshallEnum(null, io); Assert.assertNull(MarshallUtil.unmarshallEnum(io, ordinal -> TestEnum.values()[ordinal])); Assert.assertEquals(0, io.buffer.size()); for (TestEnum e : TestEnum.values()) { io.reset(); MarshallUtil.marshallEnum(e, io); Assert.assertEquals(e, MarshallUtil.unmarshallEnum(io, ordinal -> TestEnum.values()[ordinal])); Assert.assertEquals(0, io.buffer.size()); } }
@Override public void writeObject(ObjectOutput output, CacheContainerAdmin.AdminFlag flag) throws IOException { MarshallUtil.marshallEnum(flag, output); }
@Override public CounterState readObject(ObjectInput input) throws IOException, ClassNotFoundException { return MarshallUtil.unmarshallEnum(input, CounterState::valueOf); } }
@Test public void testByteArray() throws IOException, ClassNotFoundException { ObjectInputOutput io = new ObjectInputOutput(); MarshallUtil.marshallByteArray(null, io); Assert.assertNull(MarshallUtil.unmarshallByteArray(io)); Assert.assertEquals(0, io.buffer.size()); io.reset(); byte[] array = Util.EMPTY_BYTE_ARRAY; MarshallUtil.marshallByteArray(array, io); Assert.assertTrue(Arrays.equals(array, MarshallUtil.unmarshallByteArray(io))); Assert.assertEquals(0, io.buffer.size()); io.reset(); array = new byte[] {1, 2, 3}; MarshallUtil.marshallByteArray(array, io); Assert.assertTrue(Arrays.equals(array, MarshallUtil.unmarshallByteArray(io))); Assert.assertEquals(0, io.buffer.size()); io.reset(); }
@Override public ClusteredLockValue readObject(ObjectInput input) throws IOException, ClassNotFoundException { String requestId = MarshallUtil.unmarshallString(input); Object owner = input.readObject(); ClusteredLockState state = MarshallUtil.unmarshallEnum(input, ClusteredLockState::valueOf); return new ClusteredLockValue(requestId, owner, state); } }
@Override public void readFrom(ObjectInput input) throws IOException, ClassNotFoundException { boolean hasIndexName = input.readBoolean(); if (hasIndexName) { indexName = input.readUTF(); } serializedModel = MarshallUtil.unmarshallByteArray(input); }
@Test public void testUUID() throws IOException { ObjectInputOutput io = new ObjectInputOutput(); MarshallUtil.marshallUUID(null, io, true); Assert.assertNull(MarshallUtil.unmarshallUUID(io, true)); Assert.assertEquals(0, io.buffer.size()); for (int i = 0; i < NR_RANDOM; ++i) { io.reset(); UUID uuid = UUID.randomUUID(); MarshallUtil.marshallUUID(uuid, io, false); Assert.assertEquals(uuid, MarshallUtil.unmarshallUUID(io, false)); Assert.assertEquals(0, io.buffer.size()); } for (int i = 0; i < NR_RANDOM; ++i) { io.reset(); UUID uuid = UUID.randomUUID(); MarshallUtil.marshallUUID(uuid, io, true); Assert.assertEquals(uuid, MarshallUtil.unmarshallUUID(io, true)); Assert.assertEquals(0, io.buffer.size()); } }
@Override public void writeObject(ObjectOutput output, InitializerState value) throws IOException { output.writeByte(VERSION_1); MarshallUtil.marshallString(value.getRealmId(), output); output.writeInt(value.segmentsCount); MarshallUtil.marshallByteArray(value.segments.toByteArray(), output); }
public InitializerState readObjectVersion1(ObjectInput input) throws IOException { return new InitializerState( MarshallUtil.unmarshallString(input), input.readInt(), BitSet.valueOf(MarshallUtil.unmarshallByteArray(input)) ); }
/** * Unmarshal a {@link Collection}. * * @param in {@link ObjectInput} to read. * @param builder {@link CollectionBuilder} builds the concrete {@link Collection} based on size. * @param <E> Collection's element type. * @param <T> {@link Collection} implementation. * @return The concrete {@link Collection} implementation. * @throws IOException If any of the usual Input/Output related exceptions occur. * @throws ClassNotFoundException If the class of a serialized object cannot be found. */ public static <E, T extends Collection<E>> T unmarshallCollection(ObjectInput in, CollectionBuilder<E, T> builder) throws IOException, ClassNotFoundException { return unmarshallCollection(in, builder, input -> (E) input.readObject()); }
@Override public void writeObject(ObjectOutput output, Set set) throws IOException { MarshallUtil.marshallCollection(set, output); }
@Override public void writeObject(ObjectOutput output, AuthenticatedClientSessionEntity session) throws IOException { MarshallUtil.marshallUUID(session.id, output, false); MarshallUtil.marshallString(session.getRealmId(), output); MarshallUtil.marshallString(session.getAuthMethod(), output); MarshallUtil.marshallString(session.getRedirectUri(), output); KeycloakMarshallUtil.marshall(session.getTimestamp(), output); MarshallUtil.marshallString(session.getAction(), output); Map<String, String> notes = session.getNotes(); KeycloakMarshallUtil.writeMap(notes, KeycloakMarshallUtil.STRING_EXT, KeycloakMarshallUtil.STRING_EXT, output); MarshallUtil.marshallString(session.getCurrentRefreshToken(), output); KeycloakMarshallUtil.marshall(session.getCurrentRefreshTokenUseCount(), output); }
@Override public AuthenticatedClientSessionEntity readObject(ObjectInput input) throws IOException, ClassNotFoundException { AuthenticatedClientSessionEntity sessionEntity = new AuthenticatedClientSessionEntity(MarshallUtil.unmarshallUUID(input, false)); sessionEntity.setRealmId(MarshallUtil.unmarshallString(input)); sessionEntity.setAuthMethod(MarshallUtil.unmarshallString(input)); sessionEntity.setRedirectUri(MarshallUtil.unmarshallString(input)); sessionEntity.setTimestamp(KeycloakMarshallUtil.unmarshallInteger(input)); sessionEntity.setAction(MarshallUtil.unmarshallString(input)); Map<String, String> notes = KeycloakMarshallUtil.readMap(input, KeycloakMarshallUtil.STRING_EXT, KeycloakMarshallUtil.STRING_EXT, new KeycloakMarshallUtil.ConcurrentHashMapBuilder<>()); sessionEntity.setNotes(notes); sessionEntity.setCurrentRefreshToken(MarshallUtil.unmarshallString(input)); sessionEntity.setCurrentRefreshTokenUseCount(KeycloakMarshallUtil.unmarshallInteger(input)); return sessionEntity; }
@Override public UUID readObject(ObjectInput input) throws IOException, ClassNotFoundException { return MarshallUtil.unmarshallUUID(input, true); } };
@Override public void writeObject(ObjectOutput output, UUID uuid) throws IOException { MarshallUtil.marshallUUID(uuid, output, true); }
@Test public void testArray() throws IOException, ClassNotFoundException { ObjectInputOutput io = new ObjectInputOutput(); MarshallUtil.marshallArray(null, io); Assert.assertNull(MarshallUtil.unmarshallArray(io, null)); Assert.assertEquals(0, io.buffer.size()); io.reset(); String[] array = new String[0]; MarshallUtil.marshallArray(array, io); Assert.assertTrue(Arrays.equals(array, MarshallUtil.unmarshallArray(io, Util::stringArray))); Assert.assertEquals(0, io.buffer.size()); io.reset(); array = new String[] {"a", "b", "c"}; MarshallUtil.marshallArray(array, io); Assert.assertTrue(Arrays.equals(array, MarshallUtil.unmarshallArray(io, Util::stringArray))); Assert.assertEquals(0, io.buffer.size()); io.reset(); }