<commit_before>// Copyright (c) 1999 <NAME> (<EMAIL>)
// Portions Copyright (c) 1999 Network Associates, Inc.

package org.xbill.DNS;

import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import org.xbill.DNS.utils.*;

/**
 * The base class that all records are derived from.
 *
 * @author <NAME>
 */

abstract public class Record implements Cloneable {

protected Name name;
protected short type, dclass;
protected int ttl;
protected int wireLength = -1;

private	static Class [] knownTypes = new Class[256];

private static Class [] fromWireList = new Class [] {Name.class,
                                                     Short.TYPE,
                                                     Integer.TYPE,
                                                     Integer.TYPE,
                                                     DataByteInputStream.class,
                                                     Compression.class};
private static Class [] fromTextList = new Class [] {Name.class,
						     Short.TYPE,
						     Integer.TYPE,
						     MyStringTokenizer.class,
						     Name.class};

protected
Record() {}

Record(Name _name, short _type, short _dclass, int _ttl) {
	name = _name;
	type = _type;
	dclass = _dclass;
	ttl = _ttl;
}

private static final Class
toClass(short type) throws ClassNotFoundException {
	/*
	 * First, see if we've already found this type.
	 */
	if (type < 0 || type > 255)
		throw new ClassNotFoundException();
	if (knownTypes[type] != null)
		return knownTypes[type];

	String s = Record.class.toString();
	/*
	 * Remove "class " from the beginning, and "Record" from the end.
	 * Then construct the new class name.
	 */
	knownTypes[type] = Class.forName(s.substring(6, s.length() - 6) +
					 Type.string(type) + "Record");
	return knownTypes[type];
}

private static Record
newRecord(Name name, short type, short dclass, int ttl, int length,
	  DataByteInputStream in, Compression c) throws IOException
{
	Record rec;
	int recstart = in.getPos();

	try {
		Class rrclass;
		Constructor m;

		rrclass = toClass(type);
		m = rrclass.getDeclaredConstructor(fromWireList);
		rec = (Record) m.newInstance(new Object [] {
							name,
							new Short(dclass),
							new Integer(ttl),
							new Integer(length),
							in, c
						});
	}
	catch (ClassNotFoundException e) {
		rec = new UNKRecord(name, type, dclass, ttl, length, in, c);
	}
	catch (InvocationTargetException e) {
		if (e.getTargetException() instanceof IOException)
			throw (IOException) e.getTargetException();
		if (Options.check("verbose")) {
			System.err.println("new record: " + e);
			System.err.println(e.getTargetException());
		}
		return null;
	}
	catch (Exception e) {
		if (Options.check("verbose"))
			System.err.println("new record: " + e);
		return null;
	}
	if (in.getPos() - recstart != length)
		throw new IOException("Invalid record length");
	rec.wireLength = length;
	return rec;
}

/**
 * Creates a new record, with the given parameters.
 * @return An object of a type extending Record
 */
public static Record
newRecord(Name name, short type, short dclass, int ttl, int length,
	  byte [] data)
{
	DataByteInputStream dbs;
	if (data != null)
		dbs = new DataByteInputStream(data);
	else
		dbs = null;
	try {
		return newRecord(name, type, dclass, ttl, length, dbs, null);
	}
	catch (IOException e) {
		return null;<commit_msg>The change to clean up record length verification broke records in the question section.<commit_after>// Copyright (c) 1999 <NAME> (<EMAIL>)
// Portions Copyright (c) 1999 Network Associates, Inc.

package org.xbill.DNS;

import java.io.*;
import java.lang.reflect.*;
import java.util.*;
import org.xbill.DNS.utils.*;

/**
 * The base class that all records are derived from.
 *
 * @author <NAME>
 */

abstract public class Record implements Cloneable {

protected Name name;
protected short type, dclass;
protected int ttl;
protected int wireLength = -1;

private	static Class [] knownTypes = new Class[256];

private static Class [] fromWireList = new Class [] {Name.class,
                                                     Short.TYPE,
                                                     Integer.TYPE,
                                                     Integer.TYPE,
                                                     DataByteInputStream.class,
                                                     Compression.class};
private static Class [] fromTextList = new Class [] {Name.class,
						     Short.TYPE,
						     Integer.TYPE,
						     MyStringTokenizer.class,
						     Name.class};

protected
Record() {}

Record(Name _name, short _type, short _dclass, int _ttl) {
	name = _name;
	type = _type;
	dclass = _dclass;
	ttl = _ttl;
}

private static final Class
toClass(short type) throws ClassNotFoundException {
	/*
	 * First, see if we've already found this type.
	 */
	if (type < 0 || type > 255)
		throw new ClassNotFoundException();
	if (knownTypes[type] != null)
		return knownTypes[type];

	String s = Record.class.toString();
	/*
	 * Remove "class " from the beginning, and "Record" from the end.
	 * Then construct the new class name.
	 */
	knownTypes[type] = Class.forName(s.substring(6, s.length() - 6) +
					 Type.string(type) + "Record");
	return knownTypes[type];
}

private static Record
newRecord(Name name, short type, short dclass, int ttl, int length,
	  DataByteInputStream in, Compression c) throws IOException
{
	Record rec;
	int recstart;
	if (in == null)
		recstart = 0;
	else
		recstart = in.getPos();

	try {
		Class rrclass;
		Constructor m;

		rrclass = toClass(type);
		m = rrclass.getDeclaredConstructor(fromWireList);
		rec = (Record) m.newInstance(new Object [] {
							name,
							new Short(dclass),
							new Integer(ttl),
							new Integer(length),
							in, c
						});
	}
	catch (ClassNotFoundException e) {
		rec = new UNKRecord(name, type, dclass, ttl, length, in, c);
	}
	catch (InvocationTargetException e) {
		if (e.getTargetException() instanceof IOException)
			throw (IOException) e.getTargetException();
		if (Options.check("verbose")) {
			System.err.println("new record: " + e);
			System.err.println(e.getTargetException());
		}
		return null;
	}
	catch (Exception e) {
		if (Options.check("verbose"))
			System.err.println("new record: " + e);
		return null;
	}
	if (in != null && in.getPos() - recstart != length)
		throw new IOException("Invalid record length");
	rec.wireLength = length;
	return rec;
}

/**
 * Creates a new record, with the given parameters.
 * @return An object of a type extending Record
 */
public static Record
newRecord(Name name, short type, short dclass, int ttl, int length,
	  byte [] data)
{
	DataByteInputStream dbs;
	if (data != null)
		dbs = new DataByteInputStream(data);
	else
		dbs = null;
	try {
		return newRecord(name, type, dclass, ttl, length, dbs, null);
	}
	catch (IOException e) {
		return null;
{'fraction_non_alphanumeric': 0.11421098517872712, 'fraction_numerical': 0.005376344086021506, 'mean_word_length': 2.6226315789473684, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1174253', 'n_tokens_mistral': 2254, 'n_tokens_neox': 2007, 'n_words': 645}