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

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

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

ObjectOutputStream.writeUnshared介绍

[英]Writes an unshared object to the target stream. This method is identical to writeObject, except that it always writes a new object to the stream versus the use of back-referencing for identical objects by writeObject.
[中]将非共享对象写入目标流。此方法与writeObject相同,只是它总是将新对象写入流,而不是writeObject对相同对象使用反向引用。

代码示例

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

/** {@inheritDoc} */
public void writeObjectUnshared(final Object obj) throws IOException {
  oos.writeUnshared(obj);
}

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

writeUnshared(objField);
} else {
  writeObject(objField);

代码示例来源:origin: com.github.akurilov/java-commons

@Override
public boolean put(final T item)
throws IOException {
  output.writeUnshared(item);
  return true;
}

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

/** {@inheritDoc} */
public void writeObjectUnshared(final Object obj) throws IOException {
  oos.writeUnshared(obj);
}

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

/** {@inheritDoc} */
public void writeObjectUnshared(final Object obj) throws IOException {
  oos.writeUnshared(obj);
}

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

/** {@inheritDoc} */
public void writeObjectUnshared(final Object obj) throws IOException {
  oos.writeUnshared(obj);
}

代码示例来源:origin: jboss-remoting/jboss-marshalling

/** {@inheritDoc} */
public void writeObjectUnshared(final Object obj) throws IOException {
  oos.writeUnshared(obj);
}

代码示例来源:origin: jboss-remoting/jboss-marshalling

/** {@inheritDoc} */
public void writeObjectUnshared(final Object obj) throws IOException {
  oos.writeUnshared(obj);
}

代码示例来源:origin: EngineHub/CommandHelper

@Override
public void writeUnshared(Object obj) throws IOException {
  super.writeUnshared(obj);
  super.flush();
}

代码示例来源:origin: com.squareup/tape

/** Serializes o to bytes. */
  @Override public void toStream(T o, OutputStream bytes) throws IOException {
  ObjectOutputStream out = new ObjectOutputStream(bytes);
  out.writeUnshared(o);
  out.close();
 }
}

代码示例来源:origin: com.github.akurilov/java-commons

@Override
public int put(final List<T> buffer, final int from, final int to)
throws IOException {
  output.writeUnshared(
    buffer
      .subList(from, to)
      .toArray(new Object[to - from])
  );
  return to - from;
}

代码示例来源:origin: hazelcast/hazelcast-jet

private void write(OutputStream out, Object obj) throws IOException {
  ObjectOutputStream objectOutputStream = new ObjectOutputStream(out);
  if (shared) {
    objectOutputStream.writeObject(obj);
  } else {
    objectOutputStream.writeUnshared(obj);
  }
  // Force flush if not yet written due to internal behavior if pos < 1024
  objectOutputStream.flush();
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private void write(OutputStream out, Object obj) throws IOException {
  ObjectOutputStream objectOutputStream = new ObjectOutputStream(out);
  if (shared) {
    objectOutputStream.writeObject(obj);
  } else {
    objectOutputStream.writeUnshared(obj);
  }
  // Force flush if not yet written due to internal behavior if pos < 1024
  objectOutputStream.flush();
}

代码示例来源:origin: io.core9/core

/**
 * We do this ourself.
 * 
 * @param stream
 * @throws IOException
 */
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
  stream.writeShort(this.version);
  stream.writeLong(this.date);
  stream.writeLong(this.threadID);
  stream.writeUnshared(this.stackTrace);
  stream.writeUnshared(this.channel);
  stream.writeUnshared(this.value);
  stream.writeUnshared(this.additionalInfo);
}

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

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);

List<String> strings = new ArrayList<String>();
strings.add("hello");

oos.writeUnshared(strings);

strings.set(0, "world");

oos.writeUnshared(strings);

oos.close();

ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));

System.out.println(ois.readObject());
System.out.println(ois.readObject());

代码示例来源:origin: org.gridkit.lab/nimble-core

public static void writeToStream(ObjectOutputStream stream, StreamSampleRow row, Set<Object> backrefs) throws IOException {
  stream.writeUnshared(row);
  for(Map.Entry<Object, Object> e: row.data.entrySet()) {
    backrefs.add(e.getKey());
    Object v = e.getValue();
    if (v != null && !PRIMITIVES.contains(v.getClass())) {
      backrefs.add(v);
    }
    if (row.sharedStrings && v instanceof String) {
      backrefs.add(v);
    }
  }        
}

代码示例来源:origin: org.apache.polygene.core/org.apache.polygene.core.api

protected byte[] serializeJava( Object object )
{
  ByteArrayOutputStream bout = new ByteArrayOutputStream();
  try( ObjectOutputStream out = new ObjectOutputStream( bout ) )
  {
    out.writeUnshared( object );
    out.flush();
    return bout.toByteArray();
  }
  catch( IOException ex )
  {
    throw new SerializationException( "Unable to serialize using Java serialization", ex );
  }
}

代码示例来源:origin: apache/attic-polygene-java

protected byte[] serializeJava( Object object )
{
  ByteArrayOutputStream bout = new ByteArrayOutputStream();
  try( ObjectOutputStream out = new ObjectOutputStream( bout ) )
  {
    out.writeUnshared( object );
    out.flush();
    return bout.toByteArray();
  }
  catch( IOException ex )
  {
    throw new SerializationException( "Unable to serialize using Java serialization", ex );
  }
}

代码示例来源:origin: com.healthmarketscience.rmiio/rmiio

/**
 * Writes the given object to the given output stream.  The default
 * implementation uses {@link java.io.ObjectOutputStream#writeUnshared} as
 * well as periodically calls {@link java.io.ObjectOutputStream#reset} on
 * the output stream.  Subclasses may choose to change this behavior by
 * overriding this method.
 *
 * @param ostream the output stream to which the object should be written
 * @param obj the object to write
 */
protected void serializeObject(ObjectOutputStream ostream, Object obj)
 throws IOException
{
 ostream.writeUnshared(obj);
 _numObjectsWrittenSinceLastReset++;
 if(_numObjectsWrittenSinceLastReset >= _resetNumObjects) {
  ostream.reset();
  _numObjectsWrittenSinceLastReset = 0;
 }
}

代码示例来源:origin: rsiebert/TVHClient

private void serializeMessageToBuffer(@NonNull HtspMessage message) {

    mLock.lock();
    try {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      ObjectOutputStream objectOutput = new ObjectOutputStream(outputStream);
      objectOutput.writeUnshared(message);
      objectOutput.flush();

      mBuffer.position(mBuffer.limit());
      mBuffer.limit(mBuffer.capacity());

      mBuffer.put(outputStream.toByteArray());

      mBuffer.flip();
    } catch (IOException e) {
      // Ignore?
      Timber.w("Caught IOException, ignoring (" + mDataSourceNumber + ")", e);
    } catch (BufferOverflowException boe) {
      Timber.w("Caught BufferOverflowException, ignoring (" + mDataSourceNumber + ")", boe);
    } finally {
      mLock.unlock();
      // Ignore
    }
  }
}

相关文章

ObjectOutputStream类方法