Read only header part of a tag.

@return Tag header
@throws UnsupportedDataTypeException
763141
private ITag readTagHeader() throws UnsupportedDataTypeException {
        // previous tag size (4 bytes) + flv tag header size (11 bytes)
        fillBuffer(15);
        // previous tag's size
        int previousTagSize = in.getInt();
        // start of the flv tag
        byte dataType = in.get();
        if (log.isTraceEnabled()) {
            log.trace("Bits: {}", Integer.toBinaryString(dataType));
        }
        dataType = (byte) (dataType & 31);
        byte filter = (byte) ((dataType & 63) >> 5);
        byte reserved = (byte) ((dataType & 127) >> 6);
        log.debug("Reserved: {}, Filter: {}, Datatype: {}", reserved, filter, dataType);
        switch (dataType) {
            case 8: // audio
                log.debug("Found audio");
                break;
            case 9: // video
                log.debug("Found video");
                break;
            case 15: // special fms undocumented type?
            case 18: // meta / script data
                log.debug("Found meta/script data");
                break;
            default:
                log.debug("Invalid data type detected ({}), reading ahead\n current position: {} limit: {}", dataType, in.position(), in.limit());
                throw new UnsupportedDataTypeException("Invalid data type detected (" + dataType + ")");
        }
        int bodySize = IOUtils.readUnsignedMediumInt(in);
        int timestamp = IOUtils.readExtendedMediumInt(in);
        int streamId = IOUtils.readUnsignedMediumInt(in);
        if (log.isDebugEnabled()) {
            log.debug("Data type: {} timestamp: {} stream id: {} body size: {} previous tag size: {}", new Object[] { dataType, timestamp, streamId, bodySize, previousTagSize });
        }
        return new Tag(dataType, timestamp, bodySize, null, previousTagSize);
    }
329345
protected void readTag(int tag)
        throws IOException
    {
        int length = (is.read() << 8) + is.read();
        is.skip(length);
    }
1018001
private boolean readHeader() {
    boolean correct = true;
    ByteOrder byteOrder = ByteOrder.LITTLE_ENDIAN;
    int c1 = 0;
    int c2 = 0;
    try {
      c1 = data.readByte().toInt();
      c2 = data.readByte().toInt();
    } catch (Exception ex) {
      validation.addErrorLoc("Header IO Exception", "Header");
    }

    // read the first two bytes, in order to know the byte ordering
    if (c1 == 'I' && c2 == 'I') {
      byteOrder = ByteOrder.LITTLE_ENDIAN;
    } else if (c1 == 'M' && c2 == 'M') {
      byteOrder = ByteOrder.BIG_ENDIAN;
    }
    else if (byteOrderErrorTolerance > 0 && c1 == 'i' && c2 == 'i') {
      validation.addWarning("Byte Order in lower case", "" + c1 + c2, "Header");
      byteOrder = ByteOrder.LITTLE_ENDIAN;
    } else if (byteOrderErrorTolerance > 0 && c1 == 'm' && c2 == 'm') {
      validation.addWarning("Byte Order in lower case", "" + c1 + c2, "Header");
      byteOrder = ByteOrder.BIG_ENDIAN;
    } else if (byteOrderErrorTolerance > 1) {
      validation.addWarning("Non-sense Byte Order. Trying Little Endian.", "" + c1 + c2, "Header");
      byteOrder = ByteOrder.LITTLE_ENDIAN;
    } else {
      validation.addErrorLoc("Invalid Byte Order " + c1 + c2, "Header");
      correct = false;
    }
    if (correct) {
      tiffModel.setByteOrder(byteOrder);
      data.setByteOrder(byteOrder);

      try {
        // read magic number
        int magic = data.readShort().toInt();
        tiffModel.setMagicNumber(magic);
      } catch (Exception ex) {
        validation.addErrorLoc("Magic number parsing error", "Header");
        correct = false;
      }
    }
    return correct;
  }
778490
private Tag readTag(int depth) throws IOException {
        int typeId = is.readByte() & 0xFF;
        TagType type = TagType.getById(typeId);

        String name;
        if (type != TagType.TAG_END) {
            int nameLength = is.readShort() & 0xFFFF;
            byte[] nameBytes = new byte[nameLength];
            is.readFully(nameBytes);
            name = new String(nameBytes, NBTConstants.CHARSET.name());
        } else {
            name = "";
        }

        return readTagPayload(type, name, depth);
    }
499247
private function read_header()
    {
        $this->seek(0, IO::SEEK_SET);

        $magic = $this->read(DataIO::magic_size());

        if (strlen($magic) < DataIO::magic_size())
            throw new DataIoException(
                'Not an Avro data file: shorter than the Avro magic block');

        if (DataIO::magic() != $magic) {

            throw new DataIoException(
                sprintf('Not an Avro data file: %s does not match %s',
                    $magic, DataIO::magic()));
        }

        $this->metadata = $this->datum_reader->read_data(DataIO::metadata_schema(),
            DataIO::metadata_schema(),
            $this->decoder);
        $this->sync_marker = $this->read(DataIO::SYNC_SIZE);
    }
