<commit_before>package polyglot.util;

import polyglot.main.Report;
import polyglot.types.*;

import java.io.*;
import java.util.zip.*;

/**
 * The <code>TypeEncoder</code> gives the ability to encode a polyglot 
 * <code>Type</code> as a Java string.
 * <p>
 * It uses a form of serialization to encode the <code>Type</code> into
 * a byte stream and then converts the byte stream to a standard Java string.
 * <p>
 * The difference between the encoder and a normal serialization process is
 * that in order to encode this type, we need to sever any links to other types
 * in the current environment. So any <code>ClassType</code> other than the 
 * the type being encoded is replaced in the stream with a 
 * <code>PlaceHolder</code> that contains the name of the class. To aid
 * in the decoding process, placeholders for member classes user their 
 * "mangled" name; non-member classes use their fully qualified name.
 */
public class TypeEncoder
{
  protected TypeSystem ts;
  protected final boolean zip = true;
  protected final boolean base64 = true;
  protected final boolean test = false;

  public TypeEncoder( TypeSystem ts)
  {
    this.ts = ts;
  }

  public String encode( Type t) throws IOException
  {
    ByteArrayOutputStream baos;
    ObjectOutputStream oos;

    if (Report.should_report(Report.serialize, 1)) {
      Report.report(1, "Encoding type " + t);
    }
    
    baos = new ByteArrayOutputStream();

    if (zip) {
	oos = new TypeOutputStream( new GZIPOutputStream( baos), ts, t);
    }
    else {<commit_msg>Disabled gzipping of serialized types since Base64 does it also.<commit_after>package polyglot.util;

import polyglot.main.Report;
import polyglot.types.*;

import java.io.*;
import java.util.zip.*;

/**
 * The <code>TypeEncoder</code> gives the ability to encode a polyglot 
 * <code>Type</code> as a Java string.
 * <p>
 * It uses a form of serialization to encode the <code>Type</code> into
 * a byte stream and then converts the byte stream to a standard Java string.
 * <p>
 * The difference between the encoder and a normal serialization process is
 * that in order to encode this type, we need to sever any links to other types
 * in the current environment. So any <code>ClassType</code> other than the 
 * the type being encoded is replaced in the stream with a 
 * <code>PlaceHolder</code> that contains the name of the class. To aid
 * in the decoding process, placeholders for member classes user their 
 * "mangled" name; non-member classes use their fully qualified name.
 */
public class TypeEncoder
{
  protected TypeSystem ts;
  protected final boolean zip = false;
  protected final boolean base64 = true;
  protected final boolean test = false;

  public TypeEncoder( TypeSystem ts)
  {
    this.ts = ts;
  }

  public String encode( Type t) throws IOException
  {
    ByteArrayOutputStream baos;
    ObjectOutputStream oos;

    if (Report.should_report(Report.serialize, 1)) {
      Report.report(1, "Encoding type " + t);
    }
    
    baos = new ByteArrayOutputStream();

    if (zip) {
	oos = new TypeOutputStream( new GZIPOutputStream( baos), ts, t);
    }
    else {
{'fraction_non_alphanumeric': 0.08519463943841736, 'fraction_numerical': 0.003190810465858328, 'mean_word_length': 3.5900439238653004, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2996205', 'n_tokens_mistral': 902, 'n_tokens_neox': 874, 'n_words': 383}