• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 266
  • Last Modified:

InputStream & StreamTokenizer problem

I have a ZipInputStream that contains a text header and then some binary image data. First I create a StreamTokenizer and then I read the text header. Everything works great so far. The problems begin when I reach the binary data. All I get when I try to read from the input stream again is zeroes. I don't think the problem has to do with the binary data, I tried to read some text at the end of the header from the input stream which also gave only zeroes. Is it not possible to read from the input stream after creating a Tokenizer from it?
0
labatti
Asked:
labatti
  • 4
  • 3
  • 2
1 Solution
 
labattiAuthor Commented:
Oh, I forgot... It's JDK 1.2.2 on WinNT
0
 
heyhey_Commented:
post your code.
note that it if you wrap some InputStream in some other (Data)InputStream, it is not safe to read from the underlying Stream, because the wrapper probably contains cached information.
0
 
sgomsCommented:
post ur code.
How do u tokenize the stream?
-sgoms
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
labattiAuthor Commented:
Hmm, I *have* wraped the InputStream. What if I set the wrapers to null when I'm done with them?

/labatti

InputStream is = new GZIPInputStream(url.openConnection().getInputStream());

InputStreamReader isr = new InputStreamReader(is);
Reader r = new BufferedReader(isr);

StreamTokenizer tokenizer = new StreamTokenizer(r);
tokenizer.nextToken();

// A lot of text is read here
//  |
//  |
// End of reading text
 
// Here I'd like to read binary data from the
// input stream again.

byte[] b = new byte[sizeOfImage];
is.read(b);

0
 
heyhey_Commented:
>> What if I set the wrapers to null when I'm done with them?


won't work.
StreamTokenizer reads and caches some of the information ...
you'd better read only from the InputStream and parse everything yourself.
0
 
sgomsCommented:
heyhey is right.
parse the text urself.
-sgoms
0
 
labattiAuthor Commented:
Ok, thanks!

/labatti
0
 
heyhey_Commented:
so - answer ?
0
 
labattiAuthor Commented:
=)
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now