To append byte or char is simple:
char chars = new char; // fill the array .. cu.clear().append(chars); // or cu.clear().append(chars, start, length);You can quickly transfer slices of a byte or char into and out of slices of a byte array or char array component, you can get the length and so on, but you cannot change the size once it has been appended: you have to truncate away the existing component and re-append to get a new size. The array component being modified does not have to be at the end of the Item currently in the Cu. Byte arrays are stored as chars with the top byte zero in the Item, and char arrays map directly. This leaves us with Items in a Cu having many zeroes in the top bytes of the Cu's internal char array, because Java chars are two-byte UTF-16. However, the upper zeroes disappear when stored in the db because of the UTF-8 encoding transparently applied to all persisted data.
The sorting semantics of the array components is not like String or Items themselves in that the length of the component is more significant than the content. In other words, two arrays with different lengths always sort with the longer later, while identical length array components sort according to the contained bytes or chars, with earlier bytes or chars most significant.
The length of char and byte components is determined by the maximum Item length of a bit more than 1600 chars, but long arrays can effectively be constructed using Index Components, and long byte and char streams can use CharacterLongObjects and BinaryLongObjects. The latter use index components plus char and byte components internally .
There is a ByteString class, but it is only used as a convenience for
holding a reference to an internal byte with offset and length.
When a ByteString is appended, a byte string component is automatically
Cu.byteStringAt(int offset) returns a new
Cu.setCharAt(int offset, char c)and various
Cu.getDirect(..)methods that can use
System.arraycopy()for chars or tight loops for bytes, which are packed into upper and lower bytes of the char inside the Item. Sometimes it is reasonable to use a prefix of component-formatted data followed by raw data for performance-critical applications that still want flexible structuring for other purposes. The cache efficiency and speed can be maximized, and the transparent ZLib/UTF-8 compression of persisted data is still used.
Cu.appendStringFromPlainText(Cu cu). Also a char can be appended using
Cu.appendStringFromPlainText(char buf, int offset, int length)without construction.