Read an Erlang port from the stream.

@return the value of the port.

@exception OtpErlangDecodeException
if the next term in the stream is not an Erlang port.
493752
public OtpErlangPort read_port() throws OtpErlangDecodeException {
        String node;
        int id;
        int creation;
        int tag;

        tag = read1skip_version();

        if (tag != OtpExternal.portTag &&
	    tag != OtpExternal.newPortTag) {
            throw new OtpErlangDecodeException(
                    "Wrong tag encountered, expected " + OtpExternal.portTag
		    + " or " + OtpExternal.newPortTag
                            + ", got " + tag);
        }

        node = read_atom();
        id = read4BE();
	if (tag == OtpExternal.portTag)
	    creation = read1();
	else
	    creation = read4BE();

        return new OtpErlangPort(tag, node, id, creation);
    }
1048733
public short read_ushort() throws OtpErlangDecodeException {
        final long l = this.read_long(true);
        final short i = (short) l;

        if (l != (i & 0xffffL)) {
            throw new OtpErlangDecodeException("Value does not fit in ushort: "
                    + l);
        }

        return i;
    }
254856
public OtpErlangPid read_pid() throws OtpErlangDecodeException {
        String node;
        int id;
        int serial;
        int creation;
        int tag;

        tag = read1skip_version();

        if (tag != OtpExternal.pidTag &&
	    tag != OtpExternal.newPidTag) {
            throw new OtpErlangDecodeException(
                    "Wrong tag encountered, expected " + OtpExternal.pidTag
		    + " or " + OtpExternal.newPidTag
                            + ", got " + tag);
        }

        node = read_atom();
        id = read4BE();
        serial = read4BE();
	if (tag == OtpExternal.pidTag)
	    creation = read1();
	else
	    creation = read4BE();

        return new OtpErlangPid(tag, node, id, serial, creation);
    }
487823
public byte read() throws IOException {
        if (current >= fsize) {
            throw new java.io.EOFException("Reached EOF, file size=" + fsize);
        }

        final byte ret = file[current++];
        return ret;
    }
482960
public int read_nil() throws OtpErlangDecodeException {
        int arity = 0;
        final int tag = read1skip_version();

        switch (tag) {
        case OtpExternal.nilTag:
            arity = 0;
            break;

        default:
            throw new OtpErlangDecodeException("Not valid nil tag: " + tag);
        }

        return arity;
    }
744130
@Override
  public int read () throws IOException
  {
    _ensureOpen ();
    while (true)
    {
      if (m_nNextCharIndex >= m_nChars)
      {
        _fill ();
        if (m_nNextCharIndex >= m_nChars)
          return -1;
      }
      if (m_bSkipLF)
      {
        m_bSkipLF = false;
        if (m_aBuf[m_nNextCharIndex] == '\n')
        {
          m_nNextCharIndex++;
          continue;
        }
      }
      return m_aBuf[m_nNextCharIndex++];
    }
  }
118117
public long readLE(final int n) throws OtpErlangDecodeException {
        final byte[] b = new byte[n];
        try {
            super.read(b);
        } catch (final IOException e) {
            throw new OtpErlangDecodeException("Cannot read from input stream");
        }
        long v = 0;
        int i = n;
        while (i-- > 0) {
            v = v << 8 | (long) b[i] & 0xff;
        }
        return v;
    }
47537
public int read_int() throws OtpErlangDecodeException {
        final long l = this.read_long(false);
        final int i = (int) l;

        if (l != i) {
            throw new OtpErlangDecodeException("Value does not fit in int: "
                    + l);
        }

        return i;
    }
50564
public byte[] getPort() {
        byte[] port = new byte[2];
        int p = (getEndpointAddress() == null ? this.port
                : getEndpointAddress().getPort());
        port[1] = (byte) p;
        port[0] = (byte) (p >> 8);
        return port;
    }
930148
public BufferedReader getReader()
    	throws UnsupportedEncodingException
    {
        if (_inputState!=0 && _inputState!=2)
            throw new IllegalStateException();
        if (_reader==null)
        {
            String encoding=getCharacterEncoding();
            if (encoding==null)
                encoding=StringUtil.__ISO_8859_1;
            _reader=new BufferedReader(new InputStreamReader(getInputStream(),encoding));
            
        }
        _inputState=2;
        return _reader;
    }
984109
public static Reader getReadEncoding(InputStream is, String encoding)
    throws UnsupportedEncodingException
  {
    return getReadFactory(encoding).create(is);
  }
