I have a class Sample which has two constructor. One takes an object of File whereas another takes an InputStream.
package org.xyz.core;
import java.io.File;
import java.io.InputStream;
/**
* Created by 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 I am using LinkedBlockingQueue that consumes an object of Sample and has depth of 10000;
BlockingQueue<String> queue = new LinkedBlockingQueue<Sample>(10000);
Let's assume two cases here:
Case A: I initialize so many instances of Sample class by passing InputStream as an arguments and I pushed all these objects into the LinkedBlockingQueue.
Case B: I initialize so many instances of Sample class by passing File object as an arguments and I pushed all these objects into the LinkedBlockingQueue.
In which case my program will take more memory? If I keep an objects of InputStream into the memory then does it mean I am storing the whole file into the memory? What if I have so many large files?
Updated:
Please Note: I am creating the InputStream by this way:
InputStream is = new TarArchiveInputStream(new GZIPInputStream(new BufferedInputStream(new FileInputStream(file))));