List of usage examples for java.io InputStreamReader close
public void close() throws IOException
From source file:edu.illinois.cs.cogcomp.wikifier.utils.io.InFile.java
public static String readFileText(String file, String encoding) throws IOException { File f = new File(file); InputStreamReader isr = new InputStreamReader(new FileInputStream(f), encoding); System.out.println("character encoding = " + isr.getEncoding()); int c;//from w w w.j av a2 s.c o m StringBuffer res = new StringBuffer(); while ((c = isr.read()) != -1) { res.append((char) c); } isr.close(); return res.toString(); }
From source file:com.aliyun.odps.ship.DShip.java
protected static void showHelp(String filename) throws IOException { InputStream ins = DShip.class.getResourceAsStream("/" + filename); InputStreamReader reader = new InputStreamReader(ins, "utf-8"); int c = reader.read(); while (c != -1) { System.out.print((char) c); c = reader.read();/*from w w w.j a v a 2 s . c om*/ } reader.close(); }
From source file:bluej.collect.CollectUtility.java
/** * Reads a source code file from the project, and anonymises it *//* www . j a va 2 s . c om*/ static String readFileAndAnonymise(ProjectDetails proj, File f) { try { StringBuilder sb = new StringBuilder(); FileInputStream inputStream = new FileInputStream(f); InputStreamReader reader = new InputStreamReader(inputStream, proj.charset); char[] buf = new char[4096]; int read = reader.read(buf); while (read != -1) { sb.append(buf, 0, read); read = reader.read(buf); } reader.close(); inputStream.close(); return CodeAnonymiser.anonymise(sb.toString()); } catch (IOException ioe) { return null; } }
From source file:com.panet.imeta.core.vfs.KettleVFS.java
/** * Read a text file (like an XML document). WARNING DO NOT USE FOR DATA FILES. * /*from w w w .ja v a2 s . c o m*/ * @param vfsFilename the filename or URL to read from * @param charSetName the character set of the string (UTF-8, ISO8859-1, etc) * @return The content of the file as a String * @throws IOException */ public static String getTextFileContent(String vfsFilename, String charSetName) throws IOException { InputStream inputStream = getInputStream(vfsFilename); InputStreamReader reader = new InputStreamReader(inputStream, charSetName); int c; StringBuffer stringBuffer = new StringBuffer(); while ((c = reader.read()) != -1) stringBuffer.append((char) c); reader.close(); inputStream.close(); return stringBuffer.toString(); }
From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java
public static void readUtterances(RuntimeBean runtime, URI source) throws IOException { InputStream is = source.toURL().openStream(); InputStreamReader rdr = new InputStreamReader(is); UtteranceLogic.read(runtime.getApp(), rdr); rdr.close(); runtime.firePropertyChange("app", null, runtime.getApp()); setProp("app.utterances", source.toString()); }
From source file:jo.alexa.sim.ui.logic.RuntimeLogic.java
public static void readIntents(RuntimeBean runtime, URI source) throws IOException { InputStream is = source.toURL().openStream(); InputStreamReader rdr = new InputStreamReader(is); ApplicationLogic.readIntents(runtime.getApp(), rdr); rdr.close(); runtime.firePropertyChange("app", null, runtime.getApp()); setProp("app.intents", source.toString()); }
From source file:Main.java
public static String toConvertString(InputStream is) { StringBuilder res = new StringBuilder(); InputStreamReader isr = new InputStreamReader(is); BufferedReader read = new BufferedReader(isr); try {/*from w w w.ja v a 2s. c o m*/ String line; line = read.readLine(); while (line != null) { res.append(line).append("<br>"); line = read.readLine(); } } catch (IOException e) { e.printStackTrace(); } finally { try { isr.close(); read.close(); is.close(); } catch (IOException e) { e.printStackTrace(); } } return res.toString(); }
From source file:chat.Models.java
/** @param test whether use the testing database */ public static AnnotationConfiguration build(boolean test) throws Exception { AnnotationConfiguration conf = new AnnotationConfiguration() { private static final long serialVersionUID = 1L; @Override/* www .ja v a 2 s .co m*/ public SessionFactory buildSessionFactory() throws HibernateException { if (!"org.hsqldb.jdbcDriver".equals(getProperty(Environment.DRIVER))) return super.buildSessionFactory(); // fix the issue of hsqldb write delay stupid default value SessionFactory fac = super.buildSessionFactory(); try { SessionImpl hib = (SessionImpl) fac.openSession(); hib.beginTransaction(); Statement stat = hib.getJDBCContext().borrowConnection().createStatement(); stat.executeUpdate("SET WRITE_DELAY FALSE"); hib.getTransaction().commit(); stat.close(); hib.close(); LOG.info("SET WRITE_DELAY FALSE"); } catch (Exception e) { throw new Error(e); } return fac; } }; InputStreamReader connect = new InputStreamReader( Models.class.getResourceAsStream("/hibernate.connect.properties"), "UTF-8"); conf.getProperties().load(connect); connect.close(); conf.setNamingStrategy(new NamingStrategy() { @Override public String classToTableName(String entity) { return StringHelper.unqualify(entity); } @Override public String propertyToColumnName(String property) { return StringHelper.unqualify(property); } @Override public String tableName(String table) { return table; } @Override public String columnName(String column) { return column; } @Override public String collectionTableName(String ownerEntity, String ownerTable, String associatedEntity, String associatedTable, String property) { return ownerTable + "_" + StringHelper.unqualify(property); } @Override public String joinKeyColumnName(String joinedColumn, String joinedTable) { return joinedColumn; } @Override public String foreignKeyColumnName(String property, String propertyEntity, String propertyTable, String referencedColumn) { return property != null ? StringHelper.unqualify(property) : propertyTable; } @Override public String logicalColumnName(String column, String property) { return StringHelper.isEmpty(column) ? StringHelper.unqualify(property) : column; } @Override public String logicalCollectionTableName(String table, String ownerTable, String associatedTable, String property) { if (table != null) return table; return ownerTable + "_" + StringHelper.unqualify(property); } @Override public String logicalCollectionColumnName(String column, String property, String referencedColumn) { return StringHelper.isEmpty(column) ? property + "_" + referencedColumn : column; } }); for (Class<?> c : Class2.packageClasses(Id.class)) conf.addAnnotatedClass(c); if (!"false".equals(conf.getProperty(Environment.AUTOCOMMIT))) throw new RuntimeException(Environment.AUTOCOMMIT + " must be false"); if (test) conf.setProperty(Environment.URL, conf.getProperty(Environment.URL + ".test")); return conf; }
From source file:com.sun.socialsite.config.RuntimeConfig.java
/** * Get the runtime configuration definitions XML file as a string. * * This is basically a convenience method for accessing this file. * The file itself contains meta-data about what configuration * properties we change at runtime via the UI and how to setup * the display for editing those properties. *//*from w w w. j a v a2 s .c o m*/ public static String getRuntimeConfigDefsAsString() { log.debug("Trying to load runtime config defs file"); try { InputStream in = Config.class.getResourceAsStream(DEFINITIONS_FILE); InputStreamReader reader = new InputStreamReader(in); StringWriter configString = new StringWriter(); char[] buf = new char[8196]; int length = 0; while ((length = reader.read(buf)) > 0) { configString.write(buf, 0, length); } reader.close(); return configString.toString(); } catch (Exception e) { log.error("Error loading runtime config defs file", e); } return ""; }
From source file:ext.services.xml.XMLUtils.java
/** * Reads an object from a file as xml.// w ww .ja v a 2s . c o m * * @param filename filename * * @return The object read from the xml file * * @throws IOException Signals that an I/O exception has occurred. */ public static Object readObjectFromFile(String filename) throws IOException { InputStreamReader inputStreamReader = null; try { inputStreamReader = new InputStreamReader(new FileInputStream(filename), "UTF-8"); return xStream.fromXML(inputStreamReader); } finally { if (inputStreamReader != null) { inputStreamReader.close(); } } }