Here you can find the source of toByteByAddress(String address)
public static byte[] toByteByAddress(String address)
//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; } }