classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Some object serialization problems for discussion(3)-ObjectInputS tream


From: Wu, Gansha
Subject: Some object serialization problems for discussion(3)-ObjectInputS tream
Date: Thu, 2 Aug 2001 09:26:15 +0800

Object serialization problems about ObjectInputStream, part 1:

  Consider read (...) here:

  public int read (byte data[], int offset, int length) throws IOException
  {
    if (this.readDataFromBlock)
    {
-      if (this.blockDataPosition + length >= this.blockDataBytes){
+     if (this.blockDataPosition + length > this.blockDataBytes){  <- Comment 1
?       int remain = this.blockDataBytes - this.blockDataPosition;
?       if(remain != 0){
?           System.arraycopy (this.blockData, this.blockDataPosition,
?                       data, offset, remain);
?           offset += remain;
?           length -= remain;          <- Comment 2
        }
        readNextBlock ();
      }

      System.arraycopy (this.blockData, this.blockDataPosition,
                        data, offset, length);
+    this.blockDataPosition += length;  <- Comment 3
      return length;            
    }
    else
      return this.realInputStream.read (data, offset, length);
  }

Comment 1:
      when "this.blockDataPosition + length == this.blockDataBytes", that means 
the data 
in block is just enough for read, readNextBlock() shouldn't be invoked, 
otherwise it will 
read more unmeaningful data into block which might be object data that must be 
read 
by realInputStream. So we should use ">" instead of ">=" here. In fact 
according to 
implementation, the following is also ok here:
      if (this.blockDataPosition == this.blockDataBytes){ ... ...

Comment 2:
      This patch(beginning with '?' needn't be added actually, because 
implementation here 
won't lead to such a scenario (a read will across two blocks), but in general 
it seems necessary.

Comment 3:
      When data in block is read here, blockDataPosition pointer should be 
updated.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]