Read end tag.

@throws IOException Signals that an I/O exception has occurred.
@throws KriptonRuntimeException the kripton runtime exception
423246
private void readEndTag() throws IOException, KriptonRuntimeException {
		read('<');
		read('/');
		name = readName(); // TODO: pass the expected name in as a hint?
		skip();
		read('>');

		int sp = (depth - 1) * 4;

		if (depth == 0) {
			checkRelaxed("read end tag " + name + " with no tags open");
			type = COMMENT;
			return;
		}

		if (name.equals(elementStack[sp + 3])) {
			namespace = elementStack[sp];
			prefix = elementStack[sp + 1];
			name = elementStack[sp + 2];
		} else if (!relaxed) {
			throw new KriptonRuntimeException("expected: /" + elementStack[sp + 3] + " read: " + name, true, this.getLineNumber(), this.getColumnNumber(), getPositionDescription(), null);
		}
	}
1017923
private int next(boolean justOneToken) throws IOException, KriptonRuntimeException {
		if (reader == null) {
			throw new KriptonRuntimeException("setInput() must be called first.", true, this.getLineNumber(), this.getColumnNumber(), getPositionDescription(), null);
		}

		if (type == END_TAG) {
			depth--;
		}

		// degenerated needs to be handled before error because of possible
		// processor expectations(!)

		if (degenerated) {
			degenerated = false;
			type = END_TAG;
			return type;
		}

		if (error != null) {
			if (justOneToken) {
				text = error;
				type = COMMENT;
				error = null;
				return type;
			} else {
				error = null;
			}
		}

		type = peekType(false);

		if (type == XML_DECLARATION) {
			readXmlDeclaration();
			type = peekType(false);
		}

		text = null;
		isWhitespace = true;
		prefix = null;
		name = null;
		namespace = null;
		attributeCount = -1;
		boolean throwOnResolveFailure = !justOneToken;

		while (true) {
			switch (type) {

			/*
			 * Return immediately after encountering a start tag, end tag, or
			 * the end of the document.
			 */
			case START_TAG:
				parseStartTag(false, throwOnResolveFailure);
				return type;
			case END_TAG:
				readEndTag();
				return type;
			case END_DOCUMENT:
				return type;

			/*
			 * Return after any text token when we're looking for a single
			 * token. Otherwise concatenate all text between tags.
			 */
			case ENTITY_REF:
				if (justOneToken) {
					StringBuilder entityTextBuilder = new StringBuilder();
					readEntity(entityTextBuilder, true, throwOnResolveFailure, ValueContext.TEXT);
					text = entityTextBuilder.toString();
					break;
				}
				// fall-through
			case TEXT:
				text = readValue('<', !justOneToken, throwOnResolveFailure, ValueContext.TEXT);
				if (depth == 0 && isWhitespace) {
					type = IGNORABLE_WHITESPACE;
				}
				break;
			case CDSECT:
				read(START_CDATA);
				text = readUntil(END_CDATA, true);
				break;

			/*
			 * Comments, processing instructions and declarations are returned
			 * when we're looking for a single token. Otherwise they're skipped.
			 */
			case COMMENT:
				String commentText = readComment(justOneToken);
				if (justOneToken) {
					text = commentText;
				}
				break;
			case PROCESSING_INSTRUCTION:
				read(START_PROCESSING_INSTRUCTION);
				String processingInstruction = readUntil(END_PROCESSING_INSTRUCTION, justOneToken);
				if (justOneToken) {
					text = processingInstruction;
				}
				break;
			case DOCDECL:
				readDoctype(justOneToken);
				break;

			default:
				throw new KriptonRuntimeException("Unexpected token", true, this.getLineNumber(), this.getColumnNumber(), getPositionDescription(), null);
			}

			if (depth == 0 && (type == ENTITY_REF || type == TEXT || type == CDSECT)) {
				throw new KriptonRuntimeException("Unexpected token", true, this.getLineNumber(), this.getColumnNumber(), getPositionDescription(), null);
			}

			if (justOneToken) {
				return type;
			}

			if (type == IGNORABLE_WHITESPACE) {
				text = null;
			}

			/*
			 * We've read all that we can of a non-empty text block. Always
			 * report this as text, even if it was a CDATA block or entity
			 * reference.
			 */
			int peek = peekType(false);
			if (text != null && !text.isEmpty() && peek < TEXT) {
				type = TEXT;
				return type;
			}

			type = peek;
		}
	}
