/*
(non-Javadoc)

@see java.util.io.Externalizable.readExternal(java.io.ObjectInput)
323004
public void readExternal(java.io.ObjectInput objectInput
                    )
                                    throws java.io.IOException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass
                        , "readExternal"
                        , "objectInput=" + objectInput + "(java.io.ObjectInput)"
                            );

        byte version = objectInput.readByte();
        if (Tracing.isAnyTracingEnabled() && trace.isDebugEnabled())
            trace.debug(cclass,
                        "readExternal",
                        "version=" + version + "(byte)");

        objectStoreIdentifier = objectInput.readInt();
        storedObjectIdentifier = objectInput.readLong();

        // Re-establish the objectStore storing the ManagedObject.
        try {
            objectStore = ((ManagedObjectInputStream) objectInput).objectManagerState.getObjectStore(objectStoreIdentifier);

        } catch (ObjectManagerException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, "readExternal", exception, "1:488:1.14");
            java.io.IOException ioException = new java.io.IOException();

            // We cannot always invoke initCause, because JCLRM does not support this. 
            // ioException.initCause(exception);
            try {
                java.lang.reflect.Method initCauseMethod = Throwable.class.getMethod("initCause",
                                                                                     new Class[] { Throwable.class });
                initCauseMethod.invoke(this,
                                       new Object[] { exception });
            } catch (Exception exception2) {
                // No FFDC Code Needed.
                if (Tracing.isAnyTracingEnabled() && trace.isEventEnabled())
                    trace.event(this,
                                cclass,
                                "readExternal",
                                exception2);
            }

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this, cclass
                           , "readExternal"
                           , new Object[] { exception, new Integer(objectStoreIdentifier) }
                                );
            throw ioException;
        } // catch (ObjectManagerException exception).

        // ManagedObjectInputStream resolves the Token constructed into the definitive token.

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass
                       , "readExternal"
                            );
    }
466762
public void readExternal(ObjectInput in) throws IOException,
			ClassNotFoundException {
		if(logger.isDebugEnabled()) {
            logger.debug("readExternal");
        }

		super.readExternal(in);
		String messageString = in.readUTF();
		try {
			message = SipFactoryImpl.messageFactory.createRequest(messageString);
		} catch (ParseException e) {
			throw new IllegalArgumentException("Message " + messageString + " previously serialized could not be reparsed", e);
		}
		boolean isLinkedRequestSerialized = in.readBoolean();
		if (isLinkedRequestSerialized) {
			linkedRequest = (SipServletRequestImpl) in.readObject();
		}
		createDialog = in.readBoolean();
		String routingDirectiveString = in.readUTF();
		if(!routingDirectiveString.equals("")) {
			routingDirective = SipApplicationRoutingDirective.valueOf(routingDirectiveString);
		}
		String routingStateString = in.readUTF();
		if(!routingStateString.equals("")) {
			routingState = RoutingState.valueOf(routingStateString);
		}
		boolean isRoutingRegionSet = in.readBoolean();
		if(isRoutingRegionSet) {
			routingRegion = (SipApplicationRoutingRegion) in.readObject();
		}
		isInitial = in.readBoolean();
		if(logger.isDebugEnabled()) {
            logger.debug("readExternal - isInitial=" + isInitial);
        }
		isFinalResponseGenerated = in.readBoolean();
		is1xxResponseGenerated = in.readBoolean();
	}
411976
@Override
    public void writeExternal(ObjectOutput output) throws IOException {
        output.writeInt(SERIALIZATION_V2);
        output.writeInt(this.storage.size());
        output.writeInt(this.numberOfHeaders);
        int count = 0;
        HeaderElement elem = this.hdrSequence;
        while (null != elem) {
            if (!elem.wasRemoved()) {
                count++;
                writeByteArray(output, elem.getKey().getByteArray());
                writeByteArray(output, elem.asBytes());
            }
            elem = elem.nextSequence;
        }
        // double check the counter value
        if (count != this.numberOfHeaders) {
            throw new IOException("Expected " + this.numberOfHeaders
                                  + " headers but wrote " + count);
        }
    }
899169
public synchronized int read(byte[] externalBuf, int off, int len) throws IOException {

    if (len == 0) {
      return 0;
    }

    int totalReads = 0;
    while (true) {

      //read
      if (end - pos <= 0) {
        if (len - totalReads >= buf.length) {
          //buffer length is less than asked byte and buffer is empty
          // => filling directly into external buffer
          int reads = super.read(externalBuf, off + totalReads, len - totalReads);
          if (reads <= 0) {
            return (totalReads == 0) ? -1 : totalReads;
          }
          return totalReads + reads;

        } else {

          //filling internal buffer
          fillBuffer(len - totalReads);
          if (end <= 0) {
            return (totalReads == 0) ? -1 : totalReads;
          }
        }
      }

      //copy internal value to buffer.
      int copyLength = Math.min(len - totalReads, end - pos);
      System.arraycopy(buf, pos, externalBuf, off + totalReads, copyLength);
      pos += copyLength;
      totalReads += copyLength;

      if (totalReads >= len || super.available() <= 0) {
        return totalReads;
      }
    }
  }
324640
@Override
    public void readExternal(PofReader reader)
            throws IOException {
        name = reader.readString(0);
        mutator = reader.readBoolean(1);
        args = reader.readObjectArray(2, new Object[0]);
    }
150888
@Override
  public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(id);
    mbr.writeExternal(out);
  }
969947
@SuppressWarnings("unchecked")
    void read(ObjectInputStream in) throws ClassNotFoundException, IOException {
        GetField fields = in.readFields();

        internalPropNames = (Set<String>) fields.get(INTERNAL_PROP_NAMES, null);

        byte[] bytes = (byte[]) fields.get(OBJECT, null);

        // TODO: for internal usage, find a way to supply the class loader of the bundle that creates the contextual object?

        DeserializationObjectInputStream doin = new DeserializationObjectInputStream(
                        new ByteArrayInputStream(bytes),
                        AccessController.doPrivileged(getThreadContextClassLoader));
        object = (T) doin.readObject();
        doin.close();

        Map<String, String> execProps = (Map<String, String>) fields.get(EXEC_PROPS, null);

        bytes = (byte[]) fields.get(CONTEXT, null);
        threadContextDescriptor = (ThreadContextDescriptorImpl) ThreadContextDeserializer.deserialize(bytes, execProps);
    }
1111583
public static java.lang.reflect.Field read(ObjectInput in)
            throws ClassNotFoundException, NoSuchFieldException, IOException {
        Class cl;
        String name;

        cl = ClassRef.read(in);
        if (cl == null) {
            return null;
        } else {
            name = in.readUTF();
            return cl.getDeclaredField(name);
        }
    }
432912
public void writeExternal(ObjectOutput out) throws IOException
   {
      out.writeInt(eventType);

      byte[] buff = sessionId.getBytes(Constants.DEFAULT_ENCODING);
      out.writeInt(buff.length);
      out.write(buff);

      int listSize = items.size();
      out.writeInt(listSize);
      for (int i = 0; i < listSize; i++)
      {
         out.writeObject(items.get(i));
      }

      if (pairId != null)
      {
         out.writeInt(NOT_NULL_VALUE);
         buff = pairId.getBytes(Constants.DEFAULT_ENCODING);
         out.writeInt(buff.length);
         out.write(buff);
      }
      else
      {
         out.writeInt(NULL_VALUE);
      }
   }
520658
@Override
    public void writeExternal(ObjectOutput s) throws IOException {
        if (!removedFromLeakDetection) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(tc,
                         "Buffer being serialized but removeFromLeakDetection has not been called: " + this);
            }
        }

        if (oByteBuffer.isDirect()) {
            // hard code as local strings to help performance.
            // Strings are used here and and in the readObject routines
            s.writeObject("D");
        } else {
            s.writeObject("ND");
        }
        if (oByteBuffer.order() == java.nio.ByteOrder.BIG_ENDIAN) {
            s.writeObject("B");
        } else {
            s.writeObject("L");
        }

        int startPosition = oByteBuffer.position();
        int startLimit = oByteBuffer.limit();

        // set position to 0 and limit to capacity, so we can serialize
        // the entire buffer
        this.oByteBuffer.position(0);
        this.oByteBuffer.limit(this.oByteBuffer.capacity());

        if (oByteBuffer.hasArray() && oByteBuffer.arrayOffset() == 0) {
            s.writeObject(oByteBuffer.array());
        } else {
            byte[] bytes = new byte[oByteBuffer.limit()];
            this.oByteBuffer.get(bytes);
            s.writeObject(bytes);
        }

        this.oByteBuffer.position(startPosition);
        this.oByteBuffer.limit(startLimit);

        s.writeObject(Integer.toString(startPosition));
        s.writeObject(Integer.toString(startLimit));

        if (this.readOnly) {
            s.writeObject("R");
        } else {
            s.writeObject("RW");
        }
    }
1011335
@Override public void readExternal( ObjectInput ois )  throws IOException, ClassNotFoundException {
    int x = ois.readInt();
    byte[] buf = MemoryManager.malloc1(x);
    ois.readFully(buf);
    read(new AutoBuffer(buf));
  }
889511
public void readExternal(PofReader reader) throws IOException {
        super.readExternal(reader);
        language = reader.readString(10);
        init();
    }
645431
public void decode(AsnInputStream ais) throws AsnException {
		
		this.oid = false;
		this.integer = false;
		this.objDescriptor = false;
		this.oidValue = null;
		this.indirectReference = 0;
		this.objDescriptorValue = null;
		this.asn = false;
		this.octet = false;
		this.arbitrary = false;
		this.data = null;
		this.bitDataString = null;
		
		try {

			// The definition of EXTERNAL is
			//			
			// EXTERNAL ::= [UNIVERSAL 8] IMPLICIT SEQUENCE {
			// direct-reference OBJECT IDENTIFIER OPTIONAL,
			// indirect-reference INTEGER OPTIONAL,
			// data-value-descriptor ObjectDescriptor OPTIONAL,
			// encoding CHOICE {
			// single-ASN1-type [0] ANY,
			// octet-aligned [1] IMPLICIT OCTET STRING,
			// arbitrary [2] IMPLICIT BIT STRING }}
			//
			//			

			AsnInputStream localAsnIS = ais.readSequenceStream();
			
			while( true ) {
				if (localAsnIS.available() == 0)
					break;
				
				int tag = localAsnIS.readTag();
				if (localAsnIS.getTagClass() == Tag.CLASS_UNIVERSAL) {
					switch(tag) {
					case Tag.INTEGER:
						this.indirectReference = localAsnIS.readInteger();
						this.setInteger(true);
						break;
						
					case Tag.OBJECT_IDENTIFIER:
						this.oidValue = localAsnIS.readObjectIdentifier();
						this.setOid(true);
						break;
						
					case Tag.OBJECT_DESCRIPTOR:
						this.objDescriptorValue = localAsnIS.readGraphicString();
						this.setObjDescriptor(true);
						break;
						
					default:
						throw new AsnException("Error while decoding External: Unrecognized tag value=" + tag + ", tagClass=" + localAsnIS.getTagClass());
					}
				} else if (localAsnIS.getTagClass() == Tag.CLASS_CONTEXT_SPECIFIC) {
					
					switch(tag) {
					case External._TAG_ASN:
						this.data = localAsnIS.readSequence();
						this.setAsn(true);
						break;
						
					case External._TAG_OCTET_ALIGNED:
						this.setEncodeType(localAsnIS.readOctetString());
						setOctet(true);
						break;
						
					case External._TAG_ARBITRARY:
						this.setEncodeBitStringType(localAsnIS.readBitString());
						setArbitrary(true);
						break;
						
					default:
						throw new AsnException("Error while decoding External: Unrecognized tag value=" + tag + ", tagClass=" + localAsnIS.getTagClass());
					}

					// check: this field  must be the last
					if (localAsnIS.available() != 0)
						throw new AsnException("Error while decoding External: data field must be the last");

				} else {
					throw new AsnException("Error while decoding External: Unrecognized tag value=" + tag + ", tagClass=" + localAsnIS.getTagClass());
				}
			}
		} catch (IOException e) {
			throw new AsnException("IOException while decoding External: " + e.getMessage(), e);
		}
	}
805404
public void readExternal(ObjectInput in)
                    throws IOException, ClassNotFoundException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "readExternal");

        try {
            // read magic
            short magic = in.readShort();
            short majorVersion = in.readShort();
            short minorVersion = in.readShort();

            if (!(magic == EXTERNAL_MAGIC)) {

                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc,
                             "Magic Number absent, trying default Java deserialization");
                throw new IOException("Bean ID externalized stream format error");

            } else if (!(majorVersion == MAJOR_VERSION) ||
                       !(minorVersion == MINOR_VERSION)) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    Tr.debug(tc,
                             "BeanID Version mismatch", new Object[] { new Short(majorVersion),
                                                                      new Short(minorVersion) });
                throw new IOException("BeanID version mismatch");
            }

            // read the interface type (HOME or REMOTE)
            byte ifType = in.readByte();
            if (ifType == IF_HOME) {
                _isHome = true;
            } else {
                _isHome = false;
            }

            //89554
            // read the bean name
            byte[] j2eeNameBytes = readExternalJ2EEName(in);

            // read the serialized primary key
            pkey = readExternalPKey(in, j2eeNameBytes);

            // TAKE CARE! We don't have a container reference so can't
            // restore transient fields.
            // This is ok as long
            // as rest of container restores BeanIds using the deserialise
            // method. Since readExternal
            // is a new addition
            // this can be no different to the behaviour that would have been
            // observed when using
            // the default serialization.

        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(tc, "readExternal");
        }
    }
701045
@Override
    public void readExternal(ObjectInput in)
        throws IOException {

        byte header = in.readByte();

        switch (header) {
            case BAHAI:
                this.obj = this.readBahai(in);
                break;
            default:
                throw new InvalidObjectException("Unknown calendar type.");
        }

    }
135128
@Override
    public void readExternal(ObjectInput s) throws IOException, ClassNotFoundException {
        super.readExternal(s);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
            Tr.event(this, tc, "Deserializing " + this);
        }
    }
486933
@Override
    public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "De-serializing into: " + this);
        }
        super.readExternal(input);
        deserializeMethod(input);
        deserializeScheme(input);
        this.myURIBytes = readByteArray(input);
        setQueryString(readByteArray(input));
    }