Read a tuple header from the stream.

@return the arity of the tuple.

@exception OtpErlangDecodeException
if the next term in the stream is not a tuple.
504432
public int read_tuple_head() throws OtpErlangDecodeException {
        int arity = 0;
        final int tag = read1skip_version();

        // decode the tuple header and get arity
        switch (tag) {
        case OtpExternal.smallTupleTag:
            arity = read1();
            break;

        case OtpExternal.largeTupleTag:
            arity = read4BE();
            break;

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

        return arity;
    }
1339246
def parse_content_type(headers: MutableMapping) -> Tuple[Optional[str], str]:
    
    content_type = headers.get("content-type")
    if not content_type:
        return None, "utf-8"
    else:
        type_, parameters = cgi.parse_header(content_type)
        encoding = parameters.get("charset", "utf-8")
        return type_, encoding
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);
    }
1252402
public int read() throws IOException {
        synchronized (lock) {
            ensureOpen();
            for (;;) {
                if (nextChar >= nChars) {
                    fill();
                    if (nextChar >= nChars)
                        return -1;
                }
                if (skipLF) {
                    skipLF = false;
                    if (cb[nextChar] == '\n') {
                        nextChar++;
                        continue;
                    }
                }
                return cb[nextChar++];
            }
        }
    }
338596
public String getReadMethod() {
    	if ( getterName != null ) {
    		return getterName;
	    }
        String prefix;
        if ( "boolean".equals( this.type ) ) {
            prefix = "is";
        } else {
            prefix = "get";
        }
        return prefix + this.name.substring( 0,
                1 ).toUpperCase() + this.name.substring( 1 );
    }
184659
public Token read(Token t) throws IOException {
    if (t.e == EditsElement.OPCODE) {
      // read the offset first
      LongToken offsetToken = new LongToken(EditsElement.OFFSET);
      offsetToken.fromString(getNextElementsValue(EditsElement.OFFSET.name()));
      t.offset = offsetToken.value;
    }
    t.fromString(getNextElementsValue(t.getEditsElement().toString()));
    return t;
  }
1039757
private int get() throws IOException {
        int c = theLookahead;
        theLookahead = EOF;
        if (c == EOF) {
            c = inputStream.read();
        }
        if (c >= ' ' || c == '\n' || c == EOF) {
            return c;
        }
        if (c == '\r') {
            return '\n';
        }
        return ' ';
    }
184441
public byte[] read_integer_byte_array() throws OtpErlangDecodeException {
        int tag;
        byte[] nb;

        tag = read1skip_version();

        switch (tag) {
        case OtpExternal.smallIntTag:
            nb = new byte[2];
            nb[0] = 0;
            nb[1] = (byte) read1();
            break;

        case OtpExternal.intTag:
            nb = new byte[4];
            if (this.readN(nb) != 4) { // Big endian
                throw new OtpErlangDecodeException(
                        "Cannot read from intput stream");
            }
            break;

        case OtpExternal.smallBigTag:
        case OtpExternal.largeBigTag:
            int arity;
            int sign;
            if (tag == OtpExternal.smallBigTag) {
                arity = read1();
                sign = read1();
            } else {
                arity = read4BE();
                sign = read1();
                if (arity + 1 < 0) {
                    throw new OtpErlangDecodeException(
                            "Value of largeBig does not fit in BigInteger, arity "
                                    + arity + " sign " + sign);
                }
            }
            nb = new byte[arity + 1];
            // Value is read as little endian. The big end is augumented
            // with one zero byte to make the value 2's complement positive.
            if (this.readN(nb, 0, arity) != arity) {
                throw new OtpErlangDecodeException(
                        "Cannot read from intput stream");
            }
            // Reverse the array to make it big endian.
            for (int i = 0, j = nb.length; i < j--; i++) {
                // Swap [i] with [j]
                final byte b = nb[i];
                nb[i] = nb[j];
                nb[j] = b;
            }
            if (sign != 0) {
                // 2's complement negate the big endian value in the array
                int c = 1; // Carry
                for (int j = nb.length; j-- > 0;) {
                    c = (~nb[j] & 0xFF) + c;
                    nb[j] = (byte) c;
                    c >>= 8;
                }
            }
            break;

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

        return nb;
    }
1316011
public synchronized ByteBuffer getExtraHeader() throws IOException {
    final int size = headersize - INTERNAL_HEADER_SIZE;
    final MapMode mode = writable ? MapMode.READ_WRITE : MapMode.READ_ONLY;
    return file.getChannel().map(mode, INTERNAL_HEADER_SIZE, size);
  }
426726
public int readShortBE() throws IOException {
        int h = read();
        int l = read();
        if (-1 == h || -1 == l)
            return -1;
        return DataUtils.toShort(h, l);
    }
638848
public int read()
  {
    if (_length <= _offset) {
      if (_head == null)
        return -1;

      TempCharBuffer next = _head.getNext();
      if (_isFree)
        TempCharBuffer.free(_head);
      _head = next;

      if (_head == null)
        return -1;
      
      _buffer = _head.buffer();
      _length = _head.getLength();
      _offset = 0;
    }

    return _buffer[_offset++];
  }
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;
    }
