/** * A static factory method. This method validates the arguments by {@link * ByteArrays#validateBounds(byte[], int, int)}, which may throw exceptions undocumented here. * * @param rawData rawData * @param offset offset * @param length length * @return the singleton instance of IpV6Pad1Option. * @throws IllegalRawDataException if parsing the raw data fails. */ public static IpV6Pad1Option newInstance(byte[] rawData, int offset, int length) throws IllegalRawDataException { ByteArrays.validateBounds(rawData, offset, length); if (rawData[offset] != type.value()) { StringBuilder sb = new StringBuilder(100); sb.append("The type must be: ") .append(type.valueAsString()) .append(" rawData: ") .append(ByteArrays.toHexString(rawData, " ")); throw new IllegalRawDataException(sb.toString()); } return INSTANCE; }
/** * @param value value * @return a IpV6OptionType object. */ public static IpV6OptionType getInstance(Byte value) { if (registry.containsKey(value)) { return registry.get(value); } else { return new IpV6OptionType(value, "unknown"); } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } IllegalIpV6Option other = (IllegalIpV6Option) obj; return type.equals(other.type) && Arrays.equals(other.rawData, rawData); }
/** * The chg field (The third-highest-order bit of the Option Type) * * @return true if the option data may change en-route; false the option data does not change * en-route. */ public boolean optionDataMayChange() { return (value() & 0x20) != 0; }
/** * @param type type * @return a class which implements IpV6Option for a specified type. */ public Class<? extends IpV6Option> getIpV6OptionClass(IpV6OptionType type) { StringBuilder sb = new StringBuilder(120); sb.append(IPV6_OPTION_CLASS_KEY_BASE) .append(type.getClass().getName()) .append(".") .append(type.valueAsString()); return loader.<IpV6Option>getClass(sb.toString(), getUnknownIpV6OptionClass()); }
private IllegalIpV6Option(byte[] rawData, int offset, int length) { this.type = IpV6OptionType.getInstance(rawData[offset]); this.rawData = new byte[length]; System.arraycopy(rawData, offset, this.rawData, 0, length); }
@Override public int hashCode() { int result = 17; result = 31 * result + type.hashCode(); result = 31 * result + Arrays.hashCode(rawData); return result; }
/** * @param type type * @return a IpV6OptionType object. */ public static IpV6OptionType register(IpV6OptionType type) { return registry.put(type.value(), type); }
/** * @param type type * @return a class which implements IpV6Option for a specified type. */ public Class<? extends IpV6Option> getIpV6OptionClass(IpV6OptionType type) { StringBuilder sb = new StringBuilder(120); sb.append(IPV6_OPTION_CLASS_KEY_BASE) .append(type.getClass().getName()) .append(".") .append(type.valueAsString()); return loader.<IpV6Option>getClass(sb.toString(), getUnknownIpV6OptionClass()); }
private UnknownIpV6Option(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < 2) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data length must be more than 1. rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.type = IpV6OptionType.getInstance(rawData[offset]); this.dataLen = rawData[1 + offset]; if (length - 2 < this.dataLen) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data is too short to build this option(") .append(this.dataLen + 2) .append("). data: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } this.data = ByteArrays.getSubArray(rawData, 2 + offset, dataLen); }
@Override public int hashCode() { int result = 17; result = 31 * result + type.hashCode(); result = 31 * result + dataLen; result = 31 * result + Arrays.hashCode(data); return result; }
throw new IllegalRawDataException(sb.toString()); if (rawData[offset] != type.value()) { StringBuilder sb = new StringBuilder(100); sb.append("The type must be: ") .append(type.valueAsString()) .append(" rawData: ") .append(ByteArrays.toHexString(rawData, " "))
IpV6OptionType type = IpV6OptionType.getInstance(rawData[currentOffsetInHeader + offset]); IpV6Option newOne; try {
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } UnknownIpV6Option other = (UnknownIpV6Option) obj; return type.equals(other.type) && dataLen == other.dataLen && Arrays.equals(data, other.data); }
@Override public int hashCode() { int result = 17; result = 31 * result + type.hashCode(); result = 31 * result + dataLen; result = 31 * result + Arrays.hashCode(data); return result; }
/** * @param value value * @return a IpV6OptionType object. */ public static IpV6OptionType getInstance(Byte value) { if (registry.containsKey(value)) { return registry.get(value); } else { return new IpV6OptionType(value, "unknown"); } }
/** * A static factory method. This method validates the arguments by {@link * ByteArrays#validateBounds(byte[], int, int)}, which may throw exceptions undocumented here. * * @param rawData rawData * @param offset offset * @param length length * @return the singleton instance of IpV6Pad1Option. * @throws IllegalRawDataException if parsing the raw data fails. */ public static IpV6Pad1Option newInstance(byte[] rawData, int offset, int length) throws IllegalRawDataException { ByteArrays.validateBounds(rawData, offset, length); if (rawData[offset] != type.value()) { StringBuilder sb = new StringBuilder(100); sb.append("The type must be: ") .append(type.valueAsString()) .append(" rawData: ") .append(ByteArrays.toHexString(rawData, " ")); throw new IllegalRawDataException(sb.toString()); } return INSTANCE; }
@Override public byte[] getRawData() { byte[] rawData = new byte[length()]; rawData[0] = type.value(); rawData[1] = dataLen; System.arraycopy(data, 0, rawData, 2, data.length); return rawData; }
private IllegalIpV6Option(byte[] rawData, int offset, int length) { this.type = IpV6OptionType.getInstance(rawData[offset]); this.rawData = new byte[length]; System.arraycopy(rawData, offset, this.rawData, 0, length); }