List of usage examples for java.io Reader toString
public String toString()
From source file:Main.java
/** * Creates a DOM from a file representation of an xml record * /* w ww.jav a2s . com*/ * @param reader * the xml reader * @return the DOM document */ public static Document parseDom(Reader reader) { try { DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new org.xml.sax.InputSource(reader)); } catch (Exception e) { throw new RuntimeException("Could not parse DOM for '" + reader.toString() + "'!", e); } }
From source file:com.mmj.app.lucene.analyzer.JcsegWordAnalyzer.java
@SuppressWarnings("unused") @Override/* w w w . ja va 2 s.co m*/ public List<String> splitWords(Reader input, SegMode segMode) { List<String> result = new ArrayList<String>(); if (seg == null) { return Arrays.asList(input.toString()); } // jcseg? Object[] paras = createParas(false); IWord word = null; try { seg.reset(input); while ((word = seg.next()) != null) { result.add(word.getValue()); } } catch (Exception e) { logger.error(e.getMessage(), e); } return result; }
From source file:com.abstratt.mdd.internal.frontend.textuml.TextUMLCompiler.java
private Start parse(Reader source, IProblemTracker problems) throws CoreException { ProblemBuilder<Node> problemBuilder = new ProblemBuilder<Node>(problems, new SCCTextUMLSourceMiner()); PushbackReader in = new PushbackReader(source, 64 * 1024); Lexer lexer = new Lexer(in); Parser parser = new Parser(lexer); try {/*from w w w .ja v a 2s . co m*/ return parser.parse(); } catch (ParserException e) { if (problems != null) problemBuilder.addProblem( new SyntaxProblem("Found: '" + e.getToken().getText() + "'. " + e.getMessage()), e.getToken()); } catch (LexerException e) { if (problems != null) { SyntaxProblem problem = new SyntaxProblem(e.getMessage()); problem.setAttribute(IProblem.LINE_NUMBER, SCCTextUMLSourceMiner.parseLineNumber(e.getMessage())); problemBuilder.addProblem(problem, null); } } catch (IOException e) { IStatus status = new Status(IStatus.ERROR, TextUMLConstants.PLUGIN_ID, 0, "Error reading source unit: " + source.toString(), e); throw new CoreException(status); } finally { try { in.close(); } catch (IOException e) { // not interested in failures while closing } } return null; }
From source file:org.echocat.adam.configuration.ConfigurationMarshaller.java
@Nullable public static Configuration unmarshall(@Nonnull Reader content, @Nullable String systemId) { try {// w w w. j av a 2s . com final Unmarshaller unmarshaller = unmarshallerFor(content, systemId); final InputSource source = new InputSource(content); source.setSystemId(systemId != null ? systemId : "<unknownSource>"); return (Configuration) unmarshaller.unmarshal(source); } catch (final UnmarshalException e) { throw new ParseException(e, (systemId != null ? systemId : content.toString())); } catch (final JAXBException e) { throw new ConfigurationException("Could not unmarshall: " + (systemId != null ? systemId : content), e); } }
From source file:org.intermine.bio.dataconversion.XenmineConverter.java
/** * /*w ww . j a va2 s . c o m*/ * @param reader * @throws Exception * @throws ObjectStoreException */ private void processScaffoldMappingFile(Reader preader, String genomeBuild) throws Exception, ObjectStoreException { /* Xenbase gene ID * gene symbol * JGI Model Name * JGI Scaffold Name * JGI Scaffold Start Position * JGI Scaffold End Position * JGI Scaffold Strand * GenePageToJgiTropicalisScaffoldMapping_4.1.txt:XB-GENE-1021745 c1orf228 e_gw1.1.454.1 scaffold_1 4235 14986 -1 */ System.out.println("Processing scaffold file...."); Iterator<?> tsvIter; try { tsvIter = FormattedTextParser.parseTabDelimitedReader(preader); } catch (Exception e) { throw new Exception("cannot parse file: " + preader.toString(), e); } Item organism = createItem("Organism"); organism.setAttribute("taxonId", TAXON_ID); organism.setAttribute("genus", "Xenopus"); organism.setAttribute("species", "tropicalis"); organism.setAttribute("name", "Xenopus tropicalis"); organism.setAttribute("shortName", "X. tropicalis"); store(organism); while (tsvIter.hasNext()) { String[] line = (String[]) tsvIter.next(); if (line.length < 7) { LOG.error("Couldn't process line. Expected 7 cols, but was " + line.length); continue; } String xbGeneId = line[0].trim(); String symbol = line[1].trim(); String jgimodelName = line[2].trim(); String chromosome = line[3].trim(); String start = line[4].trim(); String end = line[5].trim(); String strand = line[6].trim(); String length = getLength(start, end); Item gene = createItem("Gene"); gene.setAttribute("primaryIdentifier", jgimodelName); gene.setAttribute("secondaryIdentifier", xbGeneId); gene.setAttribute("symbol", symbol); gene.setAttribute("genomeBuild", genomeBuild); String chrRefId = getChromosome(chromosome, organism.getIdentifier()); gene.setReference("chromosome", chrRefId); String locationRefId = getLocation(gene, chrRefId, start, end, strand); gene.setReference("chromosomeLocation", locationRefId); gene.setAttribute("jgiModelName", jgimodelName); gene.setReference("organism", organism); genes.put(xbGeneId, gene); } preader.close(); }
From source file:org.intermine.bio.dataconversion.XenmineConverter.java
/** * /*from www . j av a 2 s . c o m*/ * @param reader * @throws Exception * @throws ObjectStoreException */ private void processLaevisScaffoldMappingFile(Reader preader, String genomeBuild) throws Exception, ObjectStoreException { /* Xenbase gene ID * gene symbol * JGI Model Name * JGI Scaffold Name * JGI Scaffold Start Position * JGI Scaffold End Position * JGI Scaffold Strand * XB-GENE-478732 impdh2 XeXenL6RMv10052779m.g Scaffold87688 113849 139524 -1 */ System.out.println("Processing laevis scaffold file...."); Iterator<?> tsvIter; try { tsvIter = FormattedTextParser.parseTabDelimitedReader(preader); } catch (Exception e) { throw new Exception("cannot parse file: " + preader.toString(), e); } Item organism = createItem("Organism"); organism.setAttribute("taxonId", "8355"); organism.setAttribute("genus", "Xenopus"); organism.setAttribute("species", "laevis"); organism.setAttribute("name", "Xenopus laevis"); organism.setAttribute("shortName", "X. laevis"); store(organism); while (tsvIter.hasNext()) { String[] line = (String[]) tsvIter.next(); if (line.length < 7) { LOG.error("Couldn't process line. Expected 7 cols, but was " + line.length); continue; } String xbGeneId = line[0].trim(); String symbol = line[1].trim(); String jgimodelName = line[2].trim(); String chromosome = line[3].trim(); String start = line[4].trim(); String end = line[5].trim(); String strand = line[6].trim(); String length = getLength(start, end); Item gene = createItem("Gene"); gene.setAttribute("primaryIdentifier", jgimodelName); gene.setAttribute("secondaryIdentifier", xbGeneId); if (!symbol.equalsIgnoreCase("unnamed")) gene.setAttribute("symbol", symbol); gene.setAttribute("genomeBuild", genomeBuild); String chrRefId = getChromosome(chromosome, organism.getIdentifier()); gene.setReference("chromosome", chrRefId); String locationRefId = getLocation(gene, chrRefId, start, end, strand); gene.setReference("chromosomeLocation", locationRefId); gene.setAttribute("jgiModelName", jgimodelName); gene.setReference("organism", organism); genes.put(xbGeneId, gene); } preader.close(); }
From source file:org.intermine.bio.dataconversion.XenmineConverter.java
/** * //from w ww . jav a 2 s.c om * @param reader * @throws Exception * @throws ObjectStoreException */ private void processNameFile(Reader preader, String genomeBuild) throws Exception, ObjectStoreException { /* model name * Xenbase tropicalis gene ID * gene symbol * gene name */ System.out.println("Processing Names file...."); Iterator<?> tsvIter; try { tsvIter = FormattedTextParser.parseTabDelimitedReader(preader); } catch (Exception e) { throw new Exception("cannot parse file: " + preader.toString(), e); } while (tsvIter.hasNext()) { String[] line = (String[]) tsvIter.next(); if (line.length < 4) { LOG.error("Couldn't process line. Expected 4 cols, but was " + line.length); continue; } String jgimodelname = line[0].trim(); String primaryIdentifier = line[1].trim(); String symbol = line[2].trim(); String name = line[3].trim(); Item gene = genes.get(primaryIdentifier); if (gene != null) { gene.setAttribute("name", name); } } preader.close(); }
From source file:org.intermine.bio.dataconversion.XenmineConverter.java
/** * //from w ww.jav a 2 s .c o m * @param reader * @throws Exception * @throws ObjectStoreException */ private void processNcbiProteinFile(Reader preader) throws Exception, ObjectStoreException { /* gi * accession * Xenbase gene ID * gene symbol * 1000735 AAA84444 XB-GENE-865674 gsk3b */ System.out.println("Processing NCBI-PROTEIN file...."); Iterator<?> tsvIter; try { tsvIter = FormattedTextParser.parseTabDelimitedReader(preader); } catch (Exception e) { throw new Exception("cannot parse file: " + preader.toString(), e); } while (tsvIter.hasNext()) { String[] line = (String[]) tsvIter.next(); if (line.length < 4) { LOG.error("Couldn't process line. Expected 4 cols, but was " + line.length); continue; } String gi = line[0].trim(); String accession = line[1].trim(); String xenbaseGeneId = line[2].trim(); String symbol = line[3].trim(); //System.out.println("identifier.." + gi + " accession " + accession); Item gene = genes.get(xenbaseGeneId); if (gene != null) { getCrossReference(gene.getIdentifier(), gi, accession, "NCBI Protein"); } } preader.close(); }
From source file:org.intermine.bio.dataconversion.XenmineConverter.java
/** * // ww w . j ava2s. c o m * @param reader * @throws Exception * @throws ObjectStoreException */ private void processUnigeneEntrezFile(Reader preader) throws Exception, ObjectStoreException { /* Xenbase gene ID * gene symbol * Entrez ID * Unigene ID * XB-GENE-478054 trnt1 394602 Str.7616 */ System.out.println("Processing UNIGENE ENTREZ file...."); Iterator<?> tsvIter; try { tsvIter = FormattedTextParser.parseTabDelimitedReader(preader); } catch (Exception e) { throw new Exception("cannot parse file: " + preader.toString(), e); } while (tsvIter.hasNext()) { String[] line = (String[]) tsvIter.next(); if (line.length < 4) { LOG.error("Couldn't process line. Expected 4 cols, but was " + line.length); continue; } String xenbaseGeneId = line[0].trim(); String symbol = line[1].trim(); String entrezId = line[2].trim(); String unigeneId = line[3].trim(); Item gene = genes.get(xenbaseGeneId); if (gene != null) { if (StringUtils.isNotEmpty(entrezId)) getCrossReference(gene.getIdentifier(), entrezId, "", "Entrez Gene ID"); if (StringUtils.isNotEmpty(unigeneId)) getCrossReference(gene.getIdentifier(), unigeneId, "", "Unigene ID"); } } preader.close(); }
From source file:org.intermine.bio.dataconversion.XenmineConverter.java
/** * //w w w. jav a2 s . co m * @param reader * @throws Exception * @throws ObjectStoreException */ private void processNcbiMrnaFile(Reader preader) throws Exception, ObjectStoreException { /* gi * accession * Xenbase gene ID * gene symbol * 1000735 AAA84444 XB-GENE-865674 gsk3b */ System.out.println("Processing NCBI-MRNA file...."); Iterator<?> tsvIter; try { tsvIter = FormattedTextParser.parseTabDelimitedReader(preader); } catch (Exception e) { throw new Exception("cannot parse file: " + preader.toString(), e); } while (tsvIter.hasNext()) { String[] line = (String[]) tsvIter.next(); if (line.length < 4) { LOG.error("Couldn't process line. Expected 4 cols, but was " + line.length); continue; } String gi = line[0].trim(); String accession = line[1].trim(); String xenbaseGeneId = line[2].trim(); String symbol = line[3].trim(); Item gene = genes.get(xenbaseGeneId); if (gene != null) { getCrossReference(gene.getIdentifier(), gi, accession, "NCBI mRNA"); } } preader.close(); }