1321621
private static void skipToEnd(final ImageInputStream stream) throws IOException {
        if (stream.length() > 0) {
            // Seek to end of file
            stream.seek(stream.length());
        }
        else {
            // Skip to end
            long lastGood = stream.getStreamPosition();

            while (stream.read() != -1) {
                lastGood = stream.getStreamPosition();
                stream.skipBytes(1024);
            }

            stream.seek(lastGood);

            while (true) {
                if (stream.read() == -1) {
                    break;
                }
                // Just continue reading to EOF...
            }
        }
    }
282912
private void handleReadBuffer() throws IOException {
        if (readBuffer.remaining() == 0) {
            readBuffer.clear();
            actualFile.read(actualFileOffset, readBuffer);
            actualFileOffset += readBuffer.limit();
            readBuffer.position(0);
        }
    }
436128
public void endArray() throws IOException {
    int p = peeked;
    if (p == PEEKED_NONE) {
      p = doPeek();
    }
    if (p == PEEKED_END_ARRAY) {
      stackSize--;
      pathIndices[stackSize - 1]++;
      peeked = PEEKED_NONE;
    } else {
      throw new IllegalStateException("Expected END_ARRAY but was " + peek() + locationString());
    }
  }
604916
@Override
	public boolean isEmptyElementTag() {
		if (type != START_TAG) {
			throw new KriptonRuntimeException(ILLEGAL_TYPE, true, this.getLineNumber(), this.getColumnNumber(), getPositionDescription(), null);
		}
		return degenerated;
	}
976278
private void finish() throws IOException
	{
		if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
			logger.logp(Level.FINE, CLASS_NAME,"finish", "finish");
        }
		if (length == -1 && total != 0)
			length = total;
		//PK89810 Start
		if (WCCustomProperties.FINISH_RESPONSE_ON_CLOSE) {			
			WebContainerRequestState reqState = WebContainerRequestState.getInstance(false);		
			if (reqState==null || reqState.getAttribute("com.ibm.ws.webcontainer.appIsArdEnabled")==null){
				if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE))
        			logger.logp(Level.FINE, CLASS_NAME,"finish", "finishresponseonclose and appIsNotArdEnabled, setLastBuffer to true");
				response.setLastBuffer(true);	
			}       	
		}//PK89810 End
		flush();
	}
989133
public function readTag()
    {
        if ($this->current === $this->buffer_end) {
            // Make sure that it failed due to EOF, not because we hit
            // total_bytes_limit, which, unlike normal limits, is not a valid
            // place to end a message.
            $current_position = $this->total_bytes_read -
                $this->buffer_size_after_limit;
            if ($current_position >= $this->total_bytes_limit) {
                // Hit total_bytes_limit_.  But if we also hit the normal limit,
                // we're still OK.
                $this->legitimate_message_end =
                    ($this->current_limit === $this->total_bytes_limit);
            } else {
                $this->legitimate_message_end = true;
            }
            return 0;
        }

        $result = 0;
        // The larget tag is 2^29 - 1, which can be represented by int32.
        $success = $this->readVarint32($result);
        if ($success) {
            return $result;
        } else {
            return 0;
        }
    }
548184
public void endElement() throws KNXMLException
	{
		if (layout.empty())
			throw new KNXIllegalStateException("no elements to end");
		try {
			((Tag) layout.pop()).endTag();
			if (layout.empty())
				w.flush();
		}
		catch (final IOException e) {
			throw new KNXMLException(e.getMessage());
		}
	}
286484
public void endDocument() throws IOException {
      checkAndPop(JsonTokenType.BEGIN_DOCUMENT);
      if (isArray) {
         writer.endArray();
      } else {
         writer.endObject();
      }
   }
