• Post Reply Bookmark Topic Watch Topic
  • New Topic

reading multiple type of contents  RSS feed

 
Mandy Mandy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!