Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String getProperties(int properties) {
        StringBuilder permissionStr = new StringBuilder();
        String binaryString = Integer.toBinaryString(properties);
        binaryString = String.format("%16s", binaryString).replace(' ', '0');
        int len = binaryString.length();
        //PROPERTY_BROADCAST (0x00000001)
        if (binaryString.charAt(len - 1) == '1') {
            permissionStr.append("BROADCAST,");
        }
        //PROPERTY_READ (0x00000002)
        if (binaryString.charAt(len - 2) == '1') {
            permissionStr.append("READ,");
        }
        //PROPERTY_WRITE_NO_RESPONSE (0x00000004)
        if (binaryString.charAt(len - 3) == '1') {
            permissionStr.append("WRITE_NO_RESPONSE,");
        }
        //PROPERTY_WRITE (0x00000008)
        if (binaryString.charAt(len - 4) == '1') {
            permissionStr.append("READ_ENCRYPTED_MITM,");
        }

        //PROPERTY_NOTIFY (0x00000010)
        if (binaryString.charAt(len - 5) == '1') {
            permissionStr.append("NOTIFY,");
        }
        //PROPERTY_INDICATE (0x00000020)
        if (binaryString.charAt(len - 6) == '1') {
            permissionStr.append("INDICATE,");
        }
        //PROPERTY_SIGNED_WRITE (0x00000040)
        if (binaryString.charAt(len - 7) == '1') {
            permissionStr.append("SIGNED_WRITE,");
        }

        //PROPERTY_EXTENDED_PROPS (0x00000080)
        if (binaryString.charAt(len - 8) == '1') {
            permissionStr.append("EXTENDED_PROPS,");
        }

        String perStr = permissionStr.toString();
        if (perStr.endsWith(",")) {
            perStr = perStr.substring(0, perStr.length() - 1);
        }

        return perStr;
    }
}