In order to allow for mostly garbage-free behavior, standard Java string concatenation using the “+” operator is not ideal. Pronghorn has its own Appendables class that allows for garbage-free, single pass creation of text.
The API follows a fluent pattern where every method returns the same Appendable which was passed in. It is located in PronghornPipes.
Examples
Append Array
Append an array to a StringBuilder
byte[] a = new byte[1000];
Random r = new Random(101);
r.nextBytes(a);
StringBuilder str = new StringBuilder();
Appendables.appendArray(str, a);
StringBuilder str = new StringBuilder();
Appendables.appendFixedDecimalDigits(str, -42,10 );
Append Base64-encoded String
Creates a Base64-encoded String and appends it
String value = "Man is distinguished, not only by his reason, but by this singular passion from "
+"other animals, which is a lust of the mind, that by a perseverance of delight "
+"in the continued and indefatigable generation of knowledge, exceeds the short "
+"vehemence of any carnal pleasure.";
byte[] b = value.getBytes();
StringBuilder str = new StringBuilder();
Appendables.appendBase64(str, b, 0, b.length, Integer.MAX_VALUE);
StringBuilder str = new StringBuilder();
Appendables.appendEpochTime(str, 10000); //10 seconds
Append Hex Value
Convert an integer to its hex value and append that to the StringBuilder
StringBuilder str = new StringBuilder();
int value = 400;
Appendables.appendHexDigits(str, value);
Append Hex Fixed Value
Convert an integer to its fixed hex value and append that to the StringBuilder
StringBuilder str = new StringBuilder();
int value = 400;
int bits = 8;
Appendables.appendFixedHexDigits(str, value, bits);
Append Hex Array
Add hex array to the StringBuilder
int[] a = new int[1000];
Random rand = new Random(101);
byte [] b = new byte[1000];
rand.nextBytes(b);
for(int i = 0;i<a.length;i++){
a[i] = rand.nextInt(0x10) + 0x10; // Generates a random number between 0x10 and 0x20
}
StringBuilder str = new StringBuilder();
Appendables.appendHexArray(str, 'L', a, 0, 0xFF, 'R', a.length);