588339
public function getHeader()
    {
        if (null == $this->header) {
            $header = $this->getNextDataSet();
            if (null === $header) {
                throw new Exception("Cannot retrieve header");
            }
            $this->setHeader($header);
        }

        return $this->header;
    }
1117597
public <X> DataStream<X> getSideOutput(OutputTag<X> sideOutputTag) {
		if (wasSplitApplied) {
			throw new UnsupportedOperationException("getSideOutput() and split() may not be called on the same DataStream. " +
				"As a work-around, please add a no-op map function before the split() call.");
		}

		sideOutputTag = clean(requireNonNull(sideOutputTag));

		// make a defensive copy
		sideOutputTag = new OutputTag<X>(sideOutputTag.getId(), sideOutputTag.getTypeInfo());

		TypeInformation<?> type = requestedSideOutputs.get(sideOutputTag);
		if (type != null && !type.equals(sideOutputTag.getTypeInfo())) {
			throw new UnsupportedOperationException("A side output with a matching id was " +
					"already requested with a different type. This is not allowed, side output " +
					"ids need to be unique.");
		}

		requestedSideOutputs.put(sideOutputTag, sideOutputTag.getTypeInfo());

		SideOutputTransformation<X> sideOutputTransformation = new SideOutputTransformation<>(this.getTransformation(), sideOutputTag);
		return new DataStream<>(this.getExecutionEnvironment(), sideOutputTransformation);
	}
94782
@SuppressWarnings ({"unchecked", "rawtypes"})
    private Tag readTagPayload(TagType type, String name, int depth) throws IOException {
        switch (type) {
            case TAG_END:
                if (depth == 0) {
                    throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
                } else {
                    return new EndTag();
                }

            case TAG_BYTE:
                return new ByteTag(name, is.readByte());

            case TAG_SHORT:
                return new ShortTag(name, is.readShort());

            case TAG_INT:
                return new IntTag(name, is.readInt());

            case TAG_LONG:
                return new LongTag(name, is.readLong());

            case TAG_FLOAT:
                return new FloatTag(name, is.readFloat());

            case TAG_DOUBLE:
                return new DoubleTag(name, is.readDouble());

            case TAG_BYTE_ARRAY:
                int length = is.readInt();
                byte[] bytes = new byte[length];
                is.readFully(bytes);
                return new ByteArrayTag(name, bytes);

            case TAG_STRING:
                length = is.readShort();
                bytes = new byte[length];
                is.readFully(bytes);
                return new StringTag(name, new String(bytes, NBTConstants.CHARSET.name()));

            case TAG_LIST:
                TagType childType = TagType.getById(is.readByte());
                length = is.readInt();

                Class<? extends Tag> clazz = childType.getTagClass();
                List<Tag> tagList = new ArrayList<Tag>(length);
                for (int i = 0; i < length; i++) {
                    Tag tag = readTagPayload(childType, "", depth + 1);
                    if (tag instanceof EndTag) {
                        throw new IOException("TAG_End not permitted in a list.");
                    } else if (!clazz.isInstance(tag)) {
                        throw new IOException("Mixed tag types within a list.");
                    }
                    tagList.add(tag);
                }

                return new ListTag(name, clazz, tagList);

            case TAG_COMPOUND:
                CompoundMap compoundTagList = new CompoundMap();
                while (true) {
                    Tag tag = readTag(depth + 1);
                    if (tag instanceof EndTag) {
                        break;
                    } else {
                        compoundTagList.put(tag);
                    }
                }

                return new CompoundTag(name, compoundTagList);

            case TAG_INT_ARRAY:
                length = is.readInt();
                int[] ints = new int[length];
                for (int i = 0; i < length; i++) {
                    ints[i] = is.readInt();
                }
                return new IntArrayTag(name, ints);

            case TAG_SHORT_ARRAY:
                length = is.readInt();
                short[] shorts = new short[length];
                for (int i = 0; i < length; i++) {
                    shorts[i] = is.readShort();
                }
                return new ShortArrayTag(name, shorts);

            default:
                throw new IOException("Invalid tag type: " + type + ".");
        }
    }
809800
private int read() {
        int curByte = 0;
        try {
            curByte = rawData.get() & 0xFF;
        } catch (Exception e) {
            header.status = GifDecoder.STATUS_FORMAT_ERROR;
        }
        return curByte;
    }
545476
public int doEndTag() throws JspException {
        // Get body content (trim is CRUCIAL, as some XML parsers are picky...)
        String body = bodyContent.getString().trim();

        // Do transformation
        transform(new StreamSource(new ByteArrayInputStream(body.getBytes())));

        return super.doEndTag();
    }
