/** * 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 IpV4EndOfOptionList. * @throws IllegalRawDataException if parsing the raw data fails. */ public static IpV4EndOfOptionList newInstance(byte[] rawData, int offset, int length) throws IllegalRawDataException { ByteArrays.validateBounds(rawData, offset, length); if (rawData[0 + offset] != type.value()) { StringBuilder sb = new StringBuilder(100); sb.append("The type must be: ") .append(type.valueAsString()) .append(" rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } return INSTANCE; }
/** * @param value value * @return a IpV4OptionType object. */ public static IpV4OptionType getInstance(Byte value) { if (registry.containsKey(value)) { return registry.get(value); } else { return new IpV4OptionType(value, "unknown"); } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } IllegalIpV4Option other = (IllegalIpV4Option) obj; return type.equals(other.type) && Arrays.equals(other.rawData, rawData); }
/** * @param type type * @return a IpV4OptionType object. */ public static IpV4OptionType register(IpV4OptionType type) { return registry.put(type.value(), type); }
/** * @param type type * @return a class which implements IpV4Option for a specified type. */ public Class<? extends IpV4Option> getIpV4OptionClass(IpV4OptionType type) { StringBuilder sb = new StringBuilder(120); sb.append(IPV4_OPTION_CLASS_KEY_BASE) .append(type.getClass().getName()) .append(".") .append(type.valueAsString()); return loader.<IpV4Option>getClass(sb.toString(), getUnknownIpV4OptionClass()); }
try { while (currentOffsetInHeader < headerLength) { IpV4OptionType type = IpV4OptionType.getInstance(rawData[currentOffsetInHeader + offset]); IpV4Option newOne; newOne = currentOffsetInHeader += newOne.length(); if (newOne.getType().equals(IpV4OptionType.END_OF_OPTION_LIST)) { break;
@Override public int hashCode() { int result = 17; result = 31 * result + type.hashCode(); result = 31 * result + Arrays.hashCode(rawData); return result; }
private IllegalIpV4Option(byte[] rawData, int offset, int length) { this.type = IpV4OptionType.getInstance(rawData[offset]); this.rawData = new byte[length]; System.arraycopy(rawData, offset, this.rawData, 0, length); }
/** */ @Override public String valueAsString() { return String.valueOf(value() & 0xFF); }
/** * @param type type * @return a class which implements IpV4Option for a specified type. */ public Class<? extends IpV4Option> getIpV4OptionClass(IpV4OptionType type) { StringBuilder sb = new StringBuilder(120); sb.append(IPV4_OPTION_CLASS_KEY_BASE) .append(type.getClass().getName()) .append(".") .append(type.valueAsString()); return loader.<IpV4Option>getClass(sb.toString(), getUnknownIpV4OptionClass()); }
try { while (currentOffsetInHeader < headerLength) { IpV4OptionType type = IpV4OptionType.getInstance(rawData[currentOffsetInHeader + offset]); IpV4Option newOne; newOne = currentOffsetInHeader += newOne.length(); if (newOne.getType().equals(IpV4OptionType.END_OF_OPTION_LIST)) { break;
@Override public int hashCode() { int result = 17; result = 31 * result + type.hashCode(); result = 31 * result + length; result = 31 * result + Arrays.hashCode(data); return result; }
private UnknownIpV4Option(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 = IpV4OptionType.getInstance(rawData[offset]); this.length = rawData[1 + offset]; int lengthFieldAsInt = getLengthAsInt(); if (length < lengthFieldAsInt) { StringBuilder sb = new StringBuilder(100); sb.append("The raw data is too short to build this option (") .append(lengthFieldAsInt) .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, lengthFieldAsInt - 2); }
/** * 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 IpV4NoOperationOption. * @throws IllegalRawDataException if parsing the raw data fails. */ public static IpV4NoOperationOption 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, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } return getInstance(); }
@Override public int hashCode() { int result = 17; result = 31 * result + type.hashCode(); result = 31 * result + Arrays.hashCode(rawData); return result; }
private IllegalIpV4Option(byte[] rawData, int offset, int length) { this.type = IpV4OptionType.getInstance(rawData[offset]); this.rawData = new byte[length]; System.arraycopy(rawData, offset, this.rawData, 0, length); }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!this.getClass().isInstance(obj)) { return false; } UnknownIpV4Option other = (UnknownIpV4Option) obj; return type.equals(other.type) && length == other.length && Arrays.equals(data, other.data); }
/** * @param value value * @return a IpV4OptionType object. */ public static IpV4OptionType getInstance(Byte value) { if (registry.containsKey(value)) { return registry.get(value); } else { return new IpV4OptionType(value, "unknown"); } }
private IpV4StreamIdOption(byte[] rawData, int offset, int length) throws IllegalRawDataException { if (length < 4) { StringBuilder sb = new StringBuilder(50); sb.append("The raw data length must be more than 3. rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } if (rawData[0 + offset] != getType().value()) { StringBuilder sb = new StringBuilder(100); sb.append("The type must be: ") .append(getType().valueAsString()) .append(" rawData: ") .append(ByteArrays.toHexString(rawData, " ")) .append(", offset: ") .append(offset) .append(", length: ") .append(length); throw new IllegalRawDataException(sb.toString()); } if (rawData[1 + offset] != 4) { throw new IllegalRawDataException("Invalid value of length field: " + rawData[1 + offset]); } this.length = rawData[1 + offset]; this.streamId = ByteArrays.getShort(rawData, 2 + offset); }