1224171
@SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:npathcomplexity"})
	public final void readHeader() throws IOException {
		if (!this.headerWasread) {
			preReadingStage();

			final ByteBuffer hbuffer = ByteBuffer.allocate(100);
			final int read = this.stream.read(hbuffer);
			if (read < 0) {
				throw new EOFException();
			}
			hbuffer.rewind();
			hbuffer.limit(read);

			hbuffer.order(ByteOrder.BIG_ENDIAN);

			// File Code (Big endian)
			final int fileType = hbuffer.getInt();
			if (fileType != SHAPE_FILE_CODE) {
				throw new NotShapeFileException();
			}

			hbuffer.position(24);
			// File Length in 16-bit words (Big endian)
			final int streamFileSize = hbuffer.getInt();
			this.fileSize = fromESRIWords(streamFileSize);

			hbuffer.order(ByteOrder.LITTLE_ENDIAN);

			// Version (Little endian)
			final int version = hbuffer.getInt();
			if (version != SHAPE_FILE_VERSION) {
				throw new InvalidShapeFileVersionException(version, SHAPE_FILE_VERSION);
			}

			// Shape Type (Little endian)
			this.expectedShapeType = ShapeElementType.fromESRIInteger(hbuffer.getInt());

			// Xmin (Little endian)
			this.minx = fromESRI_x(hbuffer.getDouble());
			// Ymin (Little endian)
			this.miny = fromESRI_y(hbuffer.getDouble());
			// Xmax (Little endian)
			this.maxx = fromESRI_x(hbuffer.getDouble());
			// Ymax (Little endian)
			this.maxy = fromESRI_y(hbuffer.getDouble());
			this.minz = fromESRI_z(hbuffer.getDouble());
			this.maxz = fromESRI_z(hbuffer.getDouble());
			this.minm = fromESRI_m(hbuffer.getDouble());
			this.maxm = fromESRI_m(hbuffer.getDouble());

			if (!Double.isNaN(this.minx) && !Double.isNaN(this.maxx)
					&& this.maxx < this.minx) {
				final double t = this.maxx;
				this.maxx = this.minx;
				this.minx = t;
			}

			if (!Double.isNaN(this.miny) && !Double.isNaN(this.maxy)
					&& this.maxy < this.miny) {
				final double t = this.maxy;
				this.maxy = this.miny;
				this.miny = t;
			}

			if (!Double.isNaN(this.minz) && !Double.isNaN(this.maxz)
					&& this.maxz < this.minz) {
				final double t = this.maxz;
				this.maxz = this.minz;
				this.minz = t;
			}

			if (!Double.isNaN(this.minm) && !Double.isNaN(this.maxm)
					&& this.maxm < this.minm) {
				final double t = this.maxm;
				this.maxm = this.minm;
				this.minm = t;
			}

			this.headerWasread = true;
			this.nextExpectedRecordIndex = 0;

			postHeaderReadingStage();

			initializeContentBuffer();

			if (this.taskProgression != null) {
				this.taskProgression.setProperties(this.buffer.position() + HEADER_BYTES, 0, this.fileSize, false);
				this.taskProgression.setIndeterminate(false);
			}
		}
	}
394848
public T decode(ProtoHead head, InputStream in, Charset charset) throws IOException {
        this.head = head;
        return decodeContent(in, charset);
    }
539443
public int read2BE() throws OtpErlangDecodeException {
        final byte[] b = new byte[2];
        try {
            super.read(b);
        } catch (final IOException e) {
            throw new OtpErlangDecodeException("Cannot read from input stream");
        }
        return (b[0] << 8 & 0xff00) + (b[1] & 0xff);
    }
1255914
private String readHeader() throws IOException {
        StringBuffer buffer = new StringBuffer();
        int aChar;
        do {
            aChar = m_inStream.read();
            if (aChar == -1) {
                // Unexpected EOF
                throw new IOException("Unexpected EOF");
            }

            // here, got a character; append it to the line
            buffer.append((char)aChar);
        } while (aChar != '\n');
        
        // Buffer could be empty.
        return buffer.toString();
    }
309762
@SuppressWarnings({"resource", "checkstyle:magicnumber"})
	protected void readHeader() throws IOException {
		final ReadableByteChannel in = Channels.newChannel(this.input);
		final int limit = HEADER_KEY.getBytes().length + 2;
		final ByteBuffer hBuffer = ByteBuffer.allocate(limit);
		hBuffer.limit(limit);

		// Check the header
		final byte[] key = GISLayerIOConstants.HEADER_KEY.getBytes();
		final int n = in.read(hBuffer);
		if (n != limit) {
			throw new IOException("Invalid file header"); //$NON-NLS-1$
		}
		for (int i = 0; i < key.length; ++i) {
			if (hBuffer.get(i) != key[i]) {
				throw new IOException("Invalid file header"); //$NON-NLS-1$
			}
		}
		// Check the format version
		final byte major = hBuffer.get(key.length);
		final byte minor = hBuffer.get(key.length + 1);
		if (major != GISLayerIOConstants.MAJOR_SPEC_NUMBER || minor != GISLayerIOConstants.MINOR_SPEC_NUMBER) {
			throw new IOException("Invalid file format version."); //$NON-NLS-1$
		}
		// Read the number of objects inside the input stream
		final ByteBuffer sBuffer = ByteBuffer.allocate(4);
		sBuffer.limit(4);
		in.read(sBuffer);
		sBuffer.rewind();
		this.restToRead = sBuffer.getInt();
	}