[英]Read a serialized object as a stream
I have serialized a huge linked list (150mb) in this way: 我已经以这种方式序列化了一个巨大的链表(150mb):
public void serialize(ArrayList<LinkedList> e, String file){
try {
FileOutputStream fileOut =
new FileOutputStream("file+".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(e);
out.close();
fileOut.close();
}catch(IOException i)
{
i.printStackTrace();
}
}
Now, I would like to read it as a stream in a non blocking way, as opposite to the following approach: 现在,我想以一种非阻塞的方式将其作为流读取,这与以下方法相反:
public ArrayList deserialize(File file){
ArrayList<LinkedList> e = null;
try
{
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream in = new ObjectInputStream(fileIn);
e = (ArrayList<LinkedList>) in.readObject();
in.close();
fileIn.close();
return e;
}catch(IOException i)
{
i.printStackTrace();
return null;
}catch(ClassNotFoundException c)
{
System.out.println("Object not found");
c.printStackTrace();
return null;
}
}
Is it possible to use the partial deserialized data while the deserialization process is still running and not completed yet? 在反序列化过程仍在运行但尚未完成时,是否可以使用部分反序列化的数据?
You can't. 你不能 There is no such thing as non-blocking I/O to/from a file. 不存在与文件无阻塞的I / O之类的问题。 Your question doesn't make sense. 您的问题没有道理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.