371289
private void writeTagPayload(Tag<?> tag) throws IOException {
        switch (tag.getType()) {
            case TAG_END:
                writeEndTagPayload((EndTag) tag);
                break;

            case TAG_BYTE:
                writeByteTagPayload((ByteTag) tag);
                break;

            case TAG_SHORT:
                writeShortTagPayload((ShortTag) tag);
                break;

            case TAG_INT:
                writeIntTagPayload((IntTag) tag);
                break;

            case TAG_LONG:
                writeLongTagPayload((LongTag) tag);
                break;

            case TAG_FLOAT:
                writeFloatTagPayload((FloatTag) tag);
                break;

            case TAG_DOUBLE:
                writeDoubleTagPayload((DoubleTag) tag);
                break;

            case TAG_BYTE_ARRAY:
                writeByteArrayTagPayload((ByteArrayTag) tag);
                break;

            case TAG_STRING:
                writeStringTagPayload((StringTag) tag);
                break;

            case TAG_LIST:
                writeListTagPayload((ListTag<?>) tag);
                break;

            case TAG_COMPOUND:
                writeCompoundTagPayload((CompoundTag) tag);
                break;

            case TAG_INT_ARRAY:
                writeIntArrayTagPayload((IntArrayTag) tag);
                break;

            case TAG_SHORT_ARRAY:
                writeShortArrayTagPayload((ShortArrayTag) tag);
                break;

            default:
                throw new IOException("Invalid tag type: " + tag.getType() + ".");
        }
    }
95354
public void endObject() throws IOException {
    int p = peeked;
    if (p == PEEKED_NONE) {
      p = doPeek();
    }
    if (p == PEEKED_END_OBJECT) {
      stackSize--;
      pathNames[stackSize] = null; // Free the last path name so that it can be garbage collected!
      pathIndices[stackSize - 1]++;
      peeked = PEEKED_NONE;
    } else {
      throw new IllegalStateException("Expected END_OBJECT but was " + peek()
          + " at line " + getLineNumber() + " column " + getColumnNumber() + " path " + getPath());
    }
  }
314489
public void endAllElements() throws KNXMLException
	{
		try {
			while (!layout.empty())
				((Tag) layout.pop()).endTag();
			w.flush();
		}
		catch (final IOException e) {
			throw new KNXMLException(e.getMessage());
		}
	}
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;
  }
684356
public int readBit() throws IOException, JPEGMarkerException {
        int bit = 0;

        if (cnt == 0) {
            b = in.read();
            cnt = 8;

            if (b == 0xFF) {
                // Loop here to discard any padding FF's on terminating marker
                do {
                    b = in.read();
                } while (b == 0xFF);

                if (b == 0) {
                    /* Found FF/00, which represents an FF data byte */
                    b = 0xFF;
                    cnt = 8;
                } else {
                    throw new JPEGMarkerException(b);
                }
            } else if (b == -1) {
                throw new JPEGMarkerException(b);
            }
        }

        bit = b >> 7;
        cnt--;
        b = b << 1;

        return bit & 0x1;
    }
217747
public void readTags(InputStream tagsXML)
    {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        try
        {
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(tagsXML, new TagsSaxHandler(this));
        }
        catch (ParserConfigurationException | SAXException | IOException ex)
        {
            throw new RuntimeException("Failed parsing the tags definition: " + ex.getMessage(), ex);
        }
    }
622582
private boolean readSend(InH3 hIn,
                           OutboxAmp outbox,
                           HeadersAmp headers)
      throws IOException
  {
    MethodRefHamp methodHamp = null;
    
    try {
      methodHamp = readMethod(hIn);
    } catch (Throwable e) {
      log.log(Level.FINER, e.toString(), e);
      
      skipArgs(hIn);
      
      return true;
    }

    MethodRefAmp method = methodHamp.getMethod();
    
    //ClassLoader loader = method.getService().getManager().getClassLoader();
    ClassLoader loader = methodHamp.getClassLoader();
    Thread thread = Thread.currentThread();
    thread.setContextClassLoader(loader);
    // XXX: _serializer.setClassLoader(loader);

    Object []args = readArgs(methodHamp, hIn);

    if (log.isLoggable(_logLevel)) {
      log.log(_logLevel, this + " send-r " + method.getName() + debugArgs(args)
                + " {to:" + method + ", " + headers + "}");
    }
    
    // XXX: s/b systemMailbox
    SendMessage_N sendMessage
      = new SendMessage_N(outbox,
                          headers, 
                          method.serviceRef(), method.method(),
                          args);
    
    long timeout = 1000L; // mailbox delay timeout

    try {
      //sendMessage.offer(timeout);
      //sendMessage.offerQueue(timeout);
      //        // sendMessage.getWorker().wake();
      sendMessage.offer(timeout);
    } catch (Throwable e) {
      log.fine(e.toString());
      
      if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, e.toString(), e);
      }
    }
    
    return true;
  }