0

I can't understand if doing what is said in the title with the streams, if I use the object stream to write an object to a file, does it shift the filestream's pointer and when I use it, after, to write something, it writes it after the aforementioned object? And the same for input streams

Thanks a lot

radai
  • 23,949
  • 10
  • 71
  • 115
besnico
  • 253
  • 2
  • 4
  • 13

1 Answers1

1

yes, when wrapping streams (called the decorator pattern, by the way) writing to the outer-most stream (actually a shell) will propagate the write down the chain.

an important thing to note here is that various Stream objects along the chain might have their own buffers so the write wont immediately go down the pipe. good examples of this are buffered output streams and zip output streams.

if you intend to write something to a wrapping stream and then write something directly to one of the streams deeper down the chain the recommended thing to do is call flush() on the outer-most stream to make sure any buffers in the chain will be flushed out - else you risk writing bits out of order.

radai
  • 23,949
  • 10
  • 71
  • 115
  • Thank you so much man, you're a superstar, this solves a lot of issues and retireves the need for offsets in what I'm working on, very quick response btw! Awesome! – besnico Apr 14 '13 at 12:01