I needed this for a little project so I coded it up. I haven’t done a lot of tests but it works just fine for formatting the associative arrays I have run through it.
The class supports multi-line rows, limiting the width of the column, and automatically creating a heading based on the keys from the associative array.
Text Table Formatted Output of above example:
+----------+----+---------------------+ | COMPANY | ID | BALANCE | +----------+----+---------------------+ | AIG | 1 | -$99,999,999,999.00 | | Wachovia | 2 | -$10,000,000.00 | | HP | 3 | $555,000.000.00 | | IBM | 4 | $12,000.00 | +----------+----+---------------------+
Full class source code after the jump…
(more…)
I was working on a project in and needed to do POST as well as read the response headers.
I was unable to find a suitable class or method for this in either Groovy or Java, so I wrote this class. It opens a socket to the requested host, and writes to the socket using getOutputStream() and PrintWriter(). It reads the response from the server using DataInputStream() and getInputStream().