Forums Register Login

reading multiple type of contents

+Pie Number of slices to send: Send
Hi ,
I have a situation where I am reading from a stream that contains some txt part (basically xml part) and then the later part of the stream may contain a jar file or a zip file or a binary file (.exe) or a .wav file. My method takes an InputStream as param and i am able to read the xml part by using a BufferedReader. But when i am trying to read the binary part by creating a BufferedInputStream from INputStream and calling read it is always returning -1. Also i want to read everything (.zip, .jzr znd .exe etc) as a byte array and later write it out... is it possible ? I mean do i need to use ZipInputStream in order to read a zip file in order to maintain data integrity ?
+Pie Number of slices to send: Send
How are you determining the end of the text part of the stream? I'd bet you are reading with the BufferedReader until EOF (i.e. readLine() == null). That's the end of the file/stream. You need some way to tell the end of the text data and the beginning of the binary data.
As for your other question, you can read/write zip files with any stream, you just can't use the zip-specific features (i.e. view or extract contents).
+Pie Number of slices to send: Send
No no, I don't think he is reading till EOF - he is reading some multipart mime type file with a mark, I guess.
But the problem with the Buffered Reader is, it reads buffered. (big surprise Therefore the underlying InputStreamReader is read wider, than to last 'readLine'-position.
As far as I know, you may not change the horses on the fly, switching from BufferedReader to ZipReader or something.
Closing the file, and rereading should work.
+Pie Number of slices to send: Send
I did this kind of thing in a Wiki Server. Web servers all do it to handle file uploads. Feel free to browse that code and see how MessageReader passes control to MimePartReader.
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 828 times.
Similar Threads
URGENT !!! How Do I download Image files using HTTP.
Reading from same InputStream twice
Auditing ZipInputStream
XPath problem
Huge file splitting?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:26:38.