java - If I keep an objects of InputStream into the memory then does it mean I am storing the whole file into the memory? -
i have class sample has 2 constructor. 1 takes object of file whereas takes inputstream.
package org.xyz.core; import java.io.file; import java.io.inputstream; /** * created ashish pancholi on 26-03-2016. */ public class sample { file file; public sample(file file){ this.file=file; } public sample(inputstream inputstream){ this.file = createfilefrominputstream(inputstream); } } and using linkedblockingqueue consumes object of sample , has depth of 10000;
blockingqueue<string> queue = new linkedblockingqueue<sample>(10000); let's assume 2 cases here:
case a: initialize many instances of sample class passing inputstream arguments , pushed these objects linkedblockingqueue.
case b: initialize many instances of sample class passing file object arguments , pushed these objects linkedblockingqueue.
in case program take more memory? if keep objects of inputstream memory mean storing whole file memory? if have many large files?
updated:
please note: creating inputstream way:
inputstream = new tararchiveinputstream(new gzipinputstream(new bufferedinputstream(new fileinputstream(file))));
it depends.
an inputstream can buffered or non-buffered, store entire file internally or nothing, it's free of that. there may native resources associated them.
there more fundamental problem pattern though: inputstreams make sense part of process reads them. storing them en masse bad idea because:
- they aren't thread-safe. (multiple threads reading
inputstreamend in tears.) - if we're talking
fileinputstreams, keep file open , may run out of file descriptors.
Comments
Post a Comment