List of usage examples for java.io BufferedReader mark
public void mark(int readAheadLimit) throws IOException
From source file:org.eclipse.mylyn.internal.bugzilla.core.BugzillaReportSubmitForm.java
/** * Post the bug to the bugzilla server TODO: fix this mess */// ww w . jav a 2 s .com 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:ffx.xray.CIFFilter.java
/** * {@inheritDoc}//w w w .j av a2 s. c o m */ @Override public double getResolution(File cifFile, Crystal crystal) { double res = Double.POSITIVE_INFINITY; try { BufferedReader br = new BufferedReader(new FileReader(cifFile)); String str; int ncol = 0; boolean inhkl = false; while ((str = br.readLine()) != null) { String strarray[] = str.split("\\s+"); if (strarray[0].startsWith("_refln.")) { inhkl = true; br.mark(0); String cifarray[] = strarray[0].split("\\.+"); switch (Header.toHeader(cifarray[1])) { case index_h: h = ncol; break; case index_k: k = ncol; break; case index_l: l = ncol; break; } ncol++; } else if (inhkl) { if (h < 0 || k < 0 || l < 0) { String message = "Fatal error in CIF file - no H K L indexes?\n"; logger.log(Level.SEVERE, message); return -1.0; } break; } } // go back to where the reflections start br.reset(); HKL hkl = new HKL(); while ((str = br.readLine()) != null) { // reached end, break if (str.trim().startsWith("#END")) { break; } else if (str.trim().startsWith("data")) { break; } else if (str.trim().startsWith("#")) { continue; } String strarray[] = str.trim().split("\\s+"); // some files split data on to multiple lines while (strarray.length < ncol) { str = str + " " + br.readLine(); strarray = str.trim().split("\\s+"); } int ih = Integer.parseInt(strarray[h]); int ik = Integer.parseInt(strarray[k]); int il = Integer.parseInt(strarray[l]); hkl.h(ih); hkl.k(ik); hkl.l(il); res = Math.min(res, Crystal.res(crystal, hkl)); } } catch (IOException ioe) { System.out.println("IO Exception: " + ioe.getMessage()); return -1.0; } return res; }
From source file:com.googlecode.erca.framework.io.in.RcftParser.java
private void parseRelationalContext(BufferedReader input, String desc) throws IOException { RelationalContext rc = RcfFactory.eINSTANCE.createRelationalContext(); String rcName = desc.split("\\ ")[1]; logger.info("Parsing relational context " + rcName); rc.setName(rcName);/*from w w w .ja v a 2 s . c o m*/ String source = input.readLine().trim().split("\\ ")[1]; String target = input.readLine().trim().split("\\ ")[1]; String sclOp = input.readLine().trim().split("\\ ")[1]; FormalContext sourceFc = rcf.getFormalContext(source); FormalContext targetFc = rcf.getFormalContext(target); rc.setSourceContext(sourceFc); rc.setTargetContext(targetFc); rc.setScalingOperator(sclOp); input.mark(0); String line = input.readLine(); int currentRow = 0; Map<Integer, Entity> tgtEnts = new HashMap<Integer, Entity>(); while (line != null) { String tline = line.trim(); if (tline.startsWith("RelationalContext")) break; else if (tline.startsWith("FormalContext")) break; else if (tline.equals("")) break; String[] tokens = line.split("\\|"); int len = tokens.length; if (currentRow == 0) { for (int i = 2; i < len; i++) { String name = tokens[i].trim(); Entity ent = targetFc.getEntity(name); tgtEnts.put(i, ent); } } else { String name = tokens[1].trim(); Entity srcEnt = sourceFc.getEntity(name); for (int i = 2; i < len; i++) { String cell = tokens[i].trim().toLowerCase(); if ("x".equals(cell)) { Entity tgtEnt = tgtEnts.get(i); Pair pair = RcfFactory.eINSTANCE.createPair(); pair.setSource(srcEnt); pair.setTarget(tgtEnt); rc.getRelation().add(pair); logger.debug("Creates pair between " + srcEnt.getName() + " and " + tgtEnt.getName() + ". Line: " + currentRow); } } } currentRow++; input.mark(0); line = input.readLine(); } rcf.getRelationalContexts().add(rc); if (line != null) input.reset(); }
From source file:ffx.xray.parsers.CIFFilter.java
/** * {@inheritDoc}/*from w ww . jav a2s .com*/ */ @Override public double getResolution(File cifFile, Crystal crystal) { double resolution = Double.POSITIVE_INFINITY; try { BufferedReader br = new BufferedReader(new FileReader(cifFile)); String string; int nCol = 0; boolean inHKL = false; while ((string = br.readLine()) != null) { String strArray[] = string.split("\\s+"); if (strArray[0].startsWith("_refln.")) { inHKL = true; br.mark(0); String cifArray[] = strArray[0].split("\\.+"); switch (Header.toHeader(cifArray[1])) { case index_h: h = nCol; break; case index_k: k = nCol; break; case index_l: l = nCol; break; } nCol++; } else if (inHKL) { if (h < 0 || k < 0 || l < 0) { String message = " Fatal error in CIF file - no H K L indexes?\n"; logger.log(Level.SEVERE, message); return -1.0; } break; } } // Go back to where the reflections start. br.reset(); HKL hkl = new HKL(); while ((string = br.readLine()) != null) { // Reached end, break. if (string.trim().startsWith("#END")) { break; } else if (string.trim().startsWith("data")) { break; } else if (string.trim().startsWith("#")) { continue; } // Some files split data on to multiple lines. String strArray[] = string.trim().split("\\s+"); while (strArray.length < nCol) { string = string + " " + br.readLine(); strArray = string.trim().split("\\s+"); } int ih = Integer.parseInt(strArray[h]); int ik = Integer.parseInt(strArray[k]); int il = Integer.parseInt(strArray[l]); hkl.h(ih); hkl.k(ik); hkl.l(il); resolution = min(resolution, Crystal.res(crystal, hkl)); } } catch (IOException e) { String message = " CIF IO Exception."; logger.log(Level.WARNING, message, e); return -1.0; } return resolution; }
From source file:ffx.xray.CIFFilter.java
/** * {@inheritDoc}// w ww . j av a2 s . c o m */ @Override public boolean readFile(File cifFile, ReflectionList reflectionlist, DiffractionRefinementData refinementdata, CompositeConfiguration properties) { int nread, nnan, nres, nignore, ncifignore, nfriedel, ncut; boolean transpose = false; boolean intensitiesToAmplitudes = false; StringBuilder sb = new StringBuilder(); sb.append(String.format(" Opening %s\n", cifFile.getName())); if (refinementdata.rfreeflag < 0) { refinementdata.setFreeRFlag(1); sb.append(String.format(" Setting R free flag to CIF default: %d\n", refinementdata.rfreeflag)); } try { BufferedReader br = new BufferedReader(new FileReader(cifFile)); String str; int ncol = 0; boolean inhkl = false; while ((str = br.readLine()) != null) { String strarray[] = str.split("\\s+"); if (strarray[0].startsWith("_refln.")) { inhkl = true; br.mark(0); String cifarray[] = strarray[0].split("\\.+"); switch (Header.toHeader(cifarray[1])) { case index_h: h = ncol; break; case index_k: k = ncol; break; case index_l: l = ncol; break; case F_meas: case F_meas_au: fo = ncol; break; case F_meas_sigma: case F_meas_sigma_au: sigfo = ncol; break; case intensity_meas: io = ncol; break; case intensity_sigma: sigio = ncol; break; case status: rfree = ncol; break; } ncol++; } else if (inhkl) { if (h < 0 || k < 0 || l < 0) { String message = "Fatal error in CIF file - no H K L indexes?\n"; logger.log(Level.SEVERE, message); return false; } break; } } if (fo < 0 && sigfo < 0 && io > 0 && sigio > 0) { intensitiesToAmplitudes = true; } if (fo < 0 && io < 0) { logger.severe("Reflection data (I/F) not found in CIF file!"); } // go back to where the reflections start br.reset(); // check if HKLs need to be transposed or not HKL mate = new HKL(); int nposignore = 0; int ntransignore = 0; while ((str = br.readLine()) != null) { // reached end, break if (str.trim().startsWith("#END")) { break; } else if (str.trim().startsWith("data")) { break; } else if (str.trim().startsWith("#")) { continue; } String strarray[] = str.trim().split("\\s+"); // some files split data on to multiple lines while (strarray.length < ncol) { str = str + " " + br.readLine(); strarray = str.trim().split("\\s+"); } if (rfree > 0) { // ignored cases if (strarray[rfree].charAt(0) == 'x' || strarray[rfree].charAt(0) == '<' || strarray[rfree].charAt(0) == '-' || strarray[rfree].charAt(0) == 'h' || strarray[rfree].charAt(0) == 'l') { continue; } } int ih = Integer.parseInt(strarray[h]); int ik = Integer.parseInt(strarray[k]); int il = Integer.parseInt(strarray[l]); boolean friedel = reflectionlist.findSymHKL(ih, ik, il, mate, false); HKL hklpos = reflectionlist.getHKL(mate); if (hklpos == null) { nposignore++; } friedel = reflectionlist.findSymHKL(ih, ik, il, mate, true); HKL hkltrans = reflectionlist.getHKL(mate); if (hkltrans == null) { ntransignore++; } } if (nposignore > ntransignore) { transpose = true; } // reopen to start at beginning br = new BufferedReader(new FileReader(cifFile)); inhkl = false; while ((str = br.readLine()) != null) { String strarray[] = str.split("\\s+"); if (strarray[0].startsWith("_refln.")) { br.mark(0); inhkl = true; } else if (inhkl) { break; } } // go back to where the reflections start br.reset(); // read in data double anofsigf[][] = new double[refinementdata.n][4]; for (int i = 0; i < refinementdata.n; i++) { anofsigf[i][0] = anofsigf[i][1] = anofsigf[i][2] = anofsigf[i][3] = Double.NaN; } nread = nnan = nres = nignore = ncifignore = nfriedel = ncut = 0; while ((str = br.readLine()) != null) { // reached end, break if (str.trim().startsWith("#END")) { break; } else if (str.trim().startsWith("data")) { break; } else if (str.trim().startsWith("#")) { continue; } String strarray[] = str.trim().split("\\s+"); // some files split data on to multiple lines while (strarray.length < ncol) { str = str + " " + br.readLine(); strarray = str.trim().split("\\s+"); } int ih = Integer.parseInt(strarray[h]); int ik = Integer.parseInt(strarray[k]); int il = Integer.parseInt(strarray[l]); boolean friedel = reflectionlist.findSymHKL(ih, ik, il, mate, transpose); HKL hkl = reflectionlist.getHKL(mate); if (hkl != null) { boolean isnull = false; if (rfree > 0) { if (strarray[rfree].charAt(0) == 'o') { refinementdata.setFreeR(hkl.index(), 0); } else if (strarray[rfree].charAt(0) == 'f') { refinementdata.setFreeR(hkl.index(), 1); } else if (strarray[rfree].charAt(0) == 'x') { isnull = true; nnan++; } else if (strarray[rfree].charAt(0) == '<' || strarray[rfree].charAt(0) == '-' || strarray[rfree].charAt(0) == 'h' || strarray[rfree].charAt(0) == 'l') { isnull = true; ncifignore++; } else { refinementdata.setFreeR(hkl.index(), Integer.parseInt(strarray[rfree])); } } if (!intensitiesToAmplitudes && !isnull) { if (strarray[fo].charAt(0) == '?' || strarray[sigfo].charAt(0) == '?') { isnull = true; nnan++; continue; } if (refinementdata.fsigfcutoff > 0.0) { double f1 = Double.parseDouble(strarray[fo]); double sigf1 = Double.parseDouble(strarray[sigfo]); if ((f1 / sigf1) < refinementdata.fsigfcutoff) { ncut++; continue; } } if (friedel) { anofsigf[hkl.index()][2] = Double.parseDouble(strarray[fo]); anofsigf[hkl.index()][3] = Double.parseDouble(strarray[sigfo]); nfriedel++; } else { anofsigf[hkl.index()][0] = Double.parseDouble(strarray[fo]); anofsigf[hkl.index()][1] = Double.parseDouble(strarray[sigfo]); } } if (intensitiesToAmplitudes && !isnull) { if (strarray[io].charAt(0) == '?' || strarray[sigio].charAt(0) == '?') { isnull = true; nnan++; continue; } if (friedel) { anofsigf[hkl.index()][2] = Double.parseDouble(strarray[io]); anofsigf[hkl.index()][3] = Double.parseDouble(strarray[sigio]); nfriedel++; } else { anofsigf[hkl.index()][0] = Double.parseDouble(strarray[io]); anofsigf[hkl.index()][1] = Double.parseDouble(strarray[sigio]); } } nread++; } else { HKL tmp = new HKL(ih, ik, il); if (!reflectionlist.resolution .inInverseResSqRange(Crystal.invressq(reflectionlist.crystal, tmp))) { nres++; } else { nignore++; } } } br.close(); // set up fsigf from F+ and F- refinementdata.generate_fsigf_from_anofsigf(anofsigf); if (intensitiesToAmplitudes) { refinementdata.intensities_to_amplitudes(); } } catch (IOException ioe) { System.out.println("IO Exception: " + ioe.getMessage()); return false; } sb.append(String.format(" HKL data is %s\n", transpose ? "transposed" : "not transposed")); sb.append(String.format(" HKL read in: %d\n", nread)); sb.append(String.format(" HKL read as friedel mates: %d\n", nfriedel)); sb.append(String.format(" HKL with NaN (ignored): %d\n", nnan)); sb.append(String.format(" HKL NOT read in (status <, -, h or l): %d\n", ncifignore)); sb.append(String.format(" HKL NOT read in (too high resolution): %d\n", nres)); sb.append(String.format(" HKL NOT read in (not in internal list?): %d\n", nignore)); sb.append(String.format(" HKL NOT read in (F/sigF cutoff): %d\n", ncut)); sb.append(String.format(" HKL in internal list: %d\n", reflectionlist.hkllist.size())); if (logger.isLoggable(Level.INFO)) { logger.info(sb.toString()); } if (rfree < 0) { refinementdata.generateRFree(); } return true; }
From source file:ffx.xray.parsers.CIFFilter.java
/** * {@inheritDoc}//from w ww.j a va 2 s .co m */ @Override public boolean readFile(File cifFile, ReflectionList reflectionList, DiffractionRefinementData refinementData, CompositeConfiguration properties) { int nRead, nNAN, nRes; int nIgnore, nCIFIgnore; int nFriedel, nCut; boolean transpose = false; boolean intensitiesToAmplitudes = false; StringBuilder sb = new StringBuilder(); sb.append(String.format(" Opening %s\n", cifFile.getName())); if (refinementData.rfreeflag < 0) { refinementData.setFreeRFlag(1); sb.append(format(" Setting R free flag to CIF default: %d\n", refinementData.rfreeflag)); } try { BufferedReader br = new BufferedReader(new FileReader(cifFile)); String string; int nCol = 0; boolean inHKL = false; while ((string = br.readLine()) != null) { String stringArray[] = string.split("\\s+"); if (stringArray[0].startsWith("_refln.")) { inHKL = true; br.mark(0); String cifArray[] = stringArray[0].split("\\.+"); switch (Header.toHeader(cifArray[1])) { case index_h: h = nCol; break; case index_k: k = nCol; break; case index_l: l = nCol; break; case F_meas: case F_meas_au: fo = nCol; break; case F_meas_sigma: case F_meas_sigma_au: sigFo = nCol; break; case intensity_meas: io = nCol; break; case intensity_sigma: sigIo = nCol; break; case status: rFree = nCol; break; } nCol++; } else if (inHKL) { if (h < 0 || k < 0 || l < 0) { String message = " Fatal error in CIF file - no H K L indexes?\n"; logger.log(Level.SEVERE, message); return false; } break; } } if (fo < 0 && sigFo < 0 && io > 0 && sigIo > 0) { intensitiesToAmplitudes = true; } if (fo < 0 && io < 0) { logger.severe(" Reflection data (I/F) not found in CIF file!"); } // Go back to where the reflections start. br.reset(); // Check if HKLs need to be transposed or not. HKL mate = new HKL(); int nPosIgnore = 0; int nTransIgnore = 0; while ((string = br.readLine()) != null) { if (string.trim().startsWith("#END")) { // Reached end, break. break; } else if (string.trim().startsWith("data")) { break; } else if (string.trim().startsWith("#")) { continue; } // Some files split data on to multiple lines. String strArray[] = string.trim().split("\\s+"); while (strArray.length < nCol) { string = string + " " + br.readLine(); strArray = string.trim().split("\\s+"); } if (rFree > 0) { // Ignored cases. if (strArray[rFree].charAt(0) == 'x' || strArray[rFree].charAt(0) == '<' || strArray[rFree].charAt(0) == '-' || strArray[rFree].charAt(0) == 'h' || strArray[rFree].charAt(0) == 'l') { continue; } } int ih = Integer.parseInt(strArray[h]); int ik = Integer.parseInt(strArray[k]); int il = Integer.parseInt(strArray[l]); boolean friedel = reflectionList.findSymHKL(ih, ik, il, mate, false); HKL hklPos = reflectionList.getHKL(mate); if (hklPos == null) { nPosIgnore++; } friedel = reflectionList.findSymHKL(ih, ik, il, mate, true); HKL hklTrans = reflectionList.getHKL(mate); if (hklTrans == null) { nTransIgnore++; } } if (nPosIgnore > nTransIgnore) { transpose = true; } // Re-open to start at beginning. br = new BufferedReader(new FileReader(cifFile)); inHKL = false; while ((string = br.readLine()) != null) { String strArray[] = string.split("\\s+"); if (strArray[0].startsWith("_refln.")) { br.mark(0); inHKL = true; } else if (inHKL) { break; } } // Go back to where the reflections start. br.reset(); // Read in data. double anofSigF[][] = new double[refinementData.n][4]; for (int i = 0; i < refinementData.n; i++) { anofSigF[i][0] = anofSigF[i][1] = anofSigF[i][2] = anofSigF[i][3] = Double.NaN; } nRead = nNAN = nRes = nIgnore = nCIFIgnore = nFriedel = nCut = 0; while ((string = br.readLine()) != null) { // Reached end, break. if (string.trim().startsWith("#END")) { break; } else if (string.trim().startsWith("data")) { break; } else if (string.trim().startsWith("#")) { continue; } // Some files split data on to multiple lines. String strArray[] = string.trim().split("\\s+"); while (strArray.length < nCol) { string = string + " " + br.readLine(); strArray = string.trim().split("\\s+"); } int ih = Integer.parseInt(strArray[h]); int ik = Integer.parseInt(strArray[k]); int il = Integer.parseInt(strArray[l]); boolean friedel = reflectionList.findSymHKL(ih, ik, il, mate, transpose); HKL hkl = reflectionList.getHKL(mate); if (hkl != null) { boolean isnull = false; if (rFree > 0) { if (strArray[rFree].charAt(0) == 'o') { refinementData.setFreeR(hkl.index(), 0); } else if (strArray[rFree].charAt(0) == 'f') { refinementData.setFreeR(hkl.index(), 1); } else if (strArray[rFree].charAt(0) == 'x') { isnull = true; nNAN++; } else if (strArray[rFree].charAt(0) == '<' || strArray[rFree].charAt(0) == '-' || strArray[rFree].charAt(0) == 'h' || strArray[rFree].charAt(0) == 'l') { isnull = true; nCIFIgnore++; } else { refinementData.setFreeR(hkl.index(), Integer.parseInt(strArray[rFree])); } } if (!intensitiesToAmplitudes && !isnull) { if (strArray[fo].charAt(0) == '?' || strArray[sigFo].charAt(0) == '?') { isnull = true; nNAN++; continue; } if (refinementData.fsigfcutoff > 0.0) { double f1 = Double.parseDouble(strArray[fo]); double sigf1 = Double.parseDouble(strArray[sigFo]); if ((f1 / sigf1) < refinementData.fsigfcutoff) { nCut++; continue; } } if (friedel) { anofSigF[hkl.index()][2] = Double.parseDouble(strArray[fo]); anofSigF[hkl.index()][3] = Double.parseDouble(strArray[sigFo]); nFriedel++; } else { anofSigF[hkl.index()][0] = Double.parseDouble(strArray[fo]); anofSigF[hkl.index()][1] = Double.parseDouble(strArray[sigFo]); } } if (intensitiesToAmplitudes && !isnull) { if (strArray[io].charAt(0) == '?' || strArray[sigIo].charAt(0) == '?') { isnull = true; nNAN++; continue; } if (friedel) { anofSigF[hkl.index()][2] = Double.parseDouble(strArray[io]); anofSigF[hkl.index()][3] = Double.parseDouble(strArray[sigIo]); nFriedel++; } else { anofSigF[hkl.index()][0] = Double.parseDouble(strArray[io]); anofSigF[hkl.index()][1] = Double.parseDouble(strArray[sigIo]); } } nRead++; } else { HKL tmp = new HKL(ih, ik, il); if (!reflectionList.resolution .inInverseResSqRange(Crystal.invressq(reflectionList.crystal, tmp))) { nRes++; } else { nIgnore++; } } } br.close(); // Set up fsigf from F+ and F-. refinementData.generate_fsigf_from_anofsigf(anofSigF); if (intensitiesToAmplitudes) { refinementData.intensities_to_amplitudes(); } } catch (IOException ioe) { System.out.println("IO Exception: " + ioe.getMessage()); return false; } sb.append(String.format(" HKL data is %s\n", transpose ? "transposed" : "not transposed")); sb.append(String.format(" HKL read in: %d\n", nRead)); sb.append(String.format(" HKL read as friedel mates: %d\n", nFriedel)); sb.append(String.format(" HKL with NaN (ignored): %d\n", nNAN)); sb.append(String.format(" HKL NOT read in (status <, -, h or l): %d\n", nCIFIgnore)); sb.append(String.format(" HKL NOT read in (too high resolution): %d\n", nRes)); sb.append(String.format(" HKL NOT read in (not in internal list?): %d\n", nIgnore)); sb.append(String.format(" HKL NOT read in (F/sigF cutoff): %d\n", nCut)); sb.append(String.format(" HKL in internal list: %d\n", reflectionList.hkllist.size())); if (logger.isLoggable(Level.INFO)) { logger.info(sb.toString()); } if (rFree < 0) { refinementData.generateRFree(); } return true; }
From source file:org.fhcrc.cpl.toolbox.filehandler.TabLoader.java
/** * Look at first 5 lines of the file and infer col names, data types. * Most useful if maps are being returned, otherwise use inferColumnInfo(reader, clazz) to * use properties of a bean instead.//from w w w. java2 s .c o m * * @param reader * @throws IOException */ private void inferColumnInfo(BufferedReader reader) throws IOException { reader.mark(4096 * _scanAheadLineCount); String[] lines = new String[_scanAheadLineCount + Math.max(_skipLines, 0)]; int i; for (i = 0; i < lines.length;) { String line = reader.readLine(); if (null == line) break; if (line.length() == 0 || line.charAt(0) == '#') continue; lines[i++] = line; } int nLines = i; reader.reset(); if (nLines == 0) { _columns = new ColumnDescriptor[0]; return; } int nCols = 0; String[][] lineFields = new String[nLines][]; for (i = 0; i < nLines; i++) { lineFields[i] = parseLine(lines[i]); nCols = Math.max(nCols, lineFields[i].length); } ColumnDescriptor[] colDescs = new ColumnDescriptor[nCols]; for (i = 0; i < nCols; i++) colDescs[i] = new ColumnDescriptor(); //Try to infer types int inferStartLine = _skipLines == -1 ? 1 : _skipLines; for (int f = 0; f < nCols; f++) { int classIndex = -1; for (int line = inferStartLine; line < nLines; line++) { if (f >= lineFields[line].length) continue; String field = lineFields[line][f]; if ("".equals(field)) continue; for (int c = Math.max(classIndex, 0); c < convertClasses.length; c++) { //noinspection EmptyCatchBlock try { Object o = ConvertUtils.convert(field, convertClasses[c]); //We found a type that works. If it is more general than //what we had before, we must use it. if (o != null && c > classIndex) classIndex = c; break; } catch (Exception x) { } } } colDescs[f].clazz = classIndex == -1 ? String.class : convertClasses[classIndex]; } //If first line is compatible type for all fields, AND all fields not Strings (dhmay adding 20100502) // then there is no header row if (_skipLines == -1) { boolean firstLineCompat = true; boolean allStrings = true; String[] fields = lineFields[0]; for (int f = 0; f < nCols; f++) { if ("".equals(fields[f])) continue; if (colDescs[f].clazz.equals(Integer.TYPE) || colDescs[f].clazz.equals(Double.TYPE) || colDescs[f].clazz.equals(Float.TYPE)) allStrings = false; try { Object o = ConvertUtils.convert(fields[f], colDescs[f].clazz); if (null == o) { firstLineCompat = false; break; } } catch (Exception x) { firstLineCompat = false; break; } } if (firstLineCompat && !allStrings) _skipLines = 0; else _skipLines = 1; } if (_skipLines > 0) { String[] headers = lineFields[_skipLines - 1]; for (int f = 0; f < nCols; f++) colDescs[f].name = (f >= headers.length || "".equals(headers[f])) ? "column" + f : headers[f]; } else { for (int f = 0; f < colDescs.length; f++) { ColumnDescriptor colDesc = colDescs[f]; colDesc.name = "column" + f; } } _columns = colDescs; }
From source file:org.apache.jmeter.services.FileServer.java
private BufferedReader getReader(String alias, boolean recycle, boolean firstLineIsNames) throws IOException { FileEntry fileEntry = files.get(alias); if (fileEntry != null) { BufferedReader reader; if (fileEntry.inputOutputObject == null) { reader = createBufferedReader(fileEntry); fileEntry.inputOutputObject = reader; if (firstLineIsNames) { // read first line and forget reader.readLine();/* w w w . jav a 2 s .c o m*/ } } else if (!(fileEntry.inputOutputObject instanceof Reader)) { throw new IOException("File " + alias + " already in use"); } else { reader = (BufferedReader) fileEntry.inputOutputObject; if (recycle) { // need to check if we are at EOF already reader.mark(1); int peek = reader.read(); if (peek == -1) { // already at EOF reader.close(); reader = createBufferedReader(fileEntry); fileEntry.inputOutputObject = reader; if (firstLineIsNames) { // read first line and forget reader.readLine(); } } else { // OK, we still have some data, restore it reader.reset(); } } } return reader; } else { throw new IOException("File never reserved: " + alias); } }
From source file:com.pironet.tda.SunJDKParser.java
/** * parses a loggc file stream and reads any found class histograms and adds the to the dump store * * @param loggcFileStream the stream to read * @param root the root node of the dumps. *///from w w w .j av a 2s . c o m public void parseLoggcFile(InputStream loggcFileStream, DefaultMutableTreeNode root) { final BufferedReader bis = new BufferedReader(new InputStreamReader(loggcFileStream)); final List<HistogramTableModel> histograms = new Vector<>(); try { while (bis.ready()) { bis.mark(getMarkSize()); String nextLine = bis.readLine(); if (nextLine.startsWith("num #instances #bytes class name")) { bis.reset(); histograms.add(parseNextClassHistogram(bis)); } } // now add the found histograms to the tree. for (int i = histograms.size() - 1; i >= 0; i--) { DefaultMutableTreeNode dump = getNextDumpForHistogram(root); if (dump != null) { addHistogramToDump(dump, histograms.get(i)); } } } catch (IOException ex) { ex.printStackTrace(); } finally { IOUtils.closeQuietly(bis); } }
From source file:edu.ucla.stat.SOCR.chart.ChartTree_dynamic.java
/** * Creates the tree node and its subnods * /*from www .j a va2 s . c om*/ * @return A populated tree node. */ private MutableTreeNode createChartsNode(String name) { //System.out.println("adding-"+name+"-"); BufferedReader rder = startReaderBuffer(); DefaultMutableTreeNode node_root = new DefaultMutableTreeNode(name); String line, className, chartName; StringBuffer sb = new StringBuffer(); while ((line = readLine(rder)) != null) { if (line.toLowerCase().equalsIgnoreCase("[" + name + "]")) { while ((line = readLine(rder)) != null) { if (line.toLowerCase().startsWith("item")) { line = line.substring(line.indexOf("=") + 1); StringTokenizer tk = new StringTokenizer(line, "=,; "); chartName = tk.nextToken().trim(); className = tk.nextToken().trim(); // System.out.println("className =["+className+"]"); DefaultMutableTreeNode n = new DefaultMutableTreeNode( new DemoDescription(className, chartName)); node_root.add(n); } //item else if (line.toLowerCase().startsWith("subcategory")) { line = line.substring(line.indexOf("=") + 1); try { rder.mark(100); node_root.add(createChartsNode(line.trim())); rder.reset(); } catch (IOException e) { e.printStackTrace(); } } //subCategory else if (line.toLowerCase().startsWith("[")) { //System.out.println("end of "+name); return node_root; } } } } return node_root; }