List of usage examples for java.io Reader close
public abstract void close() throws IOException;
From source file:dk.dr.radio.net.Diverse.java
sStreng(InputStream is) throws IOException, UnsupportedEncodingException { // Det kan vre ndvendigt at hoppe over BOM mark - se http://android.forums.wordpress.org/topic/xml-pull-error?replies=2 //is.read(); is.read(); is.read(); // - dette virker kun hvis der ALTID er en BOM // Hop over BOM - hvis den er der! is = new BufferedInputStream(is); // bl.a. FileInputStream understtter ikke mark, s brug BufferedInputStream is.mark(1); // vi har faktisk kun brug for at sge n byte tilbage if (is.read() == 0xef) { is.read();//w w w . j av a 2 s .c o m is.read(); } // Der var en BOM! Ls de sidste 2 byte else is.reset(); // Der var ingen BOM - hop tilbage til start final char[] buffer = new char[0x3000]; StringBuilder out = new StringBuilder(); Reader in = new InputStreamReader(is, "UTF-8"); int read; do { read = in.read(buffer, 0, buffer.length); if (read > 0) { out.append(buffer, 0, read); } } while (read >= 0); in.close(); return out.toString(); }
From source file:com.rovemonteux.tormessenger.network.NetworkClient.java
public String read() throws IOException { Reader r = new InputStreamReader(netSocket.getInputStream(), Charset.forName("UTF-8")); int intch;//from ww w. j a v a2 s.c o m StringBuilder input = new StringBuilder(); while ((intch = r.read()) != 10) { char ch = (char) intch; input.append(ch); } r.close(); /*if (!(this.remoteUser == null) && !(this.remoteUser.length() < 1)) { chatFrame.chatArea.append(input.toString().trim()+"\n"); }*/ return input.toString().trim(); }
From source file:com.nary.io.FileUtils.java
public static void readFile(File filePath, StringBuilder buffer) throws IOException { BufferedReader reader = null; Reader inreader = null; try {// w w w. ja v a 2 s . co m inreader = new FileReader(filePath); reader = new BufferedReader(inreader); char[] chars = new char[8096]; int read; while ((read = reader.read(chars, 0, chars.length)) != -1) { buffer.append(chars, 0, read); } } finally { if (reader != null) try { reader.close(); } catch (IOException ignored) { } if (inreader != null) try { inreader.close(); } catch (IOException ignored) { } } }
From source file:com.sap.prd.mobile.ios.mios.UpdateVersionInPomMojo.java
Model readPom(File pom) throws IOException, XmlPullParserException { Reader r = null; try {//from ww w .jav a 2 s .com r = new InputStreamReader(new FileInputStream(pom), Charset.defaultCharset().name()); Model model = new MavenXpp3Reader().read(r); r.close(); return model; } finally { IOUtils.closeQuietly(r); } }
From source file:io.datalayer.conf.IniConfigurationTest.java
/** * Helper method for testing the load operation. Loads the specified content * into a configuration and then checks some properties. * * @param data the data to load/*from w w w . j a v a 2 s. com*/ */ private void checkLoad(String data) throws ConfigurationException, IOException { Reader reader = new StringReader(data); INIConfiguration instance = new INIConfiguration(); instance.load(reader); reader.close(); assertTrue(instance.getString("section1.var1").equals("foo")); assertTrue(instance.getInt("section1.var2") == 451); assertTrue(instance.getDouble("section2.var1") == 123.45); assertTrue(instance.getString("section2.var2").equals("bar")); assertTrue(instance.getBoolean("section3.var1")); assertTrue(instance.getSections().size() == 3); }
From source file:jp.aegif.nemaki.util.YamlManager.java
public Object loadYml() { InputStream is = getClass().getClassLoader().getResourceAsStream(baseModelFile); if (is == null) { log.error("yaml file not found"); }// w w w . j av a 2s . c o m Reader reader; try { reader = new InputStreamReader(is, "UTF-8"); reader = new BufferedReader(reader); StringBuffer buf = new StringBuffer(); int ch; while ((ch = reader.read()) >= 0) buf.append((char) ch); reader.close(); Object ydoc = YAML.load(buf.toString()); return ydoc; } catch (Exception e) { log.error(baseModelFile + " load failed", e); } return null; }
From source file:com.continuuity.loom.provisioner.mock.MockWorker.java
private String getResponseString(CloseableHttpResponse response) throws IOException { Reader reader = new InputStreamReader(response.getEntity().getContent(), Charsets.UTF_8); try {/*w ww . java2s.co m*/ return CharStreams.toString(reader); } finally { reader.close(); } }
From source file:com.github.sdbg.core.test.util.TestProject.java
/** * @return the {@link String} content of the {@link IFile}. *///from w w w . j av a 2s. c o m public String getFileString(IFile file) throws Exception { Reader reader = new InputStreamReader(file.getContents(), file.getCharset()); try { return CharStreams.toString(reader); } finally { reader.close(); } }
From source file:net.ontopia.topicmaps.impl.rdbms.ReadOnlyOccurrence.java
@Override public String getValue() { Object value = loadField(Occurrence.LF_value); if (value instanceof String) { return (String) value; } else if (value instanceof OnDemandValue) { OnDemandValue odv = (OnDemandValue) value; try {/*from www . j av a 2 s .c o m*/ Reader r = (Reader) odv.getValue(_p_getTransaction()); try { return IOUtils.toString(r); } finally { r.close(); } } catch (IOException e) { throw new OntopiaRuntimeException(e); } } else if (value != null) { throw new OntopiaRuntimeException("Occurrence value cannot be non-null at this point: " + value); } else { return null; // FIXME: or possibly something else } }
From source file:net.officefloor.tutorial.inherithttpserver.InheritHttpServerTest.java
/** * Undertakes the {@link HttpRequest} and ensures the responding page is as * expected./* w w w .j ava 2s .c om*/ * * @param url * URL. * @param fileNameContainingExpectedContent * Name of file containing the expected content. */ private void doTest(String url, String fileNameContainingExpectedContent) throws IOException { // Undertake the request HttpResponse response = this.client.execute(new HttpGet("http://localhost:7878/" + url)); assertEquals("Incorrect response status for URL " + url, 200, response.getStatusLine().getStatusCode()); String content = EntityUtils.toString(response.getEntity()); // Obtain the expected content InputStream contentInputStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(fileNameContainingExpectedContent); assertNotNull("Can not find file " + fileNameContainingExpectedContent, contentInputStream); Reader reader = new InputStreamReader(contentInputStream); StringWriter expected = new StringWriter(); for (int character = reader.read(); character != -1; character = reader.read()) { expected.append((char) character); } reader.close(); // Ensure the context is as expected assertEquals("Incorrect content for URL " + url, expected.toString(), content); }