本文整理了Java中java.io.ObjectOutputStream.<init>()
方法的一些代码示例,展示了ObjectOutputStream.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectOutputStream.<init>()
方法的具体详情如下:
包路径:java.io.ObjectOutputStream
类名称:ObjectOutputStream
方法名:<init>
[英]Constructs a new ObjectOutputStream. This default constructor can be used by subclasses that do not want to use the public constructor if it allocates unneeded data.
[中]构造一个新的ObjectOutputStream。如果子类分配了不需要的数据,则不想使用公共构造函数的子类可以使用此默认构造函数。
代码示例来源:origin: google/guava
/** Serializes and deserializes the specified object. */
@SuppressWarnings("unchecked")
static <T> T reserialize(T object) {
checkNotNull(object);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try {
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(object);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
return (T) in.readObject();
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: stackoverflow.com
FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(this);
os.close();
fos.close();
代码示例来源:origin: redisson/redisson
protected byte[] toByteArray(Object value) throws IOException {
if (value == null) {
return null;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(value);
out.flush();
return bos.toByteArray();
}
代码示例来源:origin: spring-projects/spring-framework
public static void testSerialization(Object o) throws IOException {
OutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(o);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Writes the source object to an output stream using Java serialization.
* The source object must implement {@link Serializable}.
* @see ObjectOutputStream#writeObject(Object)
*/
@Override
public void serialize(Object object, OutputStream outputStream) throws IOException {
if (!(object instanceof Serializable)) {
throw new IllegalArgumentException(getClass().getSimpleName() + " requires a Serializable payload " +
"but received an object of type [" + object.getClass().getName() + "]");
}
ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
objectOutputStream.writeObject(object);
objectOutputStream.flush();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Serialize the given RemoteInvocation to the given OutputStream.
* <p>The default implementation gives {@code decorateOutputStream} a chance
* to decorate the stream first (for example, for custom encryption or compression).
* Creates an {@code ObjectOutputStream} for the final stream and calls
* {@code doWriteRemoteInvocation} to actually write the object.
* <p>Can be overridden for custom serialization of the invocation.
* @param invocation the RemoteInvocation object
* @param os the OutputStream to write to
* @throws IOException if thrown by I/O methods
* @see #decorateOutputStream
* @see #doWriteRemoteInvocation
*/
protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(decorateOutputStream(os));
try {
doWriteRemoteInvocation(invocation, oos);
}
finally {
oos.close();
}
}
代码示例来源:origin: google/guava
@SuppressWarnings("unchecked")
static <T> T reserialize(T object) {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(object);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
return (T) in.readObject();
} catch (IOException | ClassNotFoundException e) {
Helpers.fail(e, e.getMessage());
}
throw new AssertionError("not reachable");
}
代码示例来源:origin: redisson/redisson
protected byte[] toByteArray(Object value) throws IOException {
if (value == null) {
return null;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(value);
out.flush();
return bos.toByteArray();
}
代码示例来源:origin: junit-team/junit4
private void save() throws IOException {
ObjectOutputStream stream = null;
try {
stream = new ObjectOutputStream(new FileOutputStream(fHistoryStore));
stream.writeObject(this);
} finally {
if (stream != null) {
stream.close();
}
}
}
代码示例来源:origin: stackoverflow.com
public static byte[] serialize(Object obj) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(out);
os.writeObject(obj);
return out.toByteArray();
}
public static Object deserialize(byte[] data) throws IOException, ClassNotFoundException {
ByteArrayInputStream in = new ByteArrayInputStream(data);
ObjectInputStream is = new ObjectInputStream(in);
return is.readObject();
}
代码示例来源:origin: redisson/redisson
protected byte[] toByteArray(Object value) throws IOException {
if (value == null) {
return null;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(value);
out.flush();
return bos.toByteArray();
}
代码示例来源:origin: google/j2objc
private void save() throws IOException {
ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(
fHistoryStore));
stream.writeObject(this);
stream.close();
}
代码示例来源:origin: gocd/gocd
public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
out.writeObject(o);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
return in.readObject();
}
代码示例来源:origin: redisson/redisson
protected byte[] toByteArray(Object value) throws IOException {
if (value == null) {
return null;
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(value);
out.flush();
return bos.toByteArray();
}
代码示例来源:origin: stanfordnlp/CoreNLP
public static <T> void serializeCounter(Counter<T> c, String filename) throws IOException {
// serialize to file
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
out.writeObject(c);
out.close();
}
代码示例来源:origin: TeamNewPipe/NewPipe
@NonNull
private <T extends Serializable> T clone(@NonNull T item,
@NonNull final Class<T> type) throws Exception {
final ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream();
try (final ObjectOutputStream objectOutput = new ObjectOutputStream(bytesOutput)) {
objectOutput.writeObject(item);
objectOutput.flush();
}
final Object clone = new ObjectInputStream(
new ByteArrayInputStream(bytesOutput.toByteArray())).readObject();
return type.cast(clone);
}
代码示例来源:origin: apache/flink
public static byte[] serializeObject(Object o) throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(o);
oos.flush();
return baos.toByteArray();
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public void save(String path) throws IOException {
// save the CRF
this.classifier.serializeClassifier(path);
// save the additional arguments
FileOutputStream fos = new FileOutputStream(path + ".extra");
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(this.gazetteerLocation);
out.writeObject(this.annotationsToSkip);
out.writeObject(this.useSubTypes);
out.writeObject(this.useBIO);
out.close();
}
代码示例来源:origin: spotbugs/spotbugs
static public void main(String args[]) throws Exception {
ByteArrayOutputStream pout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(pout);
oout.writeObject(new ExternalizableTest(42));
oout.close();
byte b[] = pout.toByteArray();
ByteArrayInputStream pin = new ByteArrayInputStream(b);
ObjectInputStream oin = new ObjectInputStream(pin);
Object o = oin.readObject();
System.out.println("read object");
System.out.println(o);
}
代码示例来源:origin: apache/flink
public static byte[] serializeObject(Object o) throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(o);
oos.flush();
return baos.toByteArray();
}
}
内容来源于网络,如有侵权,请联系作者删除!