842414
public int readTag() throws IOException {
    if (isAtEnd()) {
      lastTag = 0;
      return 0;
    }

    lastTag = readRawVarint32();
    if (WireFormat.getTagFieldNumber(lastTag) == 0) {
      // If we actually read zero (or any tag number corresponding to field
      // number zero), that's not a valid tag.
      throw InvalidProtocolBufferException.invalidTag();
    }
    return lastTag;
  }
1251022
public int readChar()
        throws IOException
    {
        if (_chunkLength > 0) {
            _chunkLength--;
            if (_chunkLength == 0 && _isLastChunk)
                _chunkLength = END_OF_DATA;

            int ch = parseUTF8Char();
            return ch;
        }
        else if (_chunkLength == END_OF_DATA) {
            _chunkLength = 0;
            return -1;
        }

        int tag = read();

        switch (tag) {
            case 'N':
                return -1;

            case 'S':
            case 's':
            case 'X':
            case 'x':
                _isLastChunk = tag == 'S' || tag == 'X';
                _chunkLength = (read() << 8) + read();

                _chunkLength--;
                int value = parseUTF8Char();

                // special code so successive read byte won't
                // be read as a single object.
                if (_chunkLength == 0 && _isLastChunk)
                    _chunkLength = END_OF_DATA;

                return value;

            default:
                throw new IOException("expected 'S' at " + (char) tag);
        }
    }
508457
public Content getSummaryTableHeader(List<String> header, String scope) {
        Content tr = new HtmlTree(HtmlTag.TR);
        final int size = header.size();
        Content tableHeader;
        if (size == 2) {
            tableHeader = new StringContent(header.get(0));
            tr.addContent(HtmlTree.TH(HtmlStyle.colFirst, scope, tableHeader));
            tableHeader = new StringContent(header.get(1));
            tr.addContent(HtmlTree.TH(HtmlStyle.colLast, scope, tableHeader));
            return tr;
        }
        for (int i = 0; i < size; i++) {
            tableHeader = new StringContent(header.get(i));
            if (i == 0)
                tr.addContent(HtmlTree.TH(HtmlStyle.colFirst, scope, tableHeader));
            else if (i == 1)
                tr.addContent(HtmlTree.TH(HtmlStyle.colSecond, scope, tableHeader));
            else if (i == (size - 1))
                tr.addContent(HtmlTree.TH(HtmlStyle.colLast, scope, tableHeader));
            else
                tr.addContent(HtmlTree.TH(scope, tableHeader));
        }
        return tr;
    }
909997
public int readTag() throws IOException
    {
        if (!buffer.hasRemaining())
        {
            lastTag = 0;
            return 0;
        }

        final int tag = readRawVarint32();
        if (tag >>> TAG_TYPE_BITS == 0)
        {
            // If we actually read zero, that's not a valid tag.
            throw ProtobufException.invalidTag();
        }
        lastTag = tag;
        return tag;
    }
1126041
public byte[] readBytes()
        throws IOException
    {
        int tag = read();

        switch (tag) {
            case 'N':
                return null;

            case 'B':
            case 'b':
                _isLastChunk = tag == 'B';
                _chunkLength = (read() << 8) + read();

                ByteArrayOutputStream bos = new ByteArrayOutputStream();

                int data;
                while ((data = parseByte()) >= 0)
                    bos.write(data);

                return bos.toByteArray();

            default:
                throw expect("bytes", tag);
        }
    }
115783
public Content getSummaryTableHeader(String[] header, String scope) {
        Content tr = new HtmlTree(HtmlTag.TR);
        int size = header.length;
        Content tableHeader;
        if (size == 1) {
            tableHeader = new StringContent(header[0]);
            tr.addContent(HtmlTree.TH(HtmlStyle.colOne, scope, tableHeader));
            return tr;
        }
        for (int i = 0; i < size; i++) {
            tableHeader = new StringContent(header[i]);
            if(i == 0)
                tr.addContent(HtmlTree.TH(HtmlStyle.colFirst, scope, tableHeader));
            else if(i == (size - 1))
                tr.addContent(HtmlTree.TH(HtmlStyle.colLast, scope, tableHeader));
            else
                tr.addContent(HtmlTree.TH(scope, tableHeader));
        }
        return tr;
    }
