1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package Torello.Browser;

import static Torello.Java.C.BRED_BKGND;
import static Torello.Java.C.BGREEN;
import static Torello.Java.C.RESET;

import Torello.Java.StrPrint;
import Torello.Java.StrIndent;
import Torello.Java.EXCC;

import Torello.Browser.WebSocketSender;
import Torello.BuildJAR.Miscellaneous.StringIcicle;
import NeoVisionaries.WebSockets.WebSocketFrame;

import javax.json.JsonObject;

class PrintUtil
{
    private static final String abbrevStr = BGREEN + " [Shortened for Brevity] " + RESET;

    // I wrote this one later on...  I think the original was fine
    static String json2(final JsonObject jo)
    {
        final String s = jo.toString();
        final String a = StrPrint.abbrev(s, 300, true, abbrevStr, 600);
        final String w = StrPrint.wrapToIndentationPlus(a, 90, 90, 4);

        return "    " + w;
    }

    static String json(final JsonObject jo)
    {
        // NOTE: This is an "imperative" when you request long-winded HTML,
        //       this method will otherwise print hundreds, or even thousands of
        //       lines of HTML to the screen without this.
        //
        // null ==> abbrevStr, 100 ==> Max-Line-Len, 10 ==> Max-Lines,
        // true ==> Compact-Consecutive-Blank-Lines
        // 
        // 4 ==> Indent by four space chars

        return StrIndent.indent(
            StrPrint.widthHeightAbbrev(jo.toString(), " [...] ", 100, 10, true),
            4
        );
    }

    static void ERR(
            final String        CTITLE,
            final ConnRecord    connRec,
            final String        msg,
            final JsonObject    jo
        )
    {
        connRec.err(
            CTITLE + " - " + BRED_BKGND + " Error " + RESET + ' ' + msg + '\n' +
            "    " + BRED_BKGND + " JSON which was Received: " + RESET + '\n' +
            PrintUtil.json(jo) + '\n'
        );
    }

    static void ERR(
            final String        CTITLE,
            final ConnRecord    connRec,
            final String        msg,
            final JsonObject    jo,
            final Throwable     t
        )
    {
        connRec.err(
            CTITLE + " - " + BRED_BKGND + " Error " + RESET + ' ' + msg + '\n' +
            EXCC.toString(t) + '\n' +
            BRED_BKGND + " JSON which was Received: " + RESET + '\n' +
            PrintUtil.json(jo) + '\n'
        );
    }

    static String PTXT(final WebSocketFrame f)
    { return "payload: " + StrPrint.abbrev(f.getPayloadText(), 0, true, null, 50); }

}