本文整理了Java中org.jgroups.util.Util.marshalPrimitiveType()
方法的一些代码示例,展示了Util.marshalPrimitiveType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.marshalPrimitiveType()
方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:marshalPrimitiveType
暂无
代码示例来源:origin: wildfly/wildfly
/**
* Serializes/Streams an object into a byte buffer.
* The object has to implement interface Serializable or Externalizable or Streamable.
*/
public static byte[] objectToByteBuffer(Object obj) throws Exception {
if(obj == null)
return TYPE_NULL_ARRAY;
if(obj instanceof Streamable) {
int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512;
final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true);
out.write(TYPE_STREAMABLE);
writeGenericStreamable((Streamable)obj,out);
return Arrays.copyOf(out.buf,out.position());
}
Byte type=PRIMITIVE_TYPES.get(obj.getClass());
if(type == null) { // will throw an exception if object is not serializable
final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true);
out_stream.write(TYPE_SERIALIZABLE);
try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) {
out.writeObject(obj);
out.flush();
return Arrays.copyOf(out_stream.buffer(), out_stream.position());
}
}
return marshalPrimitiveType(type, obj);
}
代码示例来源:origin: wildfly/wildfly
public static Buffer objectToBuffer(Object obj) throws Exception {
if(obj == null)
return new Buffer(TYPE_NULL_ARRAY);
if(obj instanceof Streamable) {
int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512;
final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true);
out.write(TYPE_STREAMABLE);
writeGenericStreamable((Streamable)obj,out);
return out.getBuffer();
}
Byte type=PRIMITIVE_TYPES.get(obj.getClass());
if(type == null) { // will throw an exception if object is not serializable
final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true);
out_stream.write(TYPE_SERIALIZABLE);
try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) {
out.writeObject(obj);
out.flush();
return out_stream.getBuffer();
}
}
return new Buffer(marshalPrimitiveType(type, obj));
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
/**
* Serializes/Streams an object into a byte buffer.
* The object has to implement interface Serializable or Externalizable or Streamable.
*/
public static byte[] objectToByteBuffer(Object obj) throws Exception {
if(obj == null)
return TYPE_NULL_ARRAY;
if(obj instanceof Streamable) {
int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512;
final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true);
out.write(TYPE_STREAMABLE);
writeGenericStreamable((Streamable)obj,out);
return Arrays.copyOf(out.buf,out.position());
}
Byte type=PRIMITIVE_TYPES.get(obj.getClass());
if(type == null) { // will throw an exception if object is not serializable
final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true);
out_stream.write(TYPE_SERIALIZABLE);
try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) {
out.writeObject(obj);
out.flush();
return Arrays.copyOf(out_stream.buffer(), out_stream.position());
}
}
return marshalPrimitiveType(type, obj);
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
public static Buffer objectToBuffer(Object obj) throws Exception {
if(obj == null)
return new Buffer(TYPE_NULL_ARRAY);
if(obj instanceof Streamable) {
int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512;
final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true);
out.write(TYPE_STREAMABLE);
writeGenericStreamable((Streamable)obj,out);
return out.getBuffer();
}
Byte type=PRIMITIVE_TYPES.get(obj.getClass());
if(type == null) { // will throw an exception if object is not serializable
final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true);
out_stream.write(TYPE_SERIALIZABLE);
try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) {
out.writeObject(obj);
out.flush();
return out_stream.getBuffer();
}
}
return new Buffer(marshalPrimitiveType(type, obj));
}
内容来源于网络,如有侵权,请联系作者删除!