List of usage examples for java.io LineNumberReader readLine
public String readLine() throws IOException
From source file:org.apache.zookeeper.server.quorum.QuorumPeerMainTest.java
/** * Verify handling of bad quorum address *//* w w w. j a v a 2 s. c o m*/ @Test public void testBadPeerAddressInQuorum() throws Exception { ClientBase.setupTestEnv(); // setup the logger to capture all logs ByteArrayOutputStream os = new ByteArrayOutputStream(); WriterAppender appender = getConsoleAppender(os, Level.WARN); Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum"); qlogger.addAppender(appender); try { final int CLIENT_PORT_QP1 = PortAssignment.unique(); final int CLIENT_PORT_QP2 = PortAssignment.unique(); String quorumCfgSection = "server.1=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + "\nserver.2=fee.fii.foo.fum:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2; MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); q1.start(); boolean isup = ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, 30000); Assert.assertFalse("Server never came up", isup); q1.shutdown(); Assert.assertTrue("waiting for server 1 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, ClientBase.CONNECTION_TIMEOUT)); } finally { qlogger.removeAppender(appender); } LineNumberReader r = new LineNumberReader(new StringReader(os.toString())); String line; boolean found = false; Pattern p = Pattern.compile(".*Cannot open channel to .* at election address .*"); while ((line = r.readLine()) != null) { found = p.matcher(line).matches(); if (found) { break; } } Assert.assertTrue("complains about host", found); }
From source file:org.talend.designer.runprocess.java.JavaProcessor.java
/** * yzhang Comment method "updateGraphicalNodeBreaking". * /* ww w. j a va 2 s.c o m*/ * @param breakpoint */ private void updateGraphicalNodeBreaking(IJavaBreakpoint breakpoint, boolean removed) { try { Integer breakLineNumber = (Integer) breakpoint.getMarker().getAttribute(IMarker.LINE_NUMBER); if (breakLineNumber == null || breakLineNumber == -1) { return; } IFile codeFile = this.getCodeProject().getFile(this.getSrcCodePath()); if (!codeFile.exists()) { JDIDebugModel.removeJavaBreakpointListener(this); return; } LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(codeFile.getContents())); String content = null; while (lineReader.getLineNumber() < breakLineNumber - 3) { content = lineReader.readLine(); if (content == null) { return; } } int startIndex = content.indexOf("[") + 1; //$NON-NLS-1$ int endIndex = content.indexOf(" main ] start"); //$NON-NLS-1$ if (startIndex != -1 && endIndex != -1) { String nodeUniqueName = content.substring(startIndex, endIndex); List<? extends INode> breakpointNodes = CorePlugin.getContext().getBreakpointNodes(process); List<? extends INode> graphicalNodes = process.getGraphicalNodes(); if (graphicalNodes == null) { return; } for (INode node : graphicalNodes) { if (node.getUniqueName().equals(nodeUniqueName) && removed && breakpointNodes.contains(node)) { CorePlugin.getContext().removeBreakpoint(process, node); if (node instanceof Node) { final INode currentNode = node; Display.getDefault().syncExec(new Runnable() { @Override public void run() { ((Node) currentNode).removeStatus(Process.BREAKPOINT_STATUS); } }); } } else if (node.getUniqueName().equals(nodeUniqueName) && !removed && !breakpointNodes.contains(node)) { CorePlugin.getContext().addBreakpoint(process, node); if (node instanceof Node) { final INode currentNode = node; Display.getDefault().syncExec(new Runnable() { @Override public void run() { ((Node) currentNode).addStatus(Process.BREAKPOINT_STATUS); } }); } } } } } catch (CoreException e) { RuntimeExceptionHandler.process(e); } catch (IOException e) { RuntimeExceptionHandler.process(e); } }
From source file:org.apache.zookeeper.server.quorum.QuorumPeerMainTest.java
/** * Verify that a node without the leader in its view will not attempt to connect to the leader. */// ww w.j a v a 2 s . c o m @Test public void testLeaderOutOfView() throws Exception { ClientBase.setupTestEnv(); int numServers = 3; // used for assertions later boolean foundLeading = false; boolean foundFollowing = false; // capture QuorumPeer logging ByteArrayOutputStream os = new ByteArrayOutputStream(); WriterAppender appender = getConsoleAppender(os, Level.DEBUG); Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum"); qlogger.addAppender(appender); try { Servers svrs = new Servers(); svrs.clientPorts = new int[numServers]; for (int i = 0; i < numServers; i++) { svrs.clientPorts[i] = PortAssignment.unique(); } String quorumCfgIncomplete = getUniquePortCfgForId(1) + "\n" + getUniquePortCfgForId(2); String quorumCfgComplete = quorumCfgIncomplete + "\n" + getUniquePortCfgForId(3); svrs.mt = new MainThread[3]; // Node 1 is started without the leader (3) in its config view svrs.mt[0] = new MainThread(1, svrs.clientPorts[0], quorumCfgIncomplete); for (int i = 1; i < numServers; i++) { svrs.mt[i] = new MainThread(i + 1, svrs.clientPorts[i], quorumCfgComplete); } // Node 1 must be started first, before quorum is formed, to trigger the attempted invalid connection to 3 svrs.mt[0].start(); QuorumPeer quorumPeer1 = waitForQuorumPeer(svrs.mt[0], CONNECTION_TIMEOUT); Assert.assertTrue(quorumPeer1.getPeerState() == QuorumPeer.ServerState.LOOKING); // Node 3 started second to avoid 1 and 2 forming a quorum before 3 starts up int highestServerIndex = numServers - 1; svrs.mt[highestServerIndex].start(); QuorumPeer quorumPeer3 = waitForQuorumPeer(svrs.mt[highestServerIndex], CONNECTION_TIMEOUT); Assert.assertTrue(quorumPeer3.getPeerState() == QuorumPeer.ServerState.LOOKING); // Node 2 started last, kicks off leader election for (int i = 1; i < highestServerIndex; i++) { svrs.mt[i].start(); } // Nodes 2 and 3 now form quorum and fully start. 1 attempts to vote for 3, fails, returns to LOOKING state for (int i = 1; i < numServers; i++) { Assert.assertTrue("waiting for server to start", ClientBase.waitForServerUp("127.0.0.1:" + svrs.clientPorts[i], CONNECTION_TIMEOUT)); } Assert.assertTrue(svrs.mt[0].getQuorumPeer().getPeerState() == QuorumPeer.ServerState.LOOKING); Assert.assertTrue( svrs.mt[highestServerIndex].getQuorumPeer().getPeerState() == QuorumPeer.ServerState.LEADING); for (int i = 1; i < highestServerIndex; i++) { Assert.assertTrue(svrs.mt[i].getQuorumPeer().getPeerState() == QuorumPeer.ServerState.FOLLOWING); } // Look through the logs for output that indicates Node 1 is LEADING or FOLLOWING LineNumberReader r = new LineNumberReader(new StringReader(os.toString())); Pattern leading = Pattern.compile(".*myid=1.*QuorumPeer.*LEADING.*"); Pattern following = Pattern.compile(".*myid=1.*QuorumPeer.*FOLLOWING.*"); String line; while ((line = r.readLine()) != null && !foundLeading && !foundFollowing) { foundLeading = leading.matcher(line).matches(); foundFollowing = following.matcher(line).matches(); } } finally { qlogger.removeAppender(appender); } Assert.assertFalse("Corrupt peer should never become leader", foundLeading); Assert.assertFalse("Corrupt peer should not attempt connection to out of view leader", foundFollowing); }
From source file:massbank.BatchSearchWorker.java
/** * Ytt@C???ieLXg`?j//from w w w.j a v a 2 s . c o m * @param resultFile t@C * @param textFile YtpeLXgt@C */ private void createTextFile(File resultFile, File textFile) { NumberFormat nf = NumberFormat.getNumberInstance(); LineNumberReader in = null; PrintWriter out = null; try { in = new LineNumberReader(new FileReader(resultFile)); out = new PrintWriter(new BufferedWriter(new FileWriter(textFile))); // wb_?[?o String reqIonStr = "Both"; try { if (Integer.parseInt(this.ion) > 0) { reqIonStr = "Positive"; } else if (Integer.parseInt(this.ion) < 0) { reqIonStr = "Negative"; } } catch (NumberFormatException nfe) { nfe.printStackTrace(); } out.println("***** MassBank Batch Service Results *****"); out.println(); out.println("Request Date: " + this.time); out.println("# Instrument Type: " + this.inst); out.println("# MS Type: " + this.ms); out.println("# Ion Mode: " + reqIonStr); out.println(); out.println(); // ?o String line; long queryCnt = 0; boolean readName = false; boolean readHit = false; boolean readNum = false; boolean isFinalLine = false; while ((line = in.readLine()) != null) { line = line.trim(); isFinalLine = false; if (!readName) { queryCnt++; out.println("### Query " + nf.format(queryCnt) + " ###"); out.println("# Name: " + line); readName = true; } else if (!readHit) { int num = Integer.parseInt(line); if (num == -1) { out.println("[ERROR] Invalid query\n"); break; } out.println("# Hit: " + nf.format(num)); out.println(); readHit = true; } else if (!readNum) { out.println("Top " + line + " List"); out.println("Accession\tTitle\tFormula\tMass\tScore\tHit"); out.println(); readNum = true; } else { if (!line.equals("")) { String[] data = formatLine(line); StringBuilder sb = new StringBuilder(); sb.append(data[0]).append("\t").append(data[1]).append("\t").append(data[2]).append("\t") .append(data[3]).append("\t").append(data[4]).append("\t").append(data[5]); out.println(sb.toString()); } else { out.println(); out.println(); readName = false; readHit = false; readNum = false; isFinalLine = true; } } } if (!isFinalLine) { out.println(); out.println(); } out.println("***** END ********************************"); out.println(); } catch (Exception e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { } if (out != null) { out.flush(); out.close(); } } }
From source file:org.apache.zookeeper.server.quorum.QuorumPeerMainTest.java
/** * Verify handling of inconsistent peer type */// w ww . j a va 2s . c om @Test public void testInconsistentPeerType() throws Exception { ClientBase.setupTestEnv(); // setup the logger to capture all logs ByteArrayOutputStream os = new ByteArrayOutputStream(); WriterAppender appender = getConsoleAppender(os, Level.INFO); Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum"); qlogger.addAppender(appender); // test the most likely situation only: server is stated as observer in // servers list, but there's no "peerType=observer" token in config try { final int CLIENT_PORT_QP1 = PortAssignment.unique(); final int CLIENT_PORT_QP2 = PortAssignment.unique(); final int CLIENT_PORT_QP3 = PortAssignment.unique(); String quorumCfgSection = "server.1=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP1 + "\nserver.2=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ";" + CLIENT_PORT_QP2 + "\nserver.3=127.0.0.1:" + PortAssignment.unique() + ":" + PortAssignment.unique() + ":observer" + ";" + CLIENT_PORT_QP3; MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection); MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection); MainThread q3 = new MainThread(3, CLIENT_PORT_QP3, quorumCfgSection); q1.start(); q2.start(); q3.start(); Assert.assertTrue("waiting for server 1 being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1, CONNECTION_TIMEOUT)); Assert.assertTrue("waiting for server 2 being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP2, CONNECTION_TIMEOUT)); Assert.assertTrue("waiting for server 3 being up", ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP3, CONNECTION_TIMEOUT)); q1.shutdown(); q2.shutdown(); q3.shutdown(); Assert.assertTrue("waiting for server 1 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1, ClientBase.CONNECTION_TIMEOUT)); Assert.assertTrue("waiting for server 2 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP2, ClientBase.CONNECTION_TIMEOUT)); Assert.assertTrue("waiting for server 3 down", ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP3, ClientBase.CONNECTION_TIMEOUT)); } finally { qlogger.removeAppender(appender); } LineNumberReader r = new LineNumberReader(new StringReader(os.toString())); String line; boolean warningPresent = false; boolean defaultedToObserver = false; Pattern pWarn = Pattern.compile(".*Peer type from servers list.* doesn't match peerType.*"); Pattern pObserve = Pattern.compile(".*OBSERVING.*"); while ((line = r.readLine()) != null) { if (pWarn.matcher(line).matches()) { warningPresent = true; } if (pObserve.matcher(line).matches()) { defaultedToObserver = true; } if (warningPresent && defaultedToObserver) { break; } } Assert.assertTrue("Should warn about inconsistent peer type", warningPresent && defaultedToObserver); }
From source file:org.apache.zookeeper.server.quorum.QuorumPeerMainTest.java
/** * This test validates that if a quorum member determines that it is leader without the support of the rest of the * quorum (the other members do not believe it to be the leader) it will stop attempting to lead and become a follower. * * @throws IOException/*from ww w. ja v a 2s . c o m*/ * @throws InterruptedException */ @Test public void testElectionFraud() throws IOException, InterruptedException { // capture QuorumPeer logging ByteArrayOutputStream os = new ByteArrayOutputStream(); WriterAppender appender = getConsoleAppender(os, Level.INFO); Logger qlogger = Logger.getLogger(QuorumPeer.class); qlogger.addAppender(appender); numServers = 3; // used for assertions later boolean foundLeading = false; boolean foundLooking = false; boolean foundFollowing = false; try { // spin up a quorum, we use a small ticktime to make the test run faster servers = LaunchServers(numServers, 500); // find the leader int trueLeader = servers.findLeader(); Assert.assertTrue("There should be a leader", trueLeader >= 0); // find a follower int falseLeader = (trueLeader + 1) % numServers; Assert.assertTrue("All servers should join the quorum", servers.mt[falseLeader].main.quorumPeer.follower != null); // to keep the quorum peer running and force it to go into the looking state, we kill leader election // and close the connection to the leader servers.mt[falseLeader].main.quorumPeer.electionAlg.shutdown(); servers.mt[falseLeader].main.quorumPeer.follower.getSocket().close(); // wait for the falseLeader to disconnect waitForOne(servers.zk[falseLeader], States.CONNECTING); // convince falseLeader that it is the leader servers.mt[falseLeader].main.quorumPeer.setPeerState(QuorumPeer.ServerState.LEADING); // provide time for the falseleader to realize no followers have connected // (this is twice the timeout used in Leader#getEpochToPropose) Thread.sleep(2 * servers.mt[falseLeader].main.quorumPeer.initLimit * servers.mt[falseLeader].main.quorumPeer.tickTime); // Restart leader election servers.mt[falseLeader].main.quorumPeer.startLeaderElection(); // The previous client connection to falseLeader likely closed, create a new one servers.zk[falseLeader] = new ZooKeeper("127.0.0.1:" + servers.mt[falseLeader].getClientPort(), ClientBase.CONNECTION_TIMEOUT, this); // Wait for falseLeader to rejoin the quorum waitForOne(servers.zk[falseLeader], States.CONNECTED); // and ensure trueLeader is still the leader Assert.assertTrue(servers.mt[trueLeader].main.quorumPeer.leader != null); // Look through the logs for output that indicates the falseLeader is LEADING, then LOOKING, then FOLLOWING LineNumberReader r = new LineNumberReader(new StringReader(os.toString())); Pattern leading = Pattern.compile(".*myid=" + falseLeader + ".*LEADING.*"); Pattern looking = Pattern.compile(".*myid=" + falseLeader + ".*LOOKING.*"); Pattern following = Pattern.compile(".*myid=" + falseLeader + ".*FOLLOWING.*"); String line; while ((line = r.readLine()) != null) { if (!foundLeading) { foundLeading = leading.matcher(line).matches(); } else if (!foundLooking) { foundLooking = looking.matcher(line).matches(); } else if (following.matcher(line).matches()) { foundFollowing = true; break; } } } finally { qlogger.removeAppender(appender); } Assert.assertTrue("falseLeader never attempts to become leader", foundLeading); Assert.assertTrue("falseLeader never gives up on leadership", foundLooking); Assert.assertTrue("falseLeader never rejoins the quorum", foundFollowing); }
From source file:org.voltdb.compiler.DDLCompiler.java
/** * Read until the next newline/*from w w w . j a v a 2 s.c o m*/ * @throws IOException */ String readToEndOfLine(FileReader reader) throws IOException { LineNumberReader lnr = new LineNumberReader(reader); String retval = lnr.readLine(); m_currLineNo++; return retval; }
From source file:com.castis.sysComp.PoisConverterSysComp.java
public void parseRegionFile(File file) throws Exception { String line = ""; FileInputStream in = null;/* w ww.ja v a 2s. com*/ Reader isReader = null; LineNumberReader bufReader = null; FileOutputStream fos = null; String fileName = file.getName(); int index = fileName.indexOf("-"); if (index != -1) { fileName = fileName.substring(index + 1, fileName.length()); } String dir = filePolling.getValidFileDirectory(resultDir); String tempDir = dir + "/temp/"; File targetDirectory = new File(CiFileUtil.getReplaceFullPath(tempDir)); if (!targetDirectory.isDirectory()) { CiFileUtil.createDirectory(tempDir); } fos = new FileOutputStream(tempDir + fileName); int byteSize = 2048; ByteBuffer byteBuffer = ByteBuffer.allocateDirect(byteSize); GatheringByteChannel outByteCh = fos.getChannel(); try { in = new FileInputStream(file); isReader = new InputStreamReader(in, "UTF-16LE"); bufReader = new LineNumberReader(isReader); boolean first = true; while ((line = bufReader.readLine()) != null) { byte[] utf8 = line.getBytes("UTF-8"); String string = new String(utf8, "UTF-8"); String data[] = string.split("\t"); if (first == true) { first = false; if (data[0] == null || data[0].contains("region") == false) { throw new DataParsingException("data parsing error(not formatted)"); } continue; } if (data[0] == null || data[0].equals("")) { throw new DataParsingException("data parsing error(region id)"); } if (data[1] == null || data[1].equals("")) { throw new DataParsingException("data parsing error(region name)"); } if (data[2] == null || data[2].equals("")) { throw new DataParsingException("data parsing error(parent id)"); } StringBuffer strBuffer = new StringBuffer(); strBuffer.append(data[0]); strBuffer.append("\t"); strBuffer.append(data[1]); strBuffer.append("\t"); strBuffer.append(data[2]); strBuffer.append("\r\n"); byte[] outByte = null; try { outByte = strBuffer.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException e2) { e2.printStackTrace(); } byteBuffer.put(outByte); byteBuffer.flip(); try { outByteCh.write(byteBuffer); } catch (IOException e) { } byteBuffer.clear(); } fos.close(); index = fileName.indexOf("_"); String targetDir = resultDir; File sourceFile = new File(tempDir + fileName); if (index != -1) { String directory = fileName.substring(0, index); targetDir += "/" + directory; } try { File resultTargetDir = new File(CiFileUtil.getReplaceFullPath(targetDir)); if (!resultTargetDir.isDirectory()) { CiFileUtil.createDirectory(targetDir); } CiFileUtil.renameFile(sourceFile, targetDir, fileName); } catch (Exception e) { log.error(e.getMessage()); } } catch (Exception e) { String errorMsg = "Fail to parsing Line.[current line(" + bufReader.getLineNumber() + ") :" + line + "] : "; log.error(errorMsg, e); throw new DataParsingException(errorMsg, e); //throw(e); } finally { if (in != null) in.close(); if (isReader != null) isReader.close(); if (bufReader != null) bufReader.close(); } }
From source file:com.castis.sysComp.PoisConverterSysComp.java
private void writeFile(File file) throws IOException { Map<String, String> middleNodeMap = new HashMap<String, String>(); String line = ""; FileInputStream in = null;/*w ww . java 2s. com*/ Reader isReader = null; LineNumberReader bufReader = null; FileOutputStream fos = null; String dir = filePolling.getValidFileDirectory(resultDir); String fileName = file.getName(); int index = fileName.indexOf("-"); if (index != -1) { fileName = fileName.substring(index + 1, fileName.length()); } String tempDir = dir + "/temp/"; File targetDirectory = new File(CiFileUtil.getReplaceFullPath(tempDir)); if (!targetDirectory.isDirectory()) { CiFileUtil.createDirectory(tempDir); } fos = new FileOutputStream(tempDir + fileName); int byteSize = 2048; ByteBuffer byteBuffer = ByteBuffer.allocateDirect(byteSize); GatheringByteChannel outByteCh = fos.getChannel(); try { String encodingCharset = FILE_CHARSET; in = new FileInputStream(file); isReader = new InputStreamReader(in, encodingCharset); bufReader = new LineNumberReader(isReader); boolean first = true; while ((line = bufReader.readLine()) != null) { if (line.length() == 0) { continue; } InputDataDTO data = new InputDataDTO(); String result[] = line.split("\\|"); if (first == true && result.length <= 1) { first = false; continue; } String platform = result[4]; if (platform != null && platform.equalsIgnoreCase("stb")) platform = "STB"; else if (platform != null && platform.equalsIgnoreCase("mobile")) { platform = "Mobile"; } data.setPlatform(platform); List<TreeNodeDTO> tree = treeMap.get(platform); if (tree == null) { tree = getAxis(platform); treeMap.put(platform, tree); } String fullpath = getFullPath(tree, result[0]); data.setRegion(fullpath); data.setCategory(result[1]); data.setWeekday(result[2]); data.setHour(result[3]); data.setCount(Integer.parseInt(result[5])); List<subDataDTO> subDataList = writeNodeInfoOnFile(byteSize, byteBuffer, outByteCh, data, "Y"); if (subDataList != null && subDataList.size() > 0) { writeMiddleNode(byteSize, byteBuffer, outByteCh, data, middleNodeMap, subDataList, "N"); } } fos.close(); index = fileName.indexOf("_"); String targetDir = resultDir; File sourceFile = new File(tempDir + fileName); if (index != -1) { String directory = fileName.substring(0, index); targetDir += "/viewCount/" + directory; } try { File resultTargetDir = new File(CiFileUtil.getReplaceFullPath(targetDir)); if (!resultTargetDir.isDirectory()) { CiFileUtil.createDirectory(targetDir); } CiFileUtil.renameFile(sourceFile, targetDir, fileName); } catch (Exception e) { log.error(e.getMessage()); } } catch (Exception e) { String errorMsg = "Fail to parsing Line.[current line(" + bufReader.getLineNumber() + ") :" + line + "] : "; log.error(errorMsg, e); throw new DataParsingException(errorMsg, e); //throw(e); } finally { if (in != null) in.close(); if (isReader != null) isReader.close(); if (bufReader != null) bufReader.close(); } }
From source file:org.jumpmind.metl.core.runtime.component.XmlReader.java
void processFiles(List<String> files, Message inputMessage, ISendMessageCallback callback, boolean unitOfWorkLastMessage) throws XmlPullParserException, IOException { IDirectory directory = getResourceReference(); XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); for (String file : files) { ArrayList<String> outboundPayload = new ArrayList<String>(); log(LogLevel.INFO, "Reading %s", file); Map<String, Serializable> headers = new HashMap<>(); headers.put("source.file.path", file); LineNumberReader lineNumberReader = null; InputStream parserIs = null; try {//from w w w. ja v a 2 s . co m String filePath = resolveParamsAndHeaders(file, inputMessage); parserIs = directory.getInputStream(filePath, mustExist); if (parserIs != null) { InputStreamReader reader = new InputStreamReader(directory.getInputStream(filePath, mustExist), encoding); parser.setInput(parserIs, encoding); lineNumberReader = new LineNumberReader(reader); lineNumberReader.setLineNumber(1); int startCol = 0; int startLine = 1; int prevEndLine = 1; int prevEndCol = 0; int eventType = parser.getEventType(); String line = null; while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case XmlPullParser.START_TAG: if (StringUtils.isBlank(readTag)) { readTag = parser.getName(); info("Read tag was not set, defaulting to root tag: " + readTag); } if (parser.getName().equals(readTag)) { startCol = prevEndCol; startLine = prevEndLine; } prevEndCol = parser.getColumnNumber(); prevEndLine = parser.getLineNumber(); break; case XmlPullParser.END_TAG: prevEndCol = parser.getColumnNumber(); prevEndLine = parser.getLineNumber(); if (parser.getName().equals(readTag)) { StringBuilder xml = new StringBuilder(); forward(startLine, lineNumberReader); int linesToRead = parser.getLineNumber() - lineNumberReader.getLineNumber(); if (lineNumberReader.getLineNumber() > startLine) { startCol = 0; } line = lineNumberReader.readLine(); while (linesToRead >= 0 && line != null) { if (startCol > 0) { if (line.length() > startCol) { xml.append(line.substring(startCol)).append("\n"); } startCol = 0; } else if (linesToRead == 0) { if (line.length() > parser.getColumnNumber()) { xml.append(line.substring(0, parser.getColumnNumber())); } else { xml.append(line).append("\n"); } } else { xml.append(line).append("\n"); } linesToRead--; if (linesToRead >= 0) { line = lineNumberReader.readLine(); } } getComponentStatistics().incrementNumberEntitiesProcessed(threadNumber); outboundPayload.add(xml.toString()); if (outboundPayload.size() == readTagsPerMessage) { callback.sendTextMessage(headers, outboundPayload); outboundPayload = new ArrayList<String>(); } startCol = 0; } break; } eventType = parser.next(); } } else { info("File %s didn't exist, but Must Exist setting was false. Continuing", file); } } finally { closeQuietly(lineNumberReader); closeQuietly(parserIs); } if (outboundPayload.size() > 0) { callback.sendTextMessage(headers, outboundPayload); } } }