Package de.fhkn.in.uce.stun.util

Examples of de.fhkn.in.uce.stun.util.MessageFormatException


    private void checkHeaderLength(final byte[] encodedHeader) throws MessageFormatException {
        if (encodedHeader == null) {
            throw new NullPointerException();
        } else if (encodedHeader.length != HEADER_LENGTH) {
            throw new MessageFormatException("Header has not the expected length."); //$NON-NLS-1$
        }
    }
View Full Code Here


    }

    private void decodeLeadingZeroBits(final int leading32Bits) throws MessageFormatException {
        final int leadingZeroBits = (leading32Bits & LEADING_ZEROS_MASK) >> LEADING_ZEROS_SHIFT;
        if (leadingZeroBits != 0) {
            throw new MessageFormatException("The most significant two bits must be zero but were " + leadingZeroBits); //$NON-NLS-1$
        }
    }
View Full Code Here

        final int messageMethodBits = messageTypeBits & MESSAGE_METHOD_MASK;
        MessageMethod result = this.decodeMessageMethodWithCommonDecoder(messageMethodBits);
        if (result == null) {
            result = this.decodeMessageMethodWithCustomDecoders(messageMethodBits);
            if (result == null) {
                throw new MessageFormatException("Unknown message: " + messageMethodBits); //$NON-NLS-1$
            }
        }
        return result;
    }
View Full Code Here

        return result;
    }

    private void checkMagicCookie(final int toCheck) throws MessageFormatException {
        if (toCheck != MessageHeader.MAGIC_COOKIE) {
            throw new MessageFormatException("The magic cookie is wrong: " + toCheck); //$NON-NLS-1$
        }
    }
View Full Code Here

            dout.writeInt(leading32bits);
            dout.writeInt(MessageHeader.MAGIC_COOKIE);
            dout.write(this.transactionId);
            final byte[] headerAsBytes = bout.toByteArray();
            if (headerAsBytes.length != HEADER_LENGTH) {
                throw new MessageFormatException("Header has the wrong length: " + headerAsBytes.length); //$NON-NLS-1$
            }

            out.write(bout.toByteArray());
            out.flush();
        }
View Full Code Here

        return new OtherAddress(new InetSocketAddress(address, port));
    }

    private static void checkLeadingZeros(final int leadingZeroBits) throws MessageFormatException {
        if (leadingZeroBits != 0) {
            throw new MessageFormatException("Wrong message format, the leading zeros were " + leadingZeroBits); //$NON-NLS-1$
        }
    }
View Full Code Here

        if (ipFamilyBits == IPV4_FAMILY) {
            bytesForIp = new byte[4];
        } else if (ipFamilyBits == IPV6_FAMILY) {
            bytesForIp = new byte[16];
        } else {
            throw new MessageFormatException("Unknown address family " + ipFamilyBits); //$NON-NLS-1$
        }
        return bytesForIp;
    }
View Full Code Here

        if (message.hasAttribute(NATTraversalTechniqueAttribute.class)) {
            final NATTraversalTechniqueAttribute usedTechAttr = message
                    .getAttribute(NATTraversalTechniqueAttribute.class);
            result = this.registry.getNATTraversalTechniqueByEncoding(usedTechAttr.getEncoded());
        } else {
            throw new MessageFormatException("NATTraversalTechniqueAttriute not included in message"); //$NON-NLS-1$
        }
        return result;
    }
View Full Code Here

        return reader.readSTUNMessage(in);
    }

    private InetSocketAddress getAlternateSTUNServerAddressFromMessage(final Message message) throws Exception {
        if (!message.hasAttribute(OtherAddress.class)) {
            throw new MessageFormatException("The required OTHER-ADDRESS attribute is not provided.");
        }
        final OtherAddress otherAddress = message.getAttribute(OtherAddress.class);
        return otherAddress.getEndpoint();
    }
View Full Code Here

        final int filteringRealizationBits = din.readUnsignedByte();
        final NATFeatureRealization filteringRealization = NATFeatureRealization.fromEncoded(filteringRealizationBits);

        if (null == mappingFeature || !mappingFeature.equals(NATFeature.MAPPING) || null == filteringFeature
                || !filteringFeature.equals(NATFeature.FILTERING)) {
            throw new MessageFormatException("Could not encode the NAT feature attributes."); //$NON-NLS-1$
        }

        if (null == mappingRealization || null == filteringRealization) {
            throw new MessageFormatException("Could not get the realization of a NAT feature"); //$NON-NLS-1$
        }

        return new NATBehavior(mappingRealization, filteringRealization);
    }
View Full Code Here

TOP

Related Classes of de.fhkn.in.uce.stun.util.MessageFormatException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.