
org.sapia.ubik.mcast.Util Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sapia_ubik Show documentation
Show all versions of sapia_ubik Show documentation
A RMI-like distributed computing framework
The newest version!
package org.sapia.ubik.mcast;
import java.io.*;
import java.net.DatagramPacket;
/**
* @author Yanick Duchesne
*
* - Copyright:
- Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
* - License:
- Read the license.txt file of the jar or visit the
* license page at the Sapia OSS web site
*
*/
public class Util {
public static Object fromDatagram(DatagramPacket pack)
throws IOException, ClassNotFoundException {
ByteArrayInputStream bis = new ByteArrayInputStream(pack.getData(),
pack.getOffset(), pack.getLength());
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(bis);
Object o = ois.readObject();
return o;
} finally {
if (ois != null) {
ois.close();
}
}
}
public static byte[] toBytes(Object o, int bufsize) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(bufsize);
ObjectOutputStream ous = new ObjectOutputStream(bos);
ous.writeObject(o);
ous.flush();
ous.close();
return bos.toByteArray();
}
public static int getSizeInBytes(Object o) throws IOException {
return toBytes(o, 1000).length;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy