📄 serializationtester.java
字号:
/* * @(#)SerializationTester.java 1.4 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package java.awt.dnd;import java.io.OutputStream;import java.io.ObjectOutputStream;import java.io.IOException;import java.io.Serializable;/** * Tests if an object can truly be serialized by serializing it to a null * OutputStream. * * @version 1.4, 01/23/03 * @since 1.4 */final class SerializationTester { private static ObjectOutputStream stream; static { try { stream = new ObjectOutputStream(new OutputStream() { public void write(int b) {} }); } catch (IOException cannotHappen) { } } static boolean test(Object obj) { if (!(obj instanceof Serializable)) { return false; } try { stream.writeObject(obj); } catch (IOException e) { return false; } finally { // Fix for 4503661. // Reset the stream so that it doesn't keep a reference to the // written object. try { stream.reset(); } catch (IOException e) { // Ignore the exception. } } return true; } private SerializationTester() {}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -