Consider I have an enumeration:
public enum MyEnum {
SUCCESS;
}
I also have a string represented as a byte[]:
byte[] bytes = aString.getBytes(Charset.forName("UTF8"));
I need a mechanism that will combine the 2 byte[] into a single array, enum followed by the string, and retrieve the data out the other end. The only way I can think of doing this is by converting the enumeration into a known fixed size byte[]. Then when I extract the data from a given byte[], I know the first x represent the enum, and the remainder the string. Then all I need to do is convert the first part of the byte[] back into an enumeration, and the remainder into a string with:
new String(byte[],Charset)
Any helpful utilities to aid me in this?
Clarification: The mechanism needs to be very quick, and the byte[] of the string has already been supplied via another mechanism. I need to create a byte[] for the enumeration, then simply combine the two. At the other end I need to extract the byte[] for the enumeration and string into separate byte[]. I need to turn the first byte[] into the enumeration, but the second byte[] representing the string is passed to somewhere else. Thus I do not want to create a single encapsulating data class containing an enumeration and string, the overhead is too much.