<commit_before>package com.thoughtworks.xstream.io.xml;

import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.StreamException;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

/**
 * A stream writing that outputs to a StAX stream writer
 *
 * @author <NAME>
 * @version $Revision$
 */
public class StaxWriter implements HierarchicalStreamWriter {
    private XMLStreamWriter out;

    public StaxWriter(XMLStreamWriter out) throws XMLStreamException {
        this.out = out;
        out.writeStartDocument();
    }

    /**
     * Call this method when you're finished with me
     */
    public void close() {
        try {
            out.writeEndDocument();
            out.close();
        }
        catch (XMLStreamException e) {
            throw new StreamException(e);
        }
    }

    public void addAttribute(String name, String value) {
        try {
            out.writeAttribute(name, value);
        }
        catch (XMLStreamException e) {<commit_msg>Added flag to fix XSTR-134<commit_after>package com.thoughtworks.xstream.io.xml;

import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.StreamException;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

/**
 * A stream writing that outputs to a StAX stream writer
 *
 * @author <NAME>
 * @version $Revision$
 */
public class StaxWriter implements HierarchicalStreamWriter {
    private XMLStreamWriter out;
    private boolean writeStartDocument;

    public StaxWriter(XMLStreamWriter out) throws XMLStreamException {
        this(out, true);
    }

    /**
     * Allows a StaxWriter to be created for partial XML output
     *
     * @param out the stream to output to
     * @param writeStartDocument a flag to indicate whether or not the start/end document events should be written
     * @throws XMLStreamException if the events could not be written to the output
     */
    public StaxWriter(XMLStreamWriter out, boolean writeStartDocument) throws XMLStreamException {
        this.out = out;
        this.writeStartDocument = writeStartDocument;
        if (writeStartDocument) {
            out.writeStartDocument();
        }
    }

    /**
     * Call this method when you're finished with me
     */
    public void close() {
        try {
            if (writeStartDocument) {
                out.writeEndDocument();
            }
            out.close();
        }
        catch (XMLStreamException e) {
            throw new StreamException(e);
        }
    }

    public void addAttribute(String name, String value) {
        try {
            out.writeAttribute(name, value);
        }
        catch (XMLStreamException e) {
{'fraction_non_alphanumeric': 0.08216216216216216, 'fraction_numerical': 0.001081081081081081, 'mean_word_length': 2.5681233933161955, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6540787', 'n_tokens_mistral': 753, 'n_tokens_neox': 732, 'n_words': 211}