use of java.io.ObjectInputStream in project hazelcast by hazelcast.
the class MulticastDiscoveryReceiver method receive.
public MulticastMemberInfo receive() {
ObjectInputStream in = null;
ByteArrayInputStream bis = null;
try {
Object o;
multicastSocket.receive(datagramPacketReceive);
byte[] data = datagramPacketReceive.getData();
MulticastMemberInfo multicastMemberInfo;
bis = new ByteArrayInputStream(data);
in = new ObjectInputStream(bis);
o = in.readObject();
multicastMemberInfo = (MulticastMemberInfo) o;
return multicastMemberInfo;
} catch (Exception e) {
if (logger.isFinestEnabled()) {
logger.finest("Couldn't get member info from multicast channel " + e.getMessage());
}
} finally {
IOUtil.closeResource(bis);
IOUtil.closeResource(in);
}
return null;
}
use of java.io.ObjectInputStream in project bazel by bazelbuild.
the class PathTest method testSerialization.
@Test
public void testSerialization() throws Exception {
FileSystem oldFileSystem = Path.getFileSystemForSerialization();
try {
Path.setFileSystemForSerialization(filesystem);
Path root = filesystem.getPath("/");
Path p1 = filesystem.getPath("/foo");
Path p2 = filesystem.getPath("/foo/bar");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(root);
oos.writeObject(p1);
oos.writeObject(p2);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bis);
Path dsRoot = (Path) ois.readObject();
Path dsP1 = (Path) ois.readObject();
Path dsP2 = (Path) ois.readObject();
new EqualsTester().addEqualityGroup(root, dsRoot).addEqualityGroup(p1, dsP1).addEqualityGroup(p2, dsP2).testEquals();
assertTrue(p2.startsWith(p1));
assertTrue(p2.startsWith(dsP1));
assertTrue(dsP2.startsWith(p1));
assertTrue(dsP2.startsWith(dsP1));
// Regression test for a very specific bug in compareTo involving our incorrect usage of
// reference equality rather than logical equality.
String relativePathStringA = "child/grandchildA";
String relativePathStringB = "child/grandchildB";
assertEquals(p1.getRelative(relativePathStringA).compareTo(p1.getRelative(relativePathStringB)), p1.getRelative(relativePathStringA).compareTo(dsP1.getRelative(relativePathStringB)));
} finally {
Path.setFileSystemForSerialization(oldFileSystem);
}
}
use of java.io.ObjectInputStream in project CoreNLP by stanfordnlp.
the class Extractors method main.
/**
* Prints out the pair of {@code Extractors} objects found in the
* file that is the first and only argument.
* @param args Filename of extractors file (standardly written with
* {@code .ex} extension)
*/
public static void main(String[] args) {
try {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(args[0]));
Extractors extrs = (Extractors) in.readObject();
Extractors extrsRare = (Extractors) in.readObject();
in.close();
System.out.println("All words: " + extrs);
System.out.println("Rare words: " + extrsRare);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of java.io.ObjectInputStream in project bazel by bazelbuild.
the class PackageIdentifierTest method testSerialization.
@Test
public void testSerialization() throws Exception {
PackageIdentifier inId = PackageIdentifier.create("@foo", new PathFragment("bar/baz"));
ByteArrayOutputStream data = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(data);
out.writeObject(inId);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data.toByteArray()));
PackageIdentifier outId = (PackageIdentifier) in.readObject();
assertEquals(inId, outId);
}
use of java.io.ObjectInputStream in project gitblit by gitblit.
the class TicketModel method copy.
/**
* Produce a deep copy of the given object. Serializes the entire object to
* a byte array in memory. Recommended for relatively small objects.
*/
@SuppressWarnings("unchecked")
static <T> T copy(T original) {
T o = null;
try {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(byteOut);
oos.writeObject(original);
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
ObjectInputStream ois = new ObjectInputStream(byteIn);
try {
o = (T) ois.readObject();
} catch (ClassNotFoundException cex) {
// actually can not happen in this instance
}
} catch (IOException iox) {
// doesn't seem likely to happen as these streams are in memory
throw new RuntimeException(iox);
}
return o;
}
Aggregations