public void close() throws IOException {
        if (!this.stack.empty()) {
            throw new InvalidObjectException("Tags are not all closed. " +
                    "Possibly, " + this.stack.pop() + " is unclosed. ");
        }
        if (thisIsWriterOwner)
        {
            this.writer.flush();
            this.writer.close();
        }
    }