List of usage examples for java.io Reader close
public abstract void close() throws IOException;
From source file:android.net.http.AbstractProxyTest.java
private String contentToString(HttpResponse response) throws IOException { StringWriter writer = new StringWriter(); char[] buffer = new char[1024]; Reader reader = new InputStreamReader(response.getEntity().getContent()); int length;/* w ww .j a va2s . com*/ while ((length = reader.read(buffer)) != -1) { writer.write(buffer, 0, length); } reader.close(); return writer.toString(); }
From source file:ConcatReader.java
/** * Close the stream and any underlying streams. * Once a stream has been closed, further read(), ready(), mark(), or reset() * invocations will throw an IOException. Closing a previously-closed stream, * however, has no effect.//from w w w. j a v a 2 s . c o m * * @throws IOException If an I/O error occurs * * @since ostermillerutils 1.04.00 */ @Override public void close() throws IOException { if (closed) return; for (Reader reader : readerQueue) { reader.close(); } closed = true; }
From source file:com.l2jfree.config.L2Properties.java
@Override public void load(Reader reader) throws IOException { try {/*from w ww .j a va2 s.c o m*/ super.load(reader); } finally { reader.close(); } }
From source file:com.sun.syndication.io.WireFeedInput.java
/** * Builds an WireFeed (RSS or Atom) from a file. * <p>/*w ww . ja v a 2s.c om*/ * NOTE: This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom.Document)'. * <p> * @param file file to read to create the WireFeed. * @return the WireFeed read from the file. * @throws FileNotFoundException thrown if the file could not be found. * @throws IOException thrown if there is problem reading the file. * @throws IllegalArgumentException thrown if feed type could not be understood by any of the underlying parsers. * @throws FeedException if the feed could not be parsed * */ public WireFeed build(File file) throws FileNotFoundException, IOException, IllegalArgumentException, FeedException { WireFeed feed; Reader reader = new FileReader(file); if (_xmlHealerOn) { reader = new XmlFixerReader(reader); } feed = build(reader); reader.close(); return feed; }
From source file:gdv.xport.satz.SatzTest.java
/** * Hier probieren wir jetzt den Import ueber einen Reader. * * @throws IOException sollte eigenlich nicht passieren, da wir von einem * String lesen//from w w w . ja v a 2 s. c o m */ @Test public void testImportFromReader() throws IOException { Satz x = new Datensatz(123, 7); Reader reader = new StringReader(INPUT_SATZ_123); try { checkImport(x, reader); } finally { reader.close(); } }
From source file:com.ieasy.basic.util.file.FileUtils.java
/** * ???//from w ww.j a va 2 s .co m * * @param fileName * ?? */ public static void readFileByChars(String fileName) { File file = new File(fileName); Reader reader = null; try { System.out.println("???"); // reader = new InputStreamReader(new FileInputStream(file)); int tempchar; while ((tempchar = reader.read()) != -1) { // windowsrn? // ? // ?r?n? if (((char) tempchar) != 'r') { System.out.print((char) tempchar); } } reader.close(); } catch (Exception e) { e.printStackTrace(); } try { System.out.println("???"); // char[] tempchars = new char[30]; int charread = 0; reader = new InputStreamReader(new FileInputStream(fileName)); // charread? while ((charread = reader.read(tempchars)) != -1) { // ??r? if ((charread == tempchars.length) && (tempchars[tempchars.length - 1] != 'r')) { System.out.print(tempchars); } else { for (int i = 0; i < charread; i++) { if (tempchars[i] == 'r') { continue; } else { System.out.print(tempchars[i]); } } } } } catch (Exception e1) { e1.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } }
From source file:gov.nih.nci.cabig.caaers.api.AdeersReportGeneratorTest.java
public void testImage() throws Exception { generator.setAdverseEventReportSerializer(new AdverseEventReportSerializer()); generator.setEvaluationService(evaluationService); String xmlFileName = "expedited_report_caaers_complete.xml"; InputStream is = AdeersReportGeneratorTest.class.getClassLoader().getResourceAsStream(xmlFileName); Writer writer = new StringWriter(); if (is != null) { char[] buffer = new char[1024]; try {// w w w .j a va 2 s . co m Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } reader.close(); } finally { is.close(); } } String caAERSXML = writer.toString(); //System.out.println(caAERSXML); long now = System.currentTimeMillis(); String fileName = System.getProperty("java.io.tmpdir") + File.separator + "ae" + String.valueOf(now) + "report.png"; List<String> list = generator.generateImage(caAERSXML, fileName); }
From source file:eu.scape_project.planning.policies.OrganisationalPolicies.java
private void resolvePreservationCases(String rdfPolicies) throws Exception { preservationCases.clear();/*ww w . j a va2 s. c o m*/ Model model = ModelFactory.createMemModelMaker().createDefaultModel(); Reader reader = new StringReader(rdfPolicies); model = model.read(reader, null); reader.close(); // String cpModelFile = POLICY_ONTOLOGY_DIR + File.separator + // CONTROL_POLICY_FILE; Model cpModel = FileManager.get().loadModel("data/vocabulary/control-policy.rdf"); cpModel.add(FileManager.get().loadModel("data/vocabulary/control-policy_modalities.rdf")); cpModel.add(FileManager.get().loadModel("data/vocabulary/control-policy_qualifiers.rdf")); model = model.add(cpModel); // query organisation from rdf String statement = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX org: <http://www.w3.org/ns/org#> " + "PREFIX owl: <http://www.w3.org/2002/07/owl#> " + "SELECT ?organisation WHERE { " + "?org rdf:type owl:NamedIndividual ." + "?org org:identifier ?organisation } "; Query orgQuery = QueryFactory.create(statement, Syntax.syntaxARQ); QueryExecution orgQe = QueryExecutionFactory.create(orgQuery, model); ResultSet orgResults = orgQe.execSelect(); try { if ((orgResults != null) && (orgResults.hasNext())) { QuerySolution orgQs = orgResults.next(); this.organisation = orgQs.getLiteral("organisation").toString(); } } finally { orgQe.close(); } // query all preservationCases statement = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> " + "PREFIX pc: <http://purl.org/DP/preservation-case#> " + "SELECT ?preservationcase ?name ?contentset WHERE { " + "?preservationcase rdf:type pc:PreservationCase . " + "?preservationcase skos:prefLabel ?name . " + "?preservationcase pc:hasContentSet ?contentset } "; Query pcQuery = QueryFactory.create(statement, Syntax.syntaxARQ); QueryExecution pcQe = QueryExecutionFactory.create(pcQuery, model); ResultSet pcResults = pcQe.execSelect(); try { while ((pcResults != null) && (pcResults.hasNext())) { QuerySolution pcQs = pcResults.next(); PreservationCase pc = new PreservationCase(); pc.setName(pcQs.getLiteral("name").toString()); pc.setUri(pcQs.getResource("preservationcase").getURI()); pc.setContentSet(pcQs.getResource("contentset").getURI()); preservationCases.add(pc); // determine user communities statement = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> " + "PREFIX pc: <http://purl.org/DP/preservation-case#> " + "SELECT ?usercommunity WHERE { " + "<" + pc.getUri() + ">" + " pc:hasUserCommunity ?usercommunity } "; Query ucQuery = QueryFactory.create(statement, Syntax.syntaxARQ); QueryExecution ucQe = QueryExecutionFactory.create(ucQuery, model); ResultSet ucResults = ucQe.execSelect(); try { String ucs = ""; while ((ucResults != null) && ucResults.hasNext()) { QuerySolution ucQs = ucResults.next(); ucs += "," + ucQs.getResource("usercommunity").getLocalName(); } if (StringUtils.isNotEmpty(ucs)) { pc.setUserCommunities(ucs.substring(1)); } } finally { ucQe.close(); } // query objectives statement = "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> " + "PREFIX pc: <http://purl.org/DP/preservation-case#> " + "PREFIX skos: <http://www.w3.org/2004/02/skos/core#> " + "PREFIX cp: <http://purl.org/DP/control-policy#> " + "SELECT ?objective ?objective_label ?objectiveType ?measure ?modality ?value ?qualifier WHERE { " + "<" + pc.getUri() + ">" + " pc:hasObjective ?objective . " + "?objective rdf:type ?objectiveType . " + "?objectiveType rdfs:subClassOf cp:Objective . " + "?objective skos:prefLabel ?objective_label . " + "?objective cp:measure ?measure . " + "?objective cp:value ?value . " + "OPTIONAL {?objective cp:qualifier ?qualifier} . " + "OPTIONAL {?objective cp:modality ?modality} }"; Query query = QueryFactory.create(statement, Syntax.syntaxARQ); QueryExecution qe = QueryExecutionFactory.create(query, model); ResultSet results = qe.execSelect(); try { while ((results != null) && (results.hasNext())) { QuerySolution qs = results.next(); ControlPolicy cp = new ControlPolicy(); String controlPolicyUri = qs.getResource("objective").getURI(); String controlPolicyName = qs.getLiteral("objective_label").toString(); String measureUri = qs.getResource("measure").toString(); String modality = qs.getResource("modality").getLocalName(); String value = qs.getLiteral("value").getString(); Resource qualifier = qs.getResource("qualifier"); Measure m = criteriaManager.getMeasure(measureUri); cp.setUri(controlPolicyUri); cp.setName(controlPolicyName); cp.setValue(value); cp.setMeasure(m); if (qualifier != null) { cp.setQualifier(ControlPolicy.Qualifier.valueOf(qualifier.getLocalName())); } else { cp.setQualifier(ControlPolicy.Qualifier.EQ); } cp.setModality(ControlPolicy.Modality.valueOf(modality)); pc.getControlPolicies().add(cp); } } finally { qe.close(); } } } finally { pcQe.close(); } }
From source file:de.hybris.platform.atddengine.ant.tasks.GenerateProxies.java
private File generateCleanTestSuiteFile(final File testSuiteFile) throws IOException, FileNotFoundException { final File genFile = new File(generatedDir, testSuiteFile.getName()); final FileWriter writer = new FileWriter(genFile); final Reader reader = new FileReader(testSuiteFile); final String fileContents = IOUtils.toString(reader); writer.write(fileContents.replaceAll(">\\s+<", "><")); // remove whitespace from XML snippets writer.close();/*w ww .j ava 2 s.c o m*/ reader.close(); return genFile; }
From source file:net.ontopia.topicmaps.core.VariantNameTest.java
public void testReader() throws Exception { // read file and store in object File filein = TestFileUtils.getTransferredTestInputFile("various", "clob.xml"); File fileout = TestFileUtils.getTestOutputFile("various", "clob.xml.out"); Reader ri = new FileReader(filein); long inlen = filein.length(); variant.setReader(ri, inlen, DataTypes.TYPE_BINARY); assertTrue("Variant datatype is incorrect", Objects.equals(DataTypes.TYPE_BINARY, variant.getDataType())); // read and decode content Reader ro = variant.getReader(); try {//from w ww.ja va 2s. co m Writer wo = new FileWriter(fileout); try { IOUtils.copy(ro, wo); } finally { wo.close(); } } finally { ro.close(); } assertTrue("Reader value is null", ro != null); try { ri = new FileReader(filein); ro = new FileReader(fileout); long outlen = variant.getLength(); try { assertTrue("Variant value put in is not the same as the one we get out.", IOUtils.contentEquals(ro, ri)); assertTrue("Variant value length is different", inlen == outlen); } finally { ri.close(); } } finally { ro.close(); } }