use of java.io.ObjectInputStream in project hazelcast by hazelcast.
the class SerializationTest method testMemberLeftException.
private void testMemberLeftException(String uuid, String host, int port, Member member) throws Exception {
MemberLeftException exception = new MemberLeftException(member);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bout);
out.writeObject(exception);
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
ObjectInputStream in = new ObjectInputStream(bin);
MemberLeftException exception2 = (MemberLeftException) in.readObject();
MemberImpl member2 = (MemberImpl) exception2.getMember();
assertEquals(uuid, member2.getUuid());
assertEquals(host, member2.getAddress().getHost());
assertEquals(port, member2.getAddress().getPort());
assertEquals(member.isLiteMember(), member2.isLiteMember());
assertEquals(member.getVersion(), member2.getVersion());
}
use of java.io.ObjectInputStream in project guava by hceylan.
the class ReserializingTestCollectionGenerator method reserialize.
@SuppressWarnings("unchecked")
static <T> T reserialize(T object) {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(object);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
return (T) in.readObject();
} catch (IOException e) {
Helpers.fail(e, e.getMessage());
} catch (ClassNotFoundException e) {
Helpers.fail(e, e.getMessage());
}
throw new AssertionError("not reachable");
}
use of java.io.ObjectInputStream in project guava by google.
the class SetsTest method testImmutableEnumSet_deserializationMakesDefensiveCopy.
// java serialization not supported in GWT.
@GwtIncompatible
public void testImmutableEnumSet_deserializationMakesDefensiveCopy() throws Exception {
ImmutableSet<SomeEnum> original = Sets.immutableEnumSet(SomeEnum.A, SomeEnum.B);
int handleOffset = 6;
byte[] serializedForm = serializeWithBackReference(original, handleOffset);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedForm));
ImmutableSet<?> deserialized = (ImmutableSet<?>) in.readObject();
EnumSet<?> delegate = (EnumSet<?>) in.readObject();
assertEquals(original, deserialized);
assertTrue(delegate.remove(SomeEnum.A));
assertTrue(deserialized.contains(SomeEnum.A));
}
use of java.io.ObjectInputStream in project guava by google.
the class MultimapBuilderTest method reserialize.
// serialization
@GwtIncompatible
private static Object reserialize(Object object) throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
new ObjectOutputStream(bytes).writeObject(object);
return new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray())).readObject();
}
use of java.io.ObjectInputStream in project guice by google.
the class MultibinderTest method testMultibinderSetIsSerializable.
public void testMultibinderSetIsSerializable() throws IOException, ClassNotFoundException {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
Multibinder.newSetBinder(binder(), String.class).addBinding().toInstance("A");
}
});
Set<String> set = injector.getInstance(Key.get(setOfString));
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteStream);
try {
objectOutputStream.writeObject(set);
} finally {
objectOutputStream.close();
}
ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(byteStream.toByteArray()));
try {
Object setCopy = objectInputStream.readObject();
assertEquals(set, setCopy);
} finally {
objectInputStream.close();
}
}
Aggregations