I have a character array that can hold maximum 50000 characters at a time. Contents of this array are coming through socket connections. However it is not guaranteed that th
Correct way to read from an InputStream
in a buffer is as follows.
public String readBufferUpdate() throws IOException {
char[] buffer =new char[50000];
int bytesRead = is.read(buffer, 0, buffer.length);
return new String(buffer, 0, bytesRead);
}
Here you is.read()
returns how many bytes have been read into bytesRead
. Only that many bytes are copied from the buffer to String
.