public static String UCS2toUTF16(byte[] input) {
        if ((input[0] & 0xff) == 0x80) {
            String outputInUTF16 = "";
            int i = 1;
            while (((input[i] & 0xff) != 0xff) && ((input[i + 1] & 0xff) != 0xff)) {
                byte[] segment = {input[i], input[i + 1]};
                int intValue = Integer.parseInt(bytesToHex(segment).replace(" ", ""), 16);
                outputInUTF16 = outputInUTF16.concat(Character.toString((char) intValue));
                i = i + 2;
            }

            return outputInUTF16;
        }

        if ((input[0] & 0xff) == 0x81) {
            String outputInUTF16 = "";
            int numberOfCharacters = input[1];
            int segmentUpper = input[2] / 16;
            int segmentLower = input[2] % 16;//bity 15-8 na int previest
            segmentUpper = segmentUpper << 11;
            segmentLower = segmentLower << 7;
            for (int i = 3; i <= numberOfCharacters + 2; i++) {
                if (input[i] < 0 /*
                         * 8th bit is set to '0'
                         */) {
                    int offset = (input[i] & 0xff) - 128;
                    int codeWord = segmentUpper + segmentLower + offset;
                    outputInUTF16 = outputInUTF16.concat(Character.toString((char) codeWord));
                } else {
                    outputInUTF16 = outputInUTF16.concat(Character.toString((char) (int) input[i]));
                }
            }
            return outputInUTF16;
        }

        if ((input[0] & 0xff) == 0x82) {
            String outputInUTF16 = "";
            int numberOfCharacters = input[1];
            byte[] segment = {input[2], input[3]};
            int intValue = Integer.parseInt(bytesToHex(segment).replace(" ", ""), 16);
            for (int i = 4; i <= numberOfCharacters + 3; i++) {
                if (input[i] < 0 /*
                         * 8th bit is set to '0'
                         */) {
                    int offset = (input[i] & 0xff) - 128;
                    int codeWord = intValue + offset;
                    outputInUTF16 = outputInUTF16.concat(Character.toString((char) codeWord));
                } else {
                    outputInUTF16 = outputInUTF16.concat(Character.toString((char) (int) input[i]));
                }
            }
            return outputInUTF16;
        }

        return "";
    }