List of usage examples for java.io BufferedReader reset
public void reset() throws IOException
From source file:cms.service.template.TemplateUtility.java
public Vector parseInputFile(BufferedReader bufReader, String strHeader) throws IOException { int i = 0;/* w w w . ja v a 2 s .c o m*/ strHeader = "[" + strHeader + "]"; Vector vBuf = new Vector(); String str = bufReader.readLine(); while (str != null) { if (str.equalsIgnoreCase(strHeader)) { while (!str.equalsIgnoreCase("[end]")) { vBuf.addElement(str); str = bufReader.readLine(); } bufReader.reset(); return vBuf; } str = bufReader.readLine(); } bufReader.reset(); return vBuf; }
From source file:cms.service.template.TemplateUtility.java
public Vector parseInputXmlFile(BufferedReader bufReader, String strHeader) throws IOException { int i = 0;//from w w w. j ava 2 s . c om String endTag = "</" + strHeader + ">"; strHeader = "<" + strHeader + ">"; Vector vBuf = new Vector(); String str = bufReader.readLine(); while (str != null) { if (str.equalsIgnoreCase(strHeader)) { while (!str.equalsIgnoreCase(endTag)) { vBuf.addElement(str); str = bufReader.readLine(); } bufReader.reset(); return vBuf; } str = bufReader.readLine(); } bufReader.reset(); return vBuf; }
From source file:org.eclipse.mylyn.internal.bugzilla.core.BugzillaReportSubmitForm.java
/** * Post the bug to the bugzilla server TODO: fix this mess */// w ww . j a v a 2 s .c o m public String submitReportToRepository(BugzillaClient client) throws IOException, BugzillaException, PossibleBugzillaFailureException, GeneralSecurityException { NameValuePair[] formData = fields.values().toArray(new NameValuePair[fields.size()]); InputStream inputStream = null; String result = null; PostMethod method = null; try { if (isNewBugPost()) { method = client.postFormData(POST_BUG_CGI, formData); } else { method = client.postFormData(PROCESS_BUG_CGI, formData); } if (method == null) throw new BugzillaException("Could not post form"); BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); in.mark(10); HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(in, null); boolean existingBugPosted = false; boolean isTitle = false; String title = ""; for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) { if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.TITLE && !((HtmlTag) (token.getValue())).isEndTag()) { isTitle = true; continue; } if (isTitle) { // get all of the data in the title tag if (token.getType() != Token.TAG) { title += ((StringBuffer) token.getValue()).toString().toLowerCase() + " "; continue; } else if (token.getType() == Token.TAG && ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.TITLE && ((HtmlTag) token.getValue()).isEndTag()) { if (!isNewBugPost && (title.toLowerCase().matches(".*bug\\s+processed.*") || title.toLowerCase().matches(".*defect\\s+processed.*"))) { existingBugPosted = true; } else if (isNewBugPost && prefix != null && prefix2 != null && postfix != null && postfix2 != null && result == null) { int startIndex = -1; int startIndexPrefix = title.toLowerCase().indexOf(prefix.toLowerCase()); int startIndexPrefix2 = title.toLowerCase().indexOf(prefix2.toLowerCase()); if (startIndexPrefix != -1 || startIndexPrefix2 != -1) { if (startIndexPrefix != -1) { startIndex = startIndexPrefix + prefix.length(); } else { startIndex = startIndexPrefix2 + prefix2.length(); } int stopIndex = title.toLowerCase().indexOf(postfix.toLowerCase(), startIndex); if (stopIndex == -1) stopIndex = title.toLowerCase().indexOf(postfix2.toLowerCase(), startIndex); if (stopIndex > -1) { result = (title.substring(startIndex, stopIndex)).trim(); } } } break; } } } if ((!isNewBugPost && existingBugPosted != true) || (isNewBugPost && result == null)) { in.reset(); BugzillaClient.parseHtmlError(in); } } catch (ParseException e) { throw new IOException("Could not parse response from server."); } finally { if (inputStream != null) { inputStream.close(); } if (method != null) { method.releaseConnection(); } } // return the bug number return result; }
From source file:com.photon.phresco.framework.actions.applications.Build.java
public String readLogFile(Project project, String fromNodejs) { StringBuilder builder = new StringBuilder(Utility.getProjectHome()); builder.append(project.getProjectInfo().getCode()); builder.append(File.separator); builder.append(DO_NOT_CHECKIN_DIR);/* ww w .ja va 2 s. com*/ builder.append(File.separator); builder.append(NODEJS_LOG_DIR); builder.append(File.separator); builder.append(NODEJS_LOG_FILE); BufferedReader reader = null; StringBuffer contents = new StringBuffer(); try { File file = new File(builder.toString()); // It executed when file not exist and view method called if (!file.exists() && fromNodejs.equals(READ_LOG_VIEW)) { return ""; } // It executed when file exist and view method called if (file.exists() && fromNodejs.equals(READ_LOG_VIEW)) { reader = new BufferedReader(new FileReader(file)); String text = null; while ((text = reader.readLine()) != null) { contents.append(text).append(System.getProperty(LINE_SEPERATOR)); } return contents.toString(); } // It executed when file not exist and return reader if (!file.exists()) { StringReader sb = new StringReader("Server started successfully..."); reader = new BufferedReader(sb); // getHttpSession().setAttribute(REQ_READER, reader); getHttpSession().setAttribute(projectCode + REQ_READ_LOG_FILE, reader); getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode); getHttpRequest().setAttribute(REQ_TEST_TYPE, REQ_READ_LOG_FILE); } // It executed when file existence and return reader if (file.exists()) { waitForTime(2); reader = new BufferedReader(new FileReader(file)); // getHttpSession().setAttribute(REQ_READER, reader); @SuppressWarnings("unused") String line = null; if (reader.markSupported()) { reader.mark(1); if ((line = reader.readLine()) == null) { reader = new BufferedReader(new StringReader("Server started successfully...")); } else { reader.reset(); } } getHttpSession().setAttribute(projectCode + REQ_READ_LOG_FILE, reader); getHttpRequest().setAttribute(REQ_PROJECT_CODE, projectCode); getHttpRequest().setAttribute(REQ_TEST_TYPE, REQ_READ_LOG_FILE); } } catch (FileNotFoundException e) { if (debugEnabled) { S_LOGGER.error( "Entered into catch block of Build.readLogFile()" + FrameworkUtil.getStackTraceAsString(e)); } } catch (IOException e) { if (debugEnabled) { S_LOGGER.error( "Entered into catch block of Build.readLogFile()" + FrameworkUtil.getStackTraceAsString(e)); } } return null; }
From source file:com.zimbra.cs.util.ProxyConfOverride.java
public static void expandTemplate(File tFile, File wFile) throws ProxyConfException { BufferedReader r = null; BufferedWriter w = null;//from ww w .j a v a 2s . c o m try { String tf = tFile.getAbsolutePath(); String wf = wFile.getAbsolutePath(); if (mDryRun) { mLog.info("Would expand template:" + tf + " to file:" + wf); return; } mLog.info("Expanding template:" + tf + " to file:" + wf); if (!tFile.exists()) { throw new ProxyConfException("Template file " + tf + " does not exist"); } r = new BufferedReader(new FileReader(tf)); w = new BufferedWriter(new FileWriter(wf)); String line; //for the first line of template, check the custom header command r.mark(100); //assume the first line won't beyond 100 line = r.readLine(); //only for back compability if (line.equalsIgnoreCase("!{explode vhn_vip_ssl}")) { expandTemplateExplodeSSLConfigsForAllVhnsAndVIPs(r, w); return; } Matcher cmdMatcher = cmdPattern.matcher(line); if (cmdMatcher.matches()) { //the command is found String[] cmd_arg = cmdMatcher.group(2).split("[ \t]+", 2); //command selection can be extracted if more commands are introduced if (cmd_arg.length == 2 && cmd_arg[0].compareTo("explode") == 0) { if (!mGenConfPerVhn) { // explode only when GenConfPerVhn is enabled return; } if (cmd_arg[1].startsWith("domain(") && cmd_arg[1].endsWith(")")) { //extract the args in "domain(arg1, arg2, ...) String arglist = cmd_arg[1].substring("domain(".length(), cmd_arg[1].length() - 1); String[] args; if (arglist.equals("")) { args = new String[0]; } else { args = arglist.split(",( |\t)*"); } expandTemplateByExplodeDomain(r, w, args); } else { throw new ProxyConfException("Illegal custom header command: " + cmdMatcher.group(2)); } } else { throw new ProxyConfException("Illegal custom header command: " + cmdMatcher.group(2)); } } else { r.reset(); //reset to read the first line expandTemplateSimple(r, w); } } catch (IOException ie) { throw new ProxyConfException("Cannot expand template file: " + ie.getMessage()); } catch (SecurityException se) { throw new ProxyConfException("Cannot expand template: " + se.getMessage()); } finally { try { if (w != null) w.close(); if (r != null) r.close(); } catch (IOException e) { throw new ProxyConfException("Cannot expand template file: " + e.getMessage()); } } }