本文整理了Java中java.io.ObjectInputStream.<init>()
方法的一些代码示例,展示了ObjectInputStream.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectInputStream.<init>()
方法的具体详情如下:
包路径:java.io.ObjectInputStream
类名称:ObjectInputStream
方法名:<init>
[英]Constructs a new ObjectInputStream. This default constructor can be used by subclasses that do not want to use the public constructor if it allocates unneeded data.
[中]构造一个新的ObjectInputStream。如果子类分配了不需要的数据,则不想使用公共构造函数的子类可以使用此默认构造函数。
代码示例来源: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
FileInputStream fis = context.openFileInput(fileName);
ObjectInputStream is = new ObjectInputStream(fis);
SimpleClass simpleClass = (SimpleClass) is.readObject();
is.close();
fis.close();
代码示例来源:origin: apache/storm
public static KerberosTicket deserializeKerberosTicket(byte[] tgtBytes) {
KerberosTicket ret;
try {
ByteArrayInputStream bin = new ByteArrayInputStream(tgtBytes);
ObjectInputStream in = new ObjectInputStream(bin);
ret = (KerberosTicket) in.readObject();
in.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
return ret;
}
代码示例来源:origin: guoguibing/librec
public static Object deserialize(String filePath) throws Exception {
FileInputStream fis = new FileInputStream(filePath);
ObjectInputStream ois = new ObjectInputStream(fis);
Object obj = ois.readObject();
ois.close();
fis.close();
return obj;
}
代码示例来源:origin: spotbugs/spotbugs
private static Bug1234 writeRead(final Bug1234 original) {
try {
final ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(fileName));
outputStream.writeObject(original);
outputStream.close();
final ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(fileName));
final Bug1234 result = (Bug1234)inputStream.readObject();
inputStream.close();
return result;
} catch (final Throwable e) {
throw new RuntimeException("Error: " + e);
}
}
代码示例来源:origin: stackoverflow.com
try {
FileInputStream e = new FileInputStream("outings.ser");
ObjectInputStream inputStream = new ObjectInputStream(e);
return (ArrayList)inputStream.readObject();
} catch (ClassNotFoundException | IOException var3) {
var3.printStackTrace();
}
return null;
代码示例来源:origin: spring-projects/spring-framework
/**
* Deserialize the byte array into an object.
* @param bytes a serialized object
* @return the result of deserializing the bytes
*/
@Nullable
public static Object deserialize(@Nullable byte[] bytes) {
if (bytes == null) {
return null;
}
try {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
return ois.readObject();
}
catch (IOException ex) {
throw new IllegalArgumentException("Failed to deserialize object", ex);
}
catch (ClassNotFoundException ex) {
throw new IllegalStateException("Failed to deserialize object type", ex);
}
}
代码示例来源:origin: stackoverflow.com
ByteArrayInputStream bis = new ByteArrayInputStream(yourBytes);
ObjectInput in = null;
try {
in = new ObjectInputStream(bis);
Object o = in.readObject();
...
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
// ignore close exception
}
}
代码示例来源:origin: apache/kafka
public static Object deserialize(InputStream inputStream) throws IOException, ClassNotFoundException {
try (ObjectInputStream objectInputStream = new ObjectInputStream(inputStream)) {
return objectInputStream.readObject();
}
}
代码示例来源: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: stackoverflow.com
FileInputStream fis = new FileInputStream("t.tmp");
ObjectInputStream ois = new ObjectInputStream(fis);
List<Club> clubs = (List<Club>) ois.readObject();
ois.close();
代码示例来源:origin: stackoverflow.com
Map map = new HashMap();
map.put("1",new Integer(1));
map.put("2",new Integer(2));
map.put("3",new Integer(3));
FileOutputStream fos = new FileOutputStream("map.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(map);
oos.close();
FileInputStream fis = new FileInputStream("map.ser");
ObjectInputStream ois = new ObjectInputStream(fis);
Map anotherMap = (Map) ois.readObject();
ois.close();
System.out.println(anotherMap);
代码示例来源:origin: quartz-scheduler/quartz
public static Object deserialize(byte[] bytes) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Object obj = ois.readObject();
ois.close();
return obj;
} catch (Exception e) {
throw new RuntimeException("error deserializing " + bytes, e);
}
}
代码示例来源:origin: hankcs/HanLP
public static <T> DoubleArrayTrie<T> unSerialize(String path)
{
ObjectInputStream in;
try
{
in = new ObjectInputStream(IOAdapter == null ? new FileInputStream(path) : IOAdapter.open(path));
return (DoubleArrayTrie<T>) in.readObject();
}
catch (Exception e)
{
// e.printStackTrace();
return null;
}
}
代码示例来源:origin: shuzheng/zheng
public static Session deserialize(String sessionStr) {
if (StringUtils.isBlank(sessionStr)) {
return null;
}
try {
ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(sessionStr));
ObjectInputStream ois = new ObjectInputStream(bis);
return (Session) ois.readObject();
} catch (Exception e) {
throw new RuntimeException("deserialize session error", e);
}
}
代码示例来源:origin: hankcs/HanLP
private static boolean loadBin(String path)
{
try
{
ObjectInputStream in = new ObjectInputStream(IOUtil.newInputStream(path));
CONVERT = (char[]) in.readObject();
in.close();
}
catch (Exception e)
{
logger.warning("字符正规化表缓存加载失败,原因如下:" + e);
return false;
}
return true;
}
代码示例来源: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: stanfordnlp/CoreNLP
public static <T> ClassicCounter<T> deserializeCounter(String filename) throws Exception {
// reconstitute
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(filename)));
ClassicCounter<T> c = ErasureUtils.uncheckedCast(in.readObject());
in.close();
return c;
}
代码示例来源:origin: stackoverflow.com
public static void main(String args[]) throws Exception {
NameStore nameStore = new NameStore("Steve", "Middle","Jobs");
ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("nameStore"));
o.writeObject(nameStore);
o.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream("nameStore"));
NameStore nameStore1 = (NameStore)in.readObject();
System.out.println(nameStore1);
代码示例来源:origin: quartz-scheduler/quartz
public static Object deserialize(byte[] bytes) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Object obj = ois.readObject();
ois.close();
return obj;
} catch (Exception e) {
throw new RuntimeException("error deserializing " + bytes, e);
}
}
内容来源于网络,如有侵权,请联系作者删除!