HCL Interview Question for Product Security Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

You define your data in json format and keep one attribute in json format as "bufferlimit":buff_limit.

- Ghosh December 03, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

- Anton December 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

According to the javadocs and numerous comments in the Internet the only possible limit for BufferedStreams is just the size of the allocated heap.

So the only way is to write a custom implementation of limiting by overriding all read methods to check limit validity in advance.

- Anton December 26, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Set size in terms of 1024 bytes like below

Reader input = new BufferedReader(
                          new FileReader("file.txt"),
                      8 * 1024
    );

- thulasi.nari December 13, 2014 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More