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

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

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

Util.writeGenericStreamable介绍

暂无

代码示例

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

  1. public static void writeObject(Object obj,DataOutput out) throws Exception {
  2. if(obj instanceof Streamable) {
  3. out.writeInt(-1);
  4. writeGenericStreamable((Streamable)obj,out);
  5. }
  6. else {
  7. byte[] buf=objectToByteBuffer(obj);
  8. out.writeInt(buf.length);
  9. out.write(buf,0,buf.length);
  10. }
  11. }

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

  1. public void writeTo(DataOutput out) throws Exception {
  2. out.writeByte(type.ordinal());
  3. // We can't use Util.writeObject since it's size is limited to 2^15-1
  4. try {
  5. if (object instanceof Streamable) {
  6. out.writeShort(-1);
  7. Util.writeGenericStreamable((Streamable)object, out);
  8. }
  9. else {
  10. byte[] bytes = Util.objectToByteBuffer(object);
  11. out.writeInt(bytes.length);
  12. out.write(bytes);
  13. }
  14. }
  15. catch (IOException e) {
  16. throw e;
  17. }
  18. catch (Exception e) {
  19. throw new IOException("Exception encountered while serializing execution request", e);
  20. }
  21. out.writeLong(request);
  22. }

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

  1. if(obj instanceof Streamable) { // use Streamable if we can
  2. out.write(TYPE_STREAMABLE);
  3. writeGenericStreamable((Streamable)obj,out);

代码示例来源: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. public static void writeObject(Object obj,DataOutput out) throws Exception {
  2. if(obj instanceof Streamable) {
  3. out.writeInt(-1);
  4. writeGenericStreamable((Streamable)obj,out);
  5. }
  6. else {
  7. byte[] buf=objectToByteBuffer(obj);
  8. out.writeInt(buf.length);
  9. out.write(buf,0,buf.length);
  10. }
  11. }

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

  1. public static void writeObject(Object obj, DataOutputStream out) throws Exception {
  2. if(obj == null || !(obj instanceof Streamable)) {
  3. byte[] buf=objectToByteBuffer(obj);
  4. out.writeShort(buf.length);
  5. out.write(buf, 0, buf.length);
  6. }
  7. else {
  8. out.writeShort(-1);
  9. writeGenericStreamable((Streamable)obj, out);
  10. }
  11. }

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

  1. /**
  2. * Serializes/Streams an object into a byte buffer.
  3. * The object has to implement interface Serializable or Externalizable
  4. * or Streamable. Only Streamable objects are interoperable w/ jgroups-me
  5. */
  6. public static byte[] oldObjectToByteBuffer(Object obj) throws Exception {
  7. byte[] result=null;
  8. synchronized(out_stream) {
  9. out_stream.reset();
  10. if(obj instanceof Streamable) { // use Streamable if we can
  11. DataOutputStream out=new DataOutputStream(out_stream);
  12. writeGenericStreamable((Streamable)obj, out);
  13. out.close();
  14. }
  15. else {
  16. ObjectOutputStream out=new ObjectOutputStream(out_stream);
  17. out.writeObject(obj);
  18. out.close();
  19. }
  20. result=out_stream.toByteArray();
  21. }
  22. return result;
  23. }

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

  1. public void writeTo(DataOutput out) throws Exception {
  2. out.writeByte(type.ordinal());
  3. // We can't use Util.writeObject since it's size is limited to 2^15-1
  4. try {
  5. if (object instanceof Streamable) {
  6. out.writeShort(-1);
  7. Util.writeGenericStreamable((Streamable)object, out);
  8. }
  9. else {
  10. byte[] bytes = Util.objectToByteBuffer(object);
  11. out.writeInt(bytes.length);
  12. out.write(bytes);
  13. }
  14. }
  15. catch (IOException e) {
  16. throw e;
  17. }
  18. catch (Exception e) {
  19. throw new IOException("Exception encountered while serializing execution request", e);
  20. }
  21. out.writeLong(request);
  22. }

代码示例来源:origin: org.jgroups/com.springsource.org.jgroups

  1. out_stream.write(TYPE_STREAMABLE);
  2. out=new DataOutputStream(out_stream);
  3. writeGenericStreamable((Streamable)obj, (DataOutputStream)out);

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

  1. if(obj instanceof Streamable) { // use Streamable if we can
  2. out.write(TYPE_STREAMABLE);
  3. writeGenericStreamable((Streamable)obj,out);

代码示例来源: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类方法