本文整理了Java中java.io.ObjectOutputStream.reset()
方法的一些代码示例,展示了ObjectOutputStream.reset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectOutputStream.reset()
方法的具体详情如下:
包路径:java.io.ObjectOutputStream
类名称:ObjectOutputStream
方法名:reset
[英]Resets the state of this stream. A marker is written to the stream, so that the corresponding input stream will also perform a reset at the same point. Objects previously written are no longer remembered, so they will be written again (instead of a cyclical reference) if found in the object graph.
[中]重置此流的状态。一个标记被写入流,因此相应的输入流也将在同一点执行重置。以前写入的对象将不再被记住,因此如果在对象图中找到,它们将被再次写入(而不是循环引用)。
代码示例来源:origin: stackoverflow.com
public class AppendingObjectOutputStream extends ObjectOutputStream {
public AppendingObjectOutputStream(OutputStream out) throws IOException {
super(out);
}
@Override
protected void writeStreamHeader() throws IOException {
// do not write a header, but reset:
// this line added after another question
// showed a problem with the original
reset();
}
}
代码示例来源:origin: wildfly/wildfly
/** {@inheritDoc} */
public void clearInstanceCache() throws IOException {
oos.reset();
}
代码示例来源:origin: wildfly/wildfly
/** {@inheritDoc} */
public void clearClassCache() throws IOException {
oos.reset();
}
代码示例来源:origin: zendesk/maxwell
protected void resetOutputStreamCaches() throws IOException {
os.reset();
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
@Override
public void serialize(Serializable object) throws IOException {
oos.reset(); // clear (class) back-references
oos.writeObject(object);
}
代码示例来源:origin: stackoverflow.com
Object obj = ...; // Your object you want to write through the stream. (Needs to implement java.io.Serializable)
ObjectOutputStream oos = new ObjectOuptputStream(socket.getOutputStream());
oos.writeObject(oos);
oos.reset(); // (***)
// Don't close it! Otherwise the connection will be closed as well.
代码示例来源:origin: apache/activemq
public void marshal(Object command, DataOutput ds) throws IOException {
ObjectOutputStream out = new ObjectOutputStream((OutputStream)ds);
out.writeObject(command);
out.flush();
out.reset();
}
代码示例来源:origin: log4j/log4j
private
void sendCachedEvents(ObjectOutputStream stream) throws IOException {
if (buffer != null) {
for (int i = 0; i < buffer.length(); i++) {
stream.writeObject(buffer.get(i));
}
stream.flush();
stream.reset();
}
}
代码示例来源:origin: netty/netty
@Override
protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception {
ObjectOutputStream oos = newObjectOutputStream(new ByteBufOutputStream(out));
try {
if (resetInterval != 0) {
// Resetting will prevent OOM on the receiving side.
writtenObjects ++;
if (writtenObjects % resetInterval == 0) {
oos.reset();
}
}
oos.writeObject(msg);
oos.flush();
} finally {
oos.close();
}
}
}
代码示例来源:origin: btraceio/btrace
private void send(Command cmd) throws IOException {
if (oos == null) {
throw new IllegalStateException();
}
oos.reset();
WireIO.write(oos, cmd);
}
代码示例来源:origin: redisson/redisson
@Override
protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception {
ObjectOutputStream oos = newObjectOutputStream(new ByteBufOutputStream(out));
try {
if (resetInterval != 0) {
// Resetting will prevent OOM on the receiving side.
writtenObjects ++;
if (writtenObjects % resetInterval == 0) {
oos.reset();
}
}
oos.writeObject(msg);
oos.flush();
} finally {
oos.close();
}
}
}
代码示例来源:origin: wildfly/wildfly
@Override
protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception {
ObjectOutputStream oos = newObjectOutputStream(new ByteBufOutputStream(out));
try {
if (resetInterval != 0) {
// Resetting will prevent OOM on the receiving side.
writtenObjects ++;
if (writtenObjects % resetInterval == 0) {
oos.reset();
}
}
oos.writeObject(msg);
oos.flush();
} finally {
oos.close();
}
}
}
代码示例来源:origin: kiegroup/jbpm
public byte[] marshal(Context ctx, ObjectOutputStream objectOutputStream, Object o) throws IOException {
ByteArrayOutputStream buff = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(buff)) {
Documents documents = (Documents) o;
// Write the number of documents in the list.
oos.writeInt(documents.getDocuments().size());
for (Document nextDocument : documents.getDocuments()) {
// Use the DocumentMarshallingStrategy to marshal individual documents.
byte[] nextMarshalledDocument = docMarshallingStrategy.marshal(ctx, objectOutputStream, nextDocument);
oos.writeInt(nextMarshalledDocument.length);
oos.write(nextMarshalledDocument);
// Need to call reset on the stream in order for the Document bytes to be written correctly.
oos.reset();
}
}
return buff.toByteArray();
}
代码示例来源:origin: apache/activemq
@Override
public void storeContent() {
ByteSequence bodyAsBytes = getContent();
if (bodyAsBytes == null && object != null) {
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut;
ActiveMQConnection connection = getConnection();
if (connection != null && connection.isUseCompression()) {
compressed = true;
os = new DeflaterOutputStream(os);
}
DataOutputStream dataOut = new DataOutputStream(os);
ObjectOutputStream objOut = new ObjectOutputStream(dataOut);
objOut.writeObject(object);
objOut.flush();
objOut.reset();
objOut.close();
setContent(bytesOut.toByteSequence());
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage(), ioe);
}
}
}
代码示例来源:origin: log4j/log4j
oos.reset();
代码示例来源:origin: io.netty/netty
@Override
protected Object encode(ChannelHandlerContext context, Channel channel, Object msg) throws Exception {
ChannelBuffer buffer = buffer(context);
ObjectOutputStream oout = this.oout;
if (resetInterval != 0) {
// Resetting will prevent OOM on the receiving side.
writtenObjects ++;
if (writtenObjects % resetInterval == 0) {
oout.reset();
// Also discard the byproduct to avoid OOM on the sending side.
buffer.discardReadBytes();
}
}
oout.writeObject(msg);
oout.flush();
ChannelBuffer encoded = buffer.readBytes(buffer.readableBytes());
return encoded;
}
代码示例来源:origin: log4j/log4j
oos.reset();
代码示例来源:origin: btraceio/btrace
oos.reset();
} catch (SocketException e) {
isConnected = false;
代码示例来源:origin: pentaho/pentaho-kettle
data.objOut.reset();
data.objOut.flush();
代码示例来源:origin: apache/log4j
private
void sendCachedEvents(ObjectOutputStream stream) throws IOException {
if (buffer != null) {
for (int i = 0; i < buffer.length(); i++) {
stream.writeObject(buffer.get(i));
}
stream.flush();
stream.reset();
}
}
内容来源于网络,如有侵权,请联系作者删除!