I want to read an input stream with a buffer and append each buffer to a string until the stream is empty.
char[] buffer = new char[32];
while ((bytesRead = streamReader.read(buffer, 0, 32)) != -1)
message += new String(buffer);
I couldn't find a method of String
to append a character array directly and opted for this. Is there a way to know if this is wasting cycles copying the character array to a new string, only to immediately discard it?
This may be premature optimization but it glares at me pretty strongly.
I believe this constructor calls Arrays.copyOf()
.