Hi everyone,
I'm working on JDev11g U2 with ADFRC
I'm using af:inputFile to upload read my file. for that i'm getting my Files InputStream on af:inputFile's valueChangeListener.
Now for the first time when i click a button to read content from this IS then it is working very well. button as i press the same button again without changing my file from af:InputFile, I'm getting InputStream as null, coz it closes itself at EOF.
Now problem is I can't reopen it, or can't make a clone, or can't use mark(int) with this..
So i used a wrapper method from apache's POI POIFSFileSystem.createNonClosingInputStream(InputStream is) to wrap my IS.
according to them it should realy solve my problem but it is not working...
InputStream wrappedStream = POIFSFileSystem.createNonClosingInputStream(is); <-------- IS read here
HSSFWorkbook wb = new HSSFWorkbook(wrappedStream);
is.reset(); <-------- getting null here as i already read above
doSomethingElse(is);
now tell me how can i implement this code too. once i read my IS, it becomes null. so how can i reset it.
Second way i did that i convert my IS as String so that i can carry it for any no. of use. coz i'm using my IS to covert my file From XML, CSV, XLS to XML
using this method-
public static String convertInputStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
return sb.toString();
}
so in case of CSV and XML it is working way, but in case of XLS , I'm not getting anything from this coverted String.
I'm using this method to get my IS back from String -
for XML -
InputStream useIS =
new ByteArrayInputStream(inputStream.getBytes("UTF-8"));
for CSV - (inputStream is String of my IS)
BufferedReader csvReader;
csvReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(inputStream.getBytes("UTF-8"))));
for XLS -
POIFSFileSystem myFileSystem =
new POIFSFileSystem(new ByteArrayInputStream(inputStream.getBytes("UTF-8")));
//InputStream inStr = new ByteArrayInputStream(inputStream.getBytes("UTF-8"));
HSSFWorkbook workbook = new HSSFWorkbook(myFileSystem);
Now can anybody help me to find out the right way to use my IS again and again.
Thanks
Fizzz...