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

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

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

Util.writeGenericStreamable介绍

暂无

代码示例

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

public static void writeObject(Object obj,DataOutput out) throws Exception {
  if(obj instanceof Streamable) {
    out.writeInt(-1);
    writeGenericStreamable((Streamable)obj,out);
  }
  else {
    byte[] buf=objectToByteBuffer(obj);
    out.writeInt(buf.length);
    out.write(buf,0,buf.length);
  }
}

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

public void writeTo(DataOutput out) throws Exception {
  out.writeByte(type.ordinal());
  // We can't use Util.writeObject since it's size is limited to 2^15-1
  try {
    if (object instanceof Streamable) {
      out.writeShort(-1);
      Util.writeGenericStreamable((Streamable)object, out);
    }
    else {
      byte[] bytes = Util.objectToByteBuffer(object);
      out.writeInt(bytes.length);
      out.write(bytes);
    }
  }
  catch (IOException e) {
    throw e;
  }
  catch (Exception e) {
    throw new IOException("Exception encountered while serializing execution request", e);
  }
  out.writeLong(request);
}

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

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

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

public static void writeObject(Object obj,DataOutput out) throws Exception {
  if(obj instanceof Streamable) {
    out.writeInt(-1);
    writeGenericStreamable((Streamable)obj,out);
  }
  else {
    byte[] buf=objectToByteBuffer(obj);
    out.writeInt(buf.length);
    out.write(buf,0,buf.length);
  }
}

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

public static void writeObject(Object obj, DataOutputStream out) throws Exception {
  if(obj == null || !(obj instanceof Streamable)) {
    byte[] buf=objectToByteBuffer(obj);
    out.writeShort(buf.length);
    out.write(buf, 0, buf.length);
  }
  else {
    out.writeShort(-1);
    writeGenericStreamable((Streamable)obj, out);
  }
}

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

/**
 * Serializes/Streams an object into a byte buffer.
 * The object has to implement interface Serializable or Externalizable
 * or Streamable.  Only Streamable objects are interoperable w/ jgroups-me
 */
public static byte[] oldObjectToByteBuffer(Object obj) throws Exception {
  byte[] result=null;
  synchronized(out_stream) {
    out_stream.reset();
    if(obj instanceof Streamable) {  // use Streamable if we can
      DataOutputStream out=new DataOutputStream(out_stream);
      writeGenericStreamable((Streamable)obj, out);
      out.close();
    }
    else {
      ObjectOutputStream out=new ObjectOutputStream(out_stream);
      out.writeObject(obj);
      out.close();
    }
    result=out_stream.toByteArray();
  }
  return result;
}

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

public void writeTo(DataOutput out) throws Exception {
  out.writeByte(type.ordinal());
  // We can't use Util.writeObject since it's size is limited to 2^15-1
  try {
    if (object instanceof Streamable) {
      out.writeShort(-1);
      Util.writeGenericStreamable((Streamable)object, out);
    }
    else {
      byte[] bytes = Util.objectToByteBuffer(object);
      out.writeInt(bytes.length);
      out.write(bytes);
    }
  }
  catch (IOException e) {
    throw e;
  }
  catch (Exception e) {
    throw new IOException("Exception encountered while serializing execution request", e);
  }
  out.writeLong(request);
}

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

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

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

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

代码示例来源: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));
}

相关文章

Util类方法