Java Byte Create toByteByAddress(String address)

Here you can find the source of toByteByAddress(String address)

Description

to Byte By Address

License

Apache License

Declaration

public static byte[] toByteByAddress(String address) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static byte[] toByteByAddress(String address) {
        if (address == null) {
            throw new IllegalArgumentException("address is invalid");
        }//from ww  w  .j  a  va 2  s .  co m
        String[] ips = address.split("[.:_]");
        if (ips.length < 4) {
            throw new IllegalArgumentException("broker is invalid");
        }
        int pos = 0;
        byte[] buf;
        if (ips.length > 4) {
            buf = new byte[6];
            int port = Integer.parseInt(ips[4]);
            buf[pos++] = (byte) (port & 0xFF);
            buf[pos++] = (byte) (port >> 8 & 0xFF);
        } else {
            buf = new byte[4];
        }
        buf[pos++] = (byte) Integer.parseInt(ips[0]);
        buf[pos++] = (byte) Integer.parseInt(ips[1]);
        buf[pos++] = (byte) Integer.parseInt(ips[2]);
        buf[pos++] = (byte) Integer.parseInt(ips[3]);
        return buf;
    }
}

Related

  1. toByte(String string)
  2. toByte(String value)
  3. toByte(String value)
  4. toByte(T value)
  5. toByteBE(int value, byte[] dst, int offset)
  6. toByteByHex(String address)
  7. toByteColor(int i)
  8. toByteFromBin(String binSymbols)
  9. toByteMatrix(Number[][] matrix)