public void parseAttributes(byte[] data) throws MessageAttributeParsingException { try { byte[] lengthArray = new byte[2]; System.arraycopy(data, 2, lengthArray, 0, 2); int length = Utility.twoBytesToInteger(lengthArray); System.arraycopy(data, 4, id, 0, 16); byte[] cuttedData; int offset = 20; while (length > 0) { cuttedData = new byte[length]; System.arraycopy(data, offset, cuttedData, 0, length); MessageAttribute ma = MessageAttribute.parseCommonHeader(cuttedData); addMessageAttribute(ma); length -= ma.getLength(); offset += ma.getLength(); } } catch (UtilityException ue) { throw new MessageAttributeParsingException("Parsing error"); } }
public void parseAttributes(byte[] data) throws MessageAttributeParsingException { try { byte[] lengthArray = new byte[2]; System.arraycopy(data, 2, lengthArray, 0, 2); int length = Utility.twoBytesToInteger(lengthArray); System.arraycopy(data, 4, id, 0, 16); byte[] cuttedData; int offset = 20; while (length > 0) { cuttedData = new byte[length]; System.arraycopy(data, offset, cuttedData, 0, length); MessageAttribute ma = MessageAttribute.parseCommonHeader(cuttedData); addMessageAttribute(ma); length -= ma.getLength(); offset += ma.getLength(); } } catch (UtilityException ue) { throw new MessageAttributeParsingException("Parsing error"); } }
public static MessageHeader parseHeader(byte[] data) throws MessageHeaderParsingException { try { MessageHeader mh = new MessageHeader(); byte[] typeArray = new byte[2]; System.arraycopy(data, 0, typeArray, 0, 2); int type = Utility.twoBytesToInteger(typeArray); switch (type) { case BINDINGREQUEST: mh.setType(MessageHeaderType.BindingRequest); LOGGER.debug("Binding Request received."); break; case BINDINGRESPONSE: mh.setType(MessageHeaderType.BindingResponse); LOGGER.debug("Binding Response received."); break; case BINDINGERRORRESPONSE: mh.setType(MessageHeaderType.BindingErrorResponse); LOGGER.debug("Binding Error Response received."); break; case SHAREDSECRETREQUEST: mh.setType(MessageHeaderType.SharedSecretRequest); LOGGER.debug("Shared Secret Request received."); break; case SHAREDSECRETRESPONSE: mh.setType(MessageHeaderType.SharedSecretResponse); LOGGER.debug("Shared Secret Response received."); break; case SHAREDSECRETERRORRESPONSE: mh.setType(MessageHeaderType.SharedSecretErrorResponse); LOGGER.debug("Shared Secret Error Response received.");break; default: throw new MessageHeaderParsingException("Message type " + type + "is not supported"); } return mh; } catch (UtilityException ue) { throw new MessageHeaderParsingException("Parsing error"); } } }
public static MessageHeader parseHeader(byte[] data) throws MessageHeaderParsingException { try { MessageHeader mh = new MessageHeader(); byte[] typeArray = new byte[2]; System.arraycopy(data, 0, typeArray, 0, 2); int type = Utility.twoBytesToInteger(typeArray); switch (type) { case BINDINGREQUEST: mh.setType(MessageHeaderType.BindingRequest); LOGGER.debug("Binding Request received."); break; case BINDINGRESPONSE: mh.setType(MessageHeaderType.BindingResponse); LOGGER.debug("Binding Response received."); break; case BINDINGERRORRESPONSE: mh.setType(MessageHeaderType.BindingErrorResponse); LOGGER.debug("Binding Error Response received."); break; case SHAREDSECRETREQUEST: mh.setType(MessageHeaderType.SharedSecretRequest); LOGGER.debug("Shared Secret Request received."); break; case SHAREDSECRETRESPONSE: mh.setType(MessageHeaderType.SharedSecretResponse); LOGGER.debug("Shared Secret Response received."); break; case SHAREDSECRETERRORRESPONSE: mh.setType(MessageHeaderType.SharedSecretErrorResponse); LOGGER.debug("Shared Secret Error Response received.");break; default: throw new MessageHeaderParsingException("Message type " + type + "is not supported"); } return mh; } catch (UtilityException ue) { throw new MessageHeaderParsingException("Parsing error"); } } }
byte[] typeArray = new byte[2]; System.arraycopy(data, 0, typeArray, 0, 2); int type = Utility.twoBytesToInteger(typeArray); byte[] lengthArray = new byte[2]; System.arraycopy(data, 2, lengthArray, 0, 2); int lengthValue = Utility.twoBytesToInteger(lengthArray); byte[] valueArray = new byte[lengthValue]; System.arraycopy(data, 4, valueArray, 0, lengthValue);
byte[] typeArray = new byte[2]; System.arraycopy(data, 0, typeArray, 0, 2); int type = Utility.twoBytesToInteger(typeArray); byte[] lengthArray = new byte[2]; System.arraycopy(data, 2, lengthArray, 0, 2); int lengthValue = Utility.twoBytesToInteger(lengthArray); byte[] valueArray = new byte[lengthValue]; System.arraycopy(data, 4, valueArray, 0, lengthValue);
protected static MappedResponseChangedSourceAddressReflectedFrom parse(MappedResponseChangedSourceAddressReflectedFrom ma, byte[] data) throws MessageAttributeParsingException { try { if (data.length < 8) { throw new MessageAttributeParsingException("Data array too short"); } int family = Utility.oneByteToInteger(data[1]); if (family != 0x01) throw new MessageAttributeParsingException("Family " + family + " is not supported"); byte[] portArray = new byte[2]; System.arraycopy(data, 2, portArray, 0, 2); ma.setPort(Utility.twoBytesToInteger(portArray)); int firstOctet = Utility.oneByteToInteger(data[4]); int secondOctet = Utility.oneByteToInteger(data[5]); int thirdOctet = Utility.oneByteToInteger(data[6]); int fourthOctet = Utility.oneByteToInteger(data[7]); ma.setAddress(new Address(firstOctet, secondOctet, thirdOctet, fourthOctet)); return ma; } catch (UtilityException ue) { throw new MessageAttributeParsingException("Parsing error"); } catch (MessageAttributeException mae) { throw new MessageAttributeParsingException("Port parsing error"); } }
protected static MappedResponseChangedSourceAddressReflectedFrom parse(MappedResponseChangedSourceAddressReflectedFrom ma, byte[] data) throws MessageAttributeParsingException { try { if (data.length < 8) { throw new MessageAttributeParsingException("Data array too short"); } int family = Utility.oneByteToInteger(data[1]); if (family != 0x01) throw new MessageAttributeParsingException("Family " + family + " is not supported"); byte[] portArray = new byte[2]; System.arraycopy(data, 2, portArray, 0, 2); ma.setPort(Utility.twoBytesToInteger(portArray)); int firstOctet = Utility.oneByteToInteger(data[4]); int secondOctet = Utility.oneByteToInteger(data[5]); int thirdOctet = Utility.oneByteToInteger(data[6]); int fourthOctet = Utility.oneByteToInteger(data[7]); ma.setAddress(new Address(firstOctet, secondOctet, thirdOctet, fourthOctet)); return ma; } catch (UtilityException ue) { throw new MessageAttributeParsingException("Parsing error"); } catch (MessageAttributeException mae) { throw new MessageAttributeParsingException("Port parsing error"); } }