351135
private static int read(InputStream is) throws IOException {
        int b = is.read();
        if (b == -1) {
            throw new EOFException();
        }
        return b;
    }
869715
private int parseCtrlWord(PushbackInputStream reader) throws IOException {
		int nextChar = 0;
		int result = errOK;
		
		if((nextChar = reader.read()) == -1) {
			return errEndOfFile;
		}
		this.byteCount++;

		StringBuffer parsedCtrlWord = new StringBuffer();
		StringBuffer parsedParam= new StringBuffer();
		RtfCtrlWordData ctrlWordParam = new RtfCtrlWordData();
		
		if(!Character.isLetterOrDigit((char)nextChar)) {
			parsedCtrlWord.append((char)nextChar);
			ctrlWordParam.ctrlWord = parsedCtrlWord.toString();
			result =  this.handleCtrlWord(ctrlWordParam);
			lastCtrlWordParam = ctrlWordParam;
			return result;
		}
		
		do {
			parsedCtrlWord.append((char)nextChar);
			//TODO: catch EOF
			nextChar = reader.read();
			this.byteCount++;
		} while  (Character.isLetter((char)nextChar));
		
		ctrlWordParam.ctrlWord = parsedCtrlWord.toString();

		if(nextChar == '-') {
			ctrlWordParam.isNeg = true;
			if((nextChar = reader.read()) == -1) {
					return errEndOfFile;
			}
			this.byteCount++;
		}
		

		if(Character.isDigit((char)nextChar)) {
			ctrlWordParam.hasParam = true;
			do {
				parsedParam.append((char)nextChar);
				//TODO: catch EOF
				nextChar = reader.read();
				this.byteCount++;
				} while  (Character.isDigit((char)nextChar));
						
			ctrlWordParam.param = parsedParam.toString();
		}
		
		// push this character back into the stream
		if(nextChar != ' ') { 
			reader.unread(nextChar);
		}
		
	    if(debugParser) {
	//	    // debug: insrsid6254399
	//	    if(ctrlWordParam.ctrlWord.equals("proptype") && ctrlWordParam.param.equals("30")) {
	//	    	System.out.print("Debug value found\n");
	//	    }
//		    if(ctrlWordParam.ctrlWord.equals("cf") ) {
//		    	System.out.print("Debug value found\n");
//		    }
	    }
	    
		result = this.handleCtrlWord(ctrlWordParam);
		lastCtrlWordParam = ctrlWordParam;
		return result;

	}
1083772
public int read4BE() throws OtpErlangDecodeException {
        final byte[] b = new byte[4];
        try {
            super.read(b);
        } catch (final IOException e) {
            throw new OtpErlangDecodeException("Cannot read from input stream");
        }
        return (b[0] << 24 & 0xff000000) + (b[1] << 16 & 0xff0000)
                + (b[2] << 8 & 0xff00) + (b[3] & 0xff);
    }
607277
@Override
	public int read() throws IOException {
		byte[] buf = new byte[1];

		int res = this.read(buf, 0, 1);

		if (res != -1) {
			return 0xFF & buf[0];
		}

		return res;
	}
101029
public char charValue() throws OtpErlangRangeException {
        final long l = longValue();
        final char i = (char) l;

        if (i != l) {
            throw new OtpErlangRangeException("Value too large for char: "
                    + val);
        }

        return i;
    }
292226
public String read_string() throws OtpErlangDecodeException {
        int tag;
        int len;
        byte[] strbuf;
        int[] intbuf;
        tag = read1skip_version();
        switch (tag) {
        case OtpExternal.stringTag:
            len = read2BE();
            strbuf = new byte[len];
            this.readN(strbuf);
            return OtpErlangString.newString(strbuf);
        case OtpExternal.nilTag:
            return "";
        case OtpExternal.listTag: // List when unicode +
            len = read4BE();
            intbuf = new int[len];
            for (int i = 0; i < len; i++) {
                intbuf[i] = read_int();
                if (!OtpErlangString.isValidCodePoint(intbuf[i])) {
                    throw new OtpErlangDecodeException("Invalid CodePoint: "
                            + intbuf[i]);
                }
            }
            read_nil();
            return new String(intbuf, 0, intbuf.length);
        default:
            throw new OtpErlangDecodeException(
                    "Wrong tag encountered, expected " + OtpExternal.stringTag
                            + " or " + OtpExternal.listTag + ", got " + tag);
        }
    }