⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 record.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}	if (!hasEscapes) {		if (array.length > 255) {			throw new TextParseException("text string too long");		}		return array;	}	ByteArrayOutputStream os = new ByteArrayOutputStream();	int digits = 0;	int intval = 0;	for (int i = 0; i < array.length; i++) {		byte b = array[i];		if (escaped) {			if (b >= '0' && b <= '9' && digits < 3) {				digits++; 				intval *= 10;				intval += (b - '0');				if (intval > 255)					throw new TextParseException								("bad escape");				if (digits < 3)					continue;				b = (byte) intval;			}			else if (digits > 0 && digits < 3)				throw new TextParseException("bad escape");			os.write(b);			escaped = false;		}		else if (array[i] == '\\') {			escaped = true;			digits = 0;			intval = 0;		}		else			os.write(array[i]);	}	if (digits > 0 && digits < 3)		throw new TextParseException("bad escape");	array = os.toByteArray();	if (array.length > 255) {		throw new TextParseException("text string too long");	}	return os.toByteArray();}/** * Converts a byte array into a String. */protected static StringbyteArrayToString(byte [] array, boolean quote) {	StringBuffer sb = new StringBuffer();	if (quote)		sb.append('"');	for (int i = 0; i < array.length; i++) {		int b = array[i] & 0xFF;		if (b < 0x20 || b >= 0x7f) {			sb.append('\\');			sb.append(byteFormat.format(b));		} else if (b == '"' || b == ';' || b == '\\') {			sb.append('\\');			sb.append((char)b);		} else			sb.append((char)b);	}	if (quote)		sb.append('"');	return sb.toString();}/** * Converts a byte array into the unknown RR format. */protected static StringunknownToString(byte [] data) {	StringBuffer sb = new StringBuffer();	sb.append("\\# ");	sb.append(data.length);	sb.append(" ");	sb.append(base16.toString(data));	return sb.toString();}/** * Builds a new Record from its textual representation * @param name The owner name of the record. * @param type The record's type. * @param dclass The record's class. * @param ttl The record's time to live. * @param st A tokenizer containing the textual representation of the rdata. * @param origin The default origin to be appended to relative domain names. * @return The new record * @throws IOException The text format was invalid. */public static RecordfromString(Name name, int type, int dclass, long ttl, Tokenizer st, Name origin)throws IOException{	Record rec;	if (!name.isAbsolute())		throw new RelativeNameException(name);	Type.check(type);	DClass.check(dclass);	TTL.check(ttl);	Tokenizer.Token t = st.get();	if (t.type == Tokenizer.IDENTIFIER && t.value.equals("\\#")) {		int length = st.getUInt16();		byte [] data = st.getHex();		if (data == null) {			data = new byte[0];		}		if (length != data.length)			throw st.exception("invalid unknown RR encoding: " +					   "length mismatch");		DNSInput in = new DNSInput(data);		return newRecord(name, type, dclass, ttl, length, in);	}	st.unget();	rec = getEmptyRecord(name, type, dclass, ttl, true);	rec.rdataFromString(st, origin);	t = st.get();	if (t.type != Tokenizer.EOL && t.type != Tokenizer.EOF) {		throw st.exception("unexpected tokens at end of record");	}	return rec;}/** * Builds a new Record from its textual representation * @param name The owner name of the record. * @param type The record's type. * @param dclass The record's class. * @param ttl The record's time to live. * @param s The textual representation of the rdata. * @param origin The default origin to be appended to relative domain names. * @return The new record * @throws IOException The text format was invalid. */public static RecordfromString(Name name, int type, int dclass, long ttl, String s, Name origin)throws IOException{	return fromString(name, type, dclass, ttl, new Tokenizer(s), origin);}/** * Returns the record's name * @see Name */public NamegetName() {	return name;}/** * Returns the record's type * @see Type */public intgetType() {	return type;}/** * Returns the type of RRset that this record would belong to.  For all types * except SIGRecord, this is equivalent to getType(). * @return The type of record, if not SIGRecord.  If the type is SIGRecord, * the type covered is returned. * @see Type * @see RRset * @see SIGRecord */public intgetRRsetType() {	if (type == Type.SIG || type == Type.RRSIG) {		SIGBase sig = (SIGBase) this;		return sig.getTypeCovered();	}	return type;}/** * Returns the record's class */public intgetDClass() {	return dclass;}/** * Returns the record's TTL */public longgetTTL() {	return ttl;}/** * Converts the type-specific RR to wire format - must be overriden */abstract voidrrToWire(DNSOutput out, Compression c, boolean canonical);/** * Determines if two Records could be part of the same RRset. * This compares the name, type, and class of the Records; the ttl and * rdata are not compared. */public booleansameRRset(Record rec) {	return (getRRsetType() == rec.getRRsetType() &&		dclass == rec.dclass &&		name.equals(rec.name));}/** * Determines if two Records are identical.  This compares the name, type, * class, and rdata (with names canonicalized).  The TTLs are not compared. * @param arg The record to compare to * @return true if the records are equal, false otherwise. */public booleanequals(Object arg) {	if (arg == null || !(arg instanceof Record))		return false;	Record r = (Record) arg;	if (type != r.type || dclass != r.dclass || !name.equals(r.name))		return false;	byte [] array1 = rdataToWireCanonical();	byte [] array2 = r.rdataToWireCanonical();	return Arrays.equals(array1, array2);}/** * Generates a hash code based on the Record's data. */public inthashCode() {	byte [] array = toWireCanonical(true);	int code = 0;	for (int i = 0; i < array.length; i++)		code += ((code << 3) + (array[i] & 0xFF));	return code;}RecordcloneRecord() {	try {		return (Record) clone();	}	catch (CloneNotSupportedException e) {		throw new IllegalStateException();	}}/** * Creates a new record identical to the current record, but with a different * name.  This is most useful for replacing the name of a wildcard record. */public RecordwithName(Name name) {	if (!name.isAbsolute())		throw new RelativeNameException(name);	Record rec = cloneRecord();	rec.name = name;	return rec;}/** * Creates a new record identical to the current record, but with a different * class and ttl.  This is most useful for dynamic update. */RecordwithDClass(int dclass, long ttl) {	Record rec = cloneRecord();	rec.dclass = dclass;	rec.ttl = ttl;	return rec;}/* Sets the TTL to the specified value.  This is intentionally not public. */voidsetTTL(long ttl) {	this.ttl = ttl;}/** * Compares this Record to another Object. * @param o The Object to be compared. * @return The value 0 if the argument is a record equivalent to this record; * a value less than 0 if the argument is less than this record in the * canonical ordering, and a value greater than 0 if the argument is greater * than this record in the canonical ordering.  The canonical ordering * is defined to compare by name, class, type, and rdata. * @throws ClassCastException if the argument is not a Record. */public intcompareTo(Object o) {	Record arg = (Record) o;	if (this == arg)		return (0);	int n = name.compareTo(arg.name);	if (n != 0)		return (n);	n = dclass - arg.dclass;	if (n != 0)		return (n);	n = type - arg.type;	if (n != 0)		return (n);	byte [] rdata1 = rdataToWireCanonical();	byte [] rdata2 = arg.rdataToWireCanonical();	for (int i = 0; i < rdata1.length && i < rdata2.length; i++) {		n = (rdata1[i] & 0xFF) - (rdata2[i] & 0xFF);		if (n != 0)			return (n);	}	return (rdata1.length - rdata2.length);}/** * Returns the name for which additional data processing should be done * for this record.  This can be used both for building responses and * parsing responses. * @return The name to used for additional data processing, or null if this * record type does not require additional data processing. */public NamegetAdditionalName() {	return null;}/* Checks that an int contains an unsigned 8 bit value */static intcheckU8(String field, int val) {	if (val < 0 || val > 0xFF)		throw new IllegalArgumentException("\"" + field + "\" " + val + 						   " must be an unsigned 8 " +						   "bit value");	return val;}/* Checks that an int contains an unsigned 16 bit value */static intcheckU16(String field, int val) {	if (val < 0 || val > 0xFFFF)		throw new IllegalArgumentException("\"" + field + "\" " + val + 						   " must be an unsigned 16 " +						   "bit value");	return val;}/* Checks that a long contains an unsigned 32 bit value */static longcheckU32(String field, long val) {	if (val < 0 || val > 0xFFFFFFFFL)		throw new IllegalArgumentException("\"" + field + "\" " + val + 						   " must be an unsigned 32 " +						   "bit value");	return val;}/* Checks that a name is absolute */static NamecheckName(String field, Name name) {	if (!name.isAbsolute())		throw new RelativeNameException(name);	return name;}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -