• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

reading multiple type of contents

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic