2

I'm trying to set inflater.Position by calling the code below:

    Stream data = Compress(buffer);  // data: length=12, position=12
    //inflater: length=0, position=12
    InflaterInputStream inflater = new InflaterInputStream(data);   
    inflater.IsStreamOwner = false;

    // move forward:
    inflater.Dispose();
    data.Position = 0;  
    inflater = new InflaterInputStream(data);     // inflater.position=0
    inflater.IsStreamOwner = false;
    byte[] buff = new byte[newPos - Position];
    while(newPos > Position)
         int count = inflater.Read(buff, 0, buff.Length);  //inflater.position=12

Right now, when I try to move forward, the Position always stays at its original value. Is it because whatever length I put in Read method, the method always reads the entire stream, thus position = end of stream? How may I set inflater.Position?

Follow up: Why is inflater has a length of 0? Does it have anything to do with CanWrite property being false?

user1486691
  • 267
  • 5
  • 18
  • I'm actually shocked you didn't get a `NotSupportedException` ("InflaterInputStream Position not supported") exception. It is not intended to be setable. – Jesse C. Slicer Jul 10 '12 at 14:24
  • I developed a MovePosition method for the setter. – user1486691 Jul 10 '12 at 14:28
  • My guess then: that's where your bug is. – Jesse C. Slicer Jul 10 '12 at 14:28
  • I'm confused then. Is the code above the actual `MovePosition` method called from the `InflaterInputStream.Position` property setter? Are you modifying the `InflaterInputStream` source directly or is it some subclass you've created? – Jesse C. Slicer Jul 10 '12 at 14:40
  • Yes, the code above is called by the setter. I created a new class and this Position property overrides. Sorry for the confusion. – user1486691 Jul 10 '12 at 14:46
  • Ok, then how do you set the position variable tracked by the superclass (returned by the getter) here? I'm betting it's `private` and not being set at all. – Jesse C. Slicer Jul 10 '12 at 14:48
  • Right, but `Stream` doesn't actually implement those; they're abstract: http://msdn.microsoft.com/en-us/library/system.io.stream.position.aspx . **You**, as a subclasser, must provide an implementation. – Jesse C. Slicer Jul 10 '12 at 15:07
  • position does change through the code, if that's what you meant. it's set to 0 and then goes back to the end of stream – user1486691 Jul 10 '12 at 15:36
  • Do you have any idea why inflater has a 0 length? – user1486691 Jul 10 '12 at 15:39
  • Fraid I don't know, sorry. Doesn't look to be the case, perusing the source here: http://web-tools.googlecode.com/svn-history/r6/documentation/_inflater_input_stream_8cs-source.html – Jesse C. Slicer Jul 10 '12 at 15:47

0 Answers0