Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static byte[] IpPortStringToBytes(String ipportString) {
        String[] strs = ipportString.substring(0, ipportString.indexOf(":")).split("[.]");
        byte[] b = new byte[strs.length + 2];
        int index = 0;

        for (String str : strs) {
            b[index++] = (byte) (Integer.parseInt(str));
        }
        String[] port = ipportString.split("[:]");
        b[index++] = (byte) ((Integer.parseInt(port[1]) & 0x00FF));
        b[index++] = (byte) ((Integer.parseInt(port[1]) & 0xFF00) >> 8);
        return b;
    }
}