HCL Interview Question
Product Security EngineersCountry: India
Interview Type: In-Person
thulasi.nari, it doesn't work this way. To make it clear try to run the test below:
public class BufferLimitTest {
@Test
public void testBufferedReaderLimit() throws IOException {
byte[] arr = {1,2,3,4,5,6};
InputStream is = new ByteArrayInputStream(arr);
InputStreamReader in = new InputStreamReader(is);
BufferedReader reader = new BufferedReader(in, 1);
int size = 0;
while(reader.read() != -1) {
size++;
}
assertThat(size, is(equalTo(1)));
}
}
It fails, because during every reading operation BufferedReader invokes its private method fill() which increases the buffer size if its current value isn't enough for reading one more element.
The second parameter of the constructor is just optimization which gives an opportunity not to copy array in future if you know which size will be enough beforehand.
You define your data in json format and keep one attribute in json format as "bufferlimit":buff_limit.
- Ghosh December 03, 2014