Aalto
Aalto

Reputation: 99

Read a serialized object as a stream

I have serialized a huge linked list (150mb) in this way:

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?

Upvotes: 1

Views: 92

Answers (1)

user207421
user207421

Reputation: 310869

You can't. There is no such thing as non-blocking I/O to/from a file. Your question doesn't make sense.

Upvotes: 2

Related Questions