Code example for ObjectInput

Methods: read, readInt, readObject

0
   * int - length of body 
   * byte array - body, of previously specified length 
   */ 
  @SuppressWarnings("unchecked") 
  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    httpStatusCode = in.readInt();
    Map<String, List<String>> headerCopy = (Map<String, List<String>>)in.readObject();
    int bodyLength = in.readInt();
    responseBytes = new byte[bodyLength];
    in.read(responseBytes, 0, bodyLength);
 
    date = getAndUpdateDate(headerCopy);
    encoding = getAndUpdateEncoding(headerCopy, responseBytes);
    headers = Collections.unmodifiableMap(headerCopy);
    metadata = Collections.emptyMap();
  } 
 
  public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(httpStatusCode);
    out.writeObject(headers);
    out.writeInt(responseBytes.length);