简体   繁体   English

读取序列化对象作为流

[英]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.

相关问题 Java:读取序列化对象的最佳方法是什么? - Java: What is the best way to read a Serialized object? Java-是否可以在不强制转换的情况下读取序列化对象? - Java - Is it possible to read a serialized object without casting? ObjectStream:有没有办法将序列化对象作为属性映射读取? - ObjectStream: is there a way to read serialized object as properties map? 有没有办法检测传入的序列化对象流是压缩的GZIPOutputStream还是简单的ObjectOutputStream? - Is there a way to detect if an incoming serialized object stream is GZIPOutputStream compressed or a simple ObjectOutputStream? 在对象序列化流上发送具有不同字段的相同对象 - Sending the same objects with different fields over an object serialized stream 试图读取我没有创建的序列化 Java 对象 - Trying to read a serialized Java object that I did not create 从磁盘读取序列化的Java对象,使用较新的类? - Read serialized java object from disk with newer class? 如何读取Java中序列化对象的大小(以字节为单位)? - How can I read the size in bytes of a serialized object in Java? 从更改的类读取序列化对象的Java兼容性 - Java compatibility for serialized object read from changed class 我们可以在linux机器上读取.NET中序列化的对象吗? - Can we read an object serialized in .NET in a linux machine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM