List of usage examples for java.util ArrayDeque pop
public E pop()
From source file:stroom.util.StreamGrepTool.java
private void processFile(final StreamStore streamStore, final long streamId, final String match) { try {// w ww .ja v a2 s.c o m final StreamSource streamSource = streamStore.openStreamSource(streamId); if (streamSource != null) { final InputStream inputStream = streamSource.getInputStream(); // Build up 2 buffers so we can output the content either side // of // the matching line final ArrayDeque<String> preBuffer = new ArrayDeque<>(); final ArrayDeque<String> postBuffer = new ArrayDeque<>(); final LineNumberReader lineNumberReader = new LineNumberReader( new InputStreamReader(inputStream, StreamUtil.DEFAULT_CHARSET)); String aline = null; while ((aline = lineNumberReader.readLine()) != null) { String lines[] = new String[] { aline }; if (addLineBreak != null) { lines = aline.split(addLineBreak); } for (final String line : lines) { if (match == null) { System.out.println(lineNumberReader.getLineNumber() + ":" + line); } else { postBuffer.add(lineNumberReader.getLineNumber() + ":" + line); if (postBuffer.size() > 5) { final String searchLine = postBuffer.pop(); checkMatch(match, preBuffer, postBuffer, searchLine); preBuffer.add(searchLine); if (preBuffer.size() > 5) { preBuffer.pop(); } } } } } // Look at the end while (postBuffer.size() > 0) { final String searchLine = postBuffer.pop(); checkMatch(match, preBuffer, postBuffer, searchLine); preBuffer.add(searchLine); if (preBuffer.size() > 5) { preBuffer.pop(); } } inputStream.close(); streamStore.closeStreamSource(streamSource); } } catch (final Exception ex) { ex.printStackTrace(); } }