org.jgroups.util.Util.marshalPrimitiveType()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(218)

本文整理了Java中org.jgroups.util.Util.marshalPrimitiveType()方法的一些代码示例,展示了Util.marshalPrimitiveType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.marshalPrimitiveType()方法的具体详情如下:
包路径:org.jgroups.util.Util
类名称:Util
方法名:marshalPrimitiveType

Util.marshalPrimitiveType介绍

暂无

代码示例

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Serializes/Streams an object into a byte buffer.
  3. * The object has to implement interface Serializable or Externalizable or Streamable.
  4. */
  5. public static byte[] objectToByteBuffer(Object obj) throws Exception {
  6. if(obj == null)
  7. return TYPE_NULL_ARRAY;
  8. if(obj instanceof Streamable) {
  9. int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512;
  10. final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true);
  11. out.write(TYPE_STREAMABLE);
  12. writeGenericStreamable((Streamable)obj,out);
  13. return Arrays.copyOf(out.buf,out.position());
  14. }
  15. Byte type=PRIMITIVE_TYPES.get(obj.getClass());
  16. if(type == null) { // will throw an exception if object is not serializable
  17. final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true);
  18. out_stream.write(TYPE_SERIALIZABLE);
  19. try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) {
  20. out.writeObject(obj);
  21. out.flush();
  22. return Arrays.copyOf(out_stream.buffer(), out_stream.position());
  23. }
  24. }
  25. return marshalPrimitiveType(type, obj);
  26. }

代码示例来源:origin: wildfly/wildfly

  1. public static Buffer objectToBuffer(Object obj) throws Exception {
  2. if(obj == null)
  3. return new Buffer(TYPE_NULL_ARRAY);
  4. if(obj instanceof Streamable) {
  5. int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512;
  6. final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true);
  7. out.write(TYPE_STREAMABLE);
  8. writeGenericStreamable((Streamable)obj,out);
  9. return out.getBuffer();
  10. }
  11. Byte type=PRIMITIVE_TYPES.get(obj.getClass());
  12. if(type == null) { // will throw an exception if object is not serializable
  13. final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true);
  14. out_stream.write(TYPE_SERIALIZABLE);
  15. try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) {
  16. out.writeObject(obj);
  17. out.flush();
  18. return out_stream.getBuffer();
  19. }
  20. }
  21. return new Buffer(marshalPrimitiveType(type, obj));
  22. }

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. /**
  2. * Serializes/Streams an object into a byte buffer.
  3. * The object has to implement interface Serializable or Externalizable or Streamable.
  4. */
  5. public static byte[] objectToByteBuffer(Object obj) throws Exception {
  6. if(obj == null)
  7. return TYPE_NULL_ARRAY;
  8. if(obj instanceof Streamable) {
  9. int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512;
  10. final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true);
  11. out.write(TYPE_STREAMABLE);
  12. writeGenericStreamable((Streamable)obj,out);
  13. return Arrays.copyOf(out.buf,out.position());
  14. }
  15. Byte type=PRIMITIVE_TYPES.get(obj.getClass());
  16. if(type == null) { // will throw an exception if object is not serializable
  17. final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true);
  18. out_stream.write(TYPE_SERIALIZABLE);
  19. try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) {
  20. out.writeObject(obj);
  21. out.flush();
  22. return Arrays.copyOf(out_stream.buffer(), out_stream.position());
  23. }
  24. }
  25. return marshalPrimitiveType(type, obj);
  26. }

代码示例来源:origin: org.jboss.eap/wildfly-client-all

  1. public static Buffer objectToBuffer(Object obj) throws Exception {
  2. if(obj == null)
  3. return new Buffer(TYPE_NULL_ARRAY);
  4. if(obj instanceof Streamable) {
  5. int expected_size=obj instanceof SizeStreamable? ((SizeStreamable)obj).serializedSize() : 512;
  6. final ByteArrayDataOutputStream out=new ByteArrayDataOutputStream(expected_size, true);
  7. out.write(TYPE_STREAMABLE);
  8. writeGenericStreamable((Streamable)obj,out);
  9. return out.getBuffer();
  10. }
  11. Byte type=PRIMITIVE_TYPES.get(obj.getClass());
  12. if(type == null) { // will throw an exception if object is not serializable
  13. final ByteArrayDataOutputStream out_stream=new ByteArrayDataOutputStream(512, true);
  14. out_stream.write(TYPE_SERIALIZABLE);
  15. try(ObjectOutputStream out=new ObjectOutputStream(new OutputStreamAdapter(out_stream))) {
  16. out.writeObject(obj);
  17. out.flush();
  18. return out_stream.getBuffer();
  19. }
  20. }
  21. return new Buffer(marshalPrimitiveType(type, obj));
  22. }

相关文章

Util类方法