    public static String byteArrayToHex(byte[] array, int length, long arrayOffset) {
        if (array == null) {
            return "";
        } 
        else {
            StringBuilder outputStringBuilder = new StringBuilder();
            for (int curOffset = 0; curOffset < length; curOffset += 16) {
                int lineLen = 16;
                if (length - curOffset < 16) {
                    lineLen = length - curOffset;
                }
                outputStringBuilder.append(String.format("0x%08x: ", arrayOffset + curOffset));
                for (int i = 0; i < 16; i++) {
                    if (i < lineLen) {        
                        int v = array[curOffset + i] & 0xFF;
                        outputStringBuilder.append(hexArray[v >>> 4]);
                        outputStringBuilder.append(hexArray[v & 0x0F]);
                    }
                    else {
                        outputStringBuilder.append("  ");
                    }
                    if (true) {
                        outputStringBuilder.append(" ");
                        if (i % 4 == 3) {
                            outputStringBuilder.append(" ");
                        }
                        if (i == 7) {
                            outputStringBuilder.append(" ");
                        }
                    }
                    else {
                        if (i % 2 == 1) {
                            outputStringBuilder.append(" ");
                        }
                    }
                }
                outputStringBuilder.append("  ");
                String ascii = new String(array, curOffset, lineLen);                
                for (int i = 0; i < 16; i++) {
                    char c = ' ';
                    if (i < lineLen) {
                        c = ascii.charAt(i);
                        int dec = (int) c;
                        if (dec < 32 || dec > 126) {
                            c = '.';
                        }
                    }
                    outputStringBuilder.append(c);    
                }
                outputStringBuilder.append("\n");
            }
            return outputStringBuilder.toString();
        }
    }

    public static String byteArrayToHex(byte[] array, int length, long arrayOffset) {
        if (array == null) {
            return "";
        } 
        else {
            StringBuilder outputStringBuilder = new StringBuilder();
            for (int curOffset = 0; curOffset < length; curOffset += 16) {
                int lineLen = 16;
                if (length - curOffset < 16) {
                    lineLen = length - curOffset;
                }
                outputStringBuilder.append(String.format("0x%08x: ", arrayOffset + curOffset));
                for (int i = 0; i < 16; i++) {
                    if (i < lineLen) {        
                        int v = array[curOffset + i] & 0xFF;
                        outputStringBuilder.append(hexArray[v >>> 4]);
                        outputStringBuilder.append(hexArray[v & 0x0F]);
                    }
                    else {
                        outputStringBuilder.append("  ");
                    }
                    if (true) {
                        outputStringBuilder.append(" ");
                        if (i % 4 == 3) {
                            outputStringBuilder.append(" ");
                        }
                        if (i == 7) {
                            outputStringBuilder.append(" ");
                        }
                    }
                    else {
                        if (i % 2 == 1) {
                            outputStringBuilder.append(" ");
                        }
                    }
                }
                outputStringBuilder.append("  ");
                String ascii = new String(array, curOffset, lineLen, java.nio.charset.StandardCharsets.US_ASCII);                
                for (int i = 0; i < 16; i++) {
                    char c = ' ';
                    if (i < ascii.length()) {
                        c = ascii.charAt(i);
                        int dec = (int) c;
                        if (dec < 32 || dec > 126) {
                            c = '.';
                        }
                    }
                    outputStringBuilder.append(c);    
                }
                outputStringBuilder.append("\n");
            }
            return outputStringBuilder.toString();
        }
    }
