java.io.ObjectOutputStream.enableReplaceObject()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(103)

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

ObjectOutputStream.enableReplaceObject介绍

[英]Enables object replacement for this stream. By default this is not enabled. Only trusted subclasses (loaded with system class loader) are allowed to change this status.
[中]启用此流的对象替换。默认情况下,此选项未启用。仅允许受信任的子类(使用系统类加载器加载)更改此状态。

代码示例

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

/**
 * Object output stream decoration constructor.
 *
 * @param out
 * @throws IOException
 * @see ObjectOutputStream#ObjectOutputStream(OutputStream)
 */
public BukkitObjectOutputStream(OutputStream out) throws IOException {
  super(out);
  super.enableReplaceObject(true);
}

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

/**
 * Constructor provided to mirror super functionality.
 *
 * @throws IOException
 * @throws SecurityException
 * @see ObjectOutputStream#ObjectOutputStream()
 */
protected BukkitObjectOutputStream() throws IOException, SecurityException {
  super();
  super.enableReplaceObject(true);
}

代码示例来源:origin: org.glassfish.main.common/container-common

public JavaEEObjectOutputStream(OutputStream oos, boolean replaceObject,
                Collection<JavaEEObjectStreamHandler> handlers)
  throws IOException {
  super(oos);
  super.enableReplaceObject(replaceObject);
  this.handlers = handlers;
}

代码示例来源:origin: SpigotMC/Spigot-API

/**
 * Object output stream decoration constructor.
 *
 * @param out
 * @throws IOException
 * @see ObjectOutputStream#ObjectOutputStream(OutputStream)
 */
public BukkitObjectOutputStream(OutputStream out) throws IOException {
  super(out);
  super.enableReplaceObject(true);
}

代码示例来源:origin: org.glassfish.common/container-common

public JavaEEObjectOutputStream(OutputStream oos, boolean replaceObject,
                Collection<JavaEEObjectStreamHandler> handlers)
  throws IOException {
  super(oos);
  super.enableReplaceObject(replaceObject);
  this.handlers = handlers;
}

代码示例来源:origin: au.net.zeus.jgdms/jgdms-platform

@Override
public boolean enableReplaceObject(boolean enable)
  throws SecurityException
{
  return super.enableReplaceObject(enable);
}
}

代码示例来源:origin: SpigotMC/Spigot-API

/**
 * Constructor provided to mirror super functionality.
 *
 * @throws IOException
 * @throws SecurityException
 * @see ObjectOutputStream#ObjectOutputStream()
 */
protected BukkitObjectOutputStream() throws IOException, SecurityException {
  super();
  super.enableReplaceObject(true);
}

代码示例来源:origin: stackoverflow.com

public class SurrogateObjectOutputStream extends ObjectOutputStream {

  public SurrogateObjectOutputStream(OutputStream out) throws IOException {
    super(out);
    enableReplaceObject(true);
  }

  protected SurrogateObjectOutputStream() throws IOException, SecurityException {
    super();
    enableReplaceObject(true);
  }

  @Override
  protected Object replaceObject(Object obj) throws IOException {
    if (obj instanceof Pojo) {
      return new PojoSurrogate((Pojo) obj);
    } else return super.replaceObject(obj);
  } 
}

代码示例来源:origin: stackoverflow.com

public class SerializableLatLngOutputStream extends ObjectOutputStream {

  public SerializableLatLngOutputStream(OutputStream out) throws IOException {
    super(out);
    enableReplaceObject(true);
  }

  protected SerializableLatLngOutputStream() throws IOException, SecurityException {
    super();
    enableReplaceObject(true);
  }

  @Override
  protected Object replaceObject(Object obj) throws IOException {
    if (obj instanceof LatLng) {
      return new SerializableLatLng((LatLng) obj);
    } else return super.replaceObject(obj);
  }

}

代码示例来源:origin: stackoverflow.com

public class SurrogateOutputStream extends ObjectOutputStream {

  public SurrogateOutputStream(OutputStream out) throws IOException {
    super(out);
    enableReplaceObject(true);
  }

  protected SurrogateOutputStream() throws IOException, SecurityException {
    super();
    enableReplaceObject(true);
  }

  @Override
  protected Object replaceObject(Object obj) throws IOException {
    if (obj instanceof Area) {
      return new AreaSurrogate((Area) obj);
    } else {
      return super.replaceObject(obj);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public class FooObjOutputStream extends ObjectOutputStream {
  public FooObjOutputStream(OutputStream out) throws IOException {
    super(out);
    enableReplaceObject(true);
  }

  protected FooObjOutputStream() throws IOException, SecurityException {
    super();
    enableReplaceObject(true);
  }

  @Override
  protected Object replaceObject(Object obj) throws IOException {
    if (obj instanceof Foo) {
      return new FooState((Foo) obj);
    } else {
      return super.replaceObject(obj);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public class MyOOS extends ObjectOutputStream {
  public MyOOS(OutputStream out) throws IOException {
    super(out);
    enableReplaceObject(true);
  }

  @Override
  protected Object replaceObject(Object obj) throws IOException {
    if ((obj instanceof Serializable))
      return obj;
    System.err.println("Skipping serialization of "+obj);
    return null;
  }
}

代码示例来源:origin: stackoverflow.com

public class StringPooledObjectOutputStream extends ObjectOutputStream {
  private Map<String, String> stringPool = new HashMap<String, String>();
  public StringPooledObjectOutputStream(OutputStream out) throws IOException {
    super(out);
    enableReplaceObject(true);
  }

  @Override
  protected Object replaceObject(Object obj) throws IOException {
    if( !(obj instanceof String) )
      return super.replaceObject(obj);

    String str = (String)obj;

    String replacedStr = stringPool.get(str);
    if( replacedStr == null ){
      replacedStr = (String)super.replaceObject(str);
      stringPool.put(replacedStr, replacedStr);
    }
    return replacedStr;
  }
}

代码示例来源:origin: org.jboss/jboss-serialization

protected boolean enableReplaceObject(boolean enable)
{
  try
  {
    if (enable == fieldEnableReplace.getBoolean(this)) {
      return enable;
    }
    fieldEnableReplace.setBoolean(this,enable);
    return !fieldEnableReplace.getBoolean(this);
  }
  catch (Exception e)
  {
    e.printStackTrace();
    // trying the super method
    return super.enableReplaceObject(enable);
  }
}

代码示例来源:origin: stackoverflow.com

enableReplaceObject(true);

代码示例来源:origin: stackoverflow.com

enableReplaceObject(true);

相关文章

ObjectOutputStream类方法