@Override public int read(char[] cbuf, int off, int len) throws IOException { init(); return internalIn2.read(cbuf, off, len); } }
public static String checkScientificNameAtNCBI(String scientificName) throws IOException { if (!taxonomyCache.containsKey(scientificName)) { String query = NCBI_ENTREZ_UTILS_URL + URLEncoder.encode(scientificName, "UTF-8"); final HttpClient httpclient = HttpClientBuilder.create().build(); HttpGet httpget = new HttpGet(query); HttpResponse response = httpclient.execute(httpget); String out = parseEntity(response.getEntity()); DocumentBuilder docBuilder; try { docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document d = docBuilder.newDocument(); TransformerFactory.newInstance().newTransformer().transform(new StreamSource(new UnicodeReader(out)), new DOMResult(d)); NodeList nl = d.getElementsByTagName("Id"); if (nl.getLength() > 0) { taxonomyCache.put(scientificName, nl.item(0).getTextContent()); } } catch (ParserConfigurationException | TransformerException | TransformerFactoryConfigurationError e) { throw new IOException("Taxon lookup error", e); } } return taxonomyCache.get(scientificName); }
@Override public void close() throws IOException { init(); internalIn2.close(); }