1309592
private InputStream readHttpHeader() throws IOException {
    	
    	// this can be helpful when simply iterating over records, 
    	// looking for problems.
        Logger logger = Logger.getLogger(this.getClass().getName());
    	ArchiveRecordHeader h = this.getHeader();
    	
        // If judged a record that doesn't have an http header, return
        // immediately.
        String url = getHeader().getUrl();
        if(!url.startsWith("http") ||
            getHeader().getLength() <= MIN_HTTP_HEADER_LENGTH) {
            return null;
        }
        
        String statusLine;
        byte[] statusBytes;
        int eolCharCount = 0;
        int errOffset = 0;
        
        // Read status line, skipping any errant http headers found before it
        // This allows a larger number of 'corrupt' arcs -- where headers were accidentally
        // inserted before the status line to be readable
        while (true) {
        	statusBytes = LaxHttpParser.readRawLine(getIn());
        	eolCharCount = getEolCharsCount(statusBytes);
        	if (eolCharCount <= 0) {
        		throw new RecoverableIOException(
                "Failed to read http status where one was expected: " 
                + ((statusBytes == null) ? "" : new String(statusBytes)));
        	}
        
        	statusLine = EncodingUtil.getString(statusBytes, 0,
        			statusBytes.length - eolCharCount, ARCConstants.DEFAULT_ENCODING);
        	
        	// If a null or DELETED break immediately
        	if ((statusLine == null) || statusLine.startsWith("DELETED")) {
        		break;
        	}
        	
        	// If it's actually the status line, break, otherwise continue skipping any
        	// previous header values
        	if (!statusLine.contains(":") && StatusLine.startsWithHTTP(statusLine)) {
        		break;
        	}
        	
        	// Add bytes read to error "offset" to add to position
        	errOffset += statusBytes.length;
        }
        
        if (errOffset > 0) {
            this.incrementPosition(errOffset);
        }
        
        if ((statusLine == null) ||
                !StatusLine.startsWithHTTP(statusLine)) {
            if (statusLine.startsWith("DELETED")) {
                // Some old ARCs have deleted records like following:
                // http://vireo.gatech.edu:80/ebt-bin/nph-dweb/dynaweb/SGI_Developer/SGITCL_PG/@Generic__BookTocView/11108%3Btd%3D2 130.207.168.42 19991010131803 text/html 29202
                // DELETED_TIME=20000425001133_DELETER=Kurt_REASON=alexalist
                // (follows ~29K spaces)
                // For now, throw a RecoverableIOException so if iterating over
                // records, we keep going.  TODO: Later make a legitimate
                // ARCRecord from the deleted record rather than throw
                // exception.
                throw new DeletedARCRecordIOException(statusLine);
            } else {
            	this.errors.add(ArcRecordErrors.HTTP_STATUS_LINE_INVALID);
            }
        }

        try {
        	this.httpStatus = new StatusLine(statusLine);
        } catch(IOException e) {
        	logger.warning(e.getMessage() + " at offset: " + h.getOffset());
        	this.errors.add(ArcRecordErrors.HTTP_STATUS_LINE_EXCEPTION);
        }
        
        // Save off all bytes read.  Keep them as bytes rather than
        // convert to strings so we don't have to worry about encodings
        // though this should never be a problem doing http headers since
        // its all supposed to be ascii.
        ByteArrayOutputStream baos =
            new ByteArrayOutputStream(statusBytes.length + 4 * 1024);
        baos.write(statusBytes);
        
        // Now read rest of the header lines looking for the separation
        // between header and body.
        for (byte [] lineBytes = null; true;) {
            lineBytes = LaxHttpParser.readRawLine(getIn());
            eolCharCount = getEolCharsCount(lineBytes);
            if (eolCharCount <= 0) {
            	if (getIn().available() == 0) {
            		httpHeaderBytesRead += statusBytes.length;
                	logger.warning("HTTP header truncated at offset: " + h.getOffset());
            		this.errors.add(ArcRecordErrors.HTTP_HEADER_TRUNCATED);
            		this.setEor(true);
            		break;
            	} else {
            		throw new IOException("Failed reading http headers: " +
            				((lineBytes != null)? new String(lineBytes): null));
            	}
            } else {
            	httpHeaderBytesRead += lineBytes.length;
            }
            // Save the bytes read.
            baos.write(lineBytes);
            if ((lineBytes.length - eolCharCount) <= 0) {
                // We've finished reading the http header.
                break;
            }
        }
        
        byte [] headerBytes = baos.toByteArray();
        // Save off where body starts.
        this.getMetaData().setContentBegin(headerBytes.length);
        ByteArrayInputStream bais =
            new ByteArrayInputStream(headerBytes);
        if (!bais.markSupported()) {
            throw new IOException("ByteArrayInputStream does not support mark");
        }
        bais.mark(headerBytes.length);
        // Read the status line.  Don't let it into the parseHeaders function.
        // It doesn't know what to do with it.
        bais.read(statusBytes, 0, statusBytes.length);
        this.httpHeaders = LaxHttpParser.parseHeaders(bais,
            ARCConstants.DEFAULT_ENCODING);
        this.getMetaData().setStatusCode(Integer.toString(getStatusCode()));
        bais.reset();
        return bais;
    }