<commit_before>package retrofit.converter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Type;

import org.simpleframework.xml.core.Persister;
import org.simpleframework.xml.Serializer;

import retrofit.mime.TypedByteArray;
import retrofit.mime.TypedInput;
import retrofit.mime.TypedOutput;

/**
 * A {@link Converter} which uses SimpleXML for reading and writing entities.
 *
 * @author <NAME> (<EMAIL>)
 */
public class SimpleXMLConverter implements Converter {
  private static final String CHARSET = "UTF-8";
  private static final String MIME_TYPE = "application/xml; charset=" + CHARSET;

  private final Serializer serializer;

  public SimpleXMLConverter() {
    this(new Persister());
  }

  public SimpleXMLConverter(Serializer serializer) {
    this.serializer = serializer;
  }

  @Override
  public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
      return serializer.read((Class<?>) type, body.in());
    } catch (Exception e) {
      throw new ConversionException(e);
    }
  }

  @Override
  public TypedOutput toBody(Object source) {
    OutputStreamWriter osw = null;

    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      osw = new OutputStreamWriter(bos, CHARSET);
      serializer.write(source, osw);
      osw.flush();
      return new TypedByteArray(MIME_TYPE, bos.toByteArray());
    } catch (Exception e) {
      throw new AssertionError(e);<commit_msg>Style tweak.<commit_after>package retrofit.converter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Type;

import org.simpleframework.xml.core.Persister;
import org.simpleframework.xml.Serializer;

import retrofit.mime.TypedByteArray;
import retrofit.mime.TypedInput;
import retrofit.mime.TypedOutput;

/**
 * A {@link Converter} which uses SimpleXML for reading and writing entities.
 *
 * @author <NAME> (<EMAIL>)
 */
public class SimpleXMLConverter implements Converter {
  private static final String CHARSET = "UTF-8";
  private static final String MIME_TYPE = "application/xml; charset=" + CHARSET;

  private final Serializer serializer;

  public SimpleXMLConverter() {
    this(new Persister());
  }

  public SimpleXMLConverter(Serializer serializer) {
    this.serializer = serializer;
  }

  @Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
      return serializer.read((Class<?>) type, body.in());
    } catch (Exception e) {
      throw new ConversionException(e);
    }
  }

  @Override public TypedOutput toBody(Object source) {
    OutputStreamWriter osw = null;

    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      osw = new OutputStreamWriter(bos, CHARSET);
      serializer.write(source, osw);
      osw.flush();
      return new TypedByteArray(MIME_TYPE, bos.toByteArray());
    } catch (Exception e) {
      throw new AssertionError(e);
{'fraction_non_alphanumeric': 0.10102007239223429, 'fraction_numerical': 0.0006581112207963146, 'mean_word_length': 4.178875638841567, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1895145', 'n_tokens_mistral': 891, 'n_tokens_neox': 865, 'n_words': 232}