List of usage examples for java.io FileReader close
public void close() throws IOException
From source file:org.accada.hal.impl.sim.BatchSimulator.java
/** * initializes the fields and starts the simulator. * * @throws SimulatorException if the event input file could not be opened. *//* ww w .ja v a2s .com*/ private void initSimulator() throws SimulatorException { // load properties from config file XMLConfiguration config = new XMLConfiguration(); URL fileurl = ResourceLocator.getURL(configFile, defaultConfigFile, this.getClass()); try { config.load(fileurl); } catch (ConfigurationException ce) { throw new SimulatorException("Can not load config file '" + configFile + "'."); } // get properties String file = config.getString("batchfile"); cycles = config.getLong("iterations"); // find batchfile URL batchfileurl = ResourceLocator.getURL(file, file, this.getClass()); try { eventFile = new File(batchfileurl.toURI()); } catch (URISyntaxException e1) { throw new SimulatorException("Can not creat URI of batchfile '" + file + "'."); } rfidThread = null; threadRunning = false; stopRequested = false; try { // tries to open file FileReader in = new FileReader(eventFile); in.close(); // start simulator thread start(); } catch (IOException e) { throw new SimulatorException("Cannot open event file '" + file + "': " + e); } }
From source file:org.chorusbdd.chorus.tools.webagent.store.FileSystemXmlStore.java
private WebAgentTestSuite loadSuite(File f) throws Exception { FileReader fileReader = null; try {/* w w w. java 2 s.c o m*/ fileReader = new FileReader(f); TestSuite suite = xmlMarshaller.read(fileReader); return new WebAgentTestSuite(suite); } finally { if (fileReader != null) { try { fileReader.close(); } catch (Exception e) { log.error("Failed to close file reader for file " + f, e); } } } }
From source file:com.whatsthatlight.teamcity.hipchat.HipChatConfigurationController.java
public void loadConfiguration() throws IOException { XStream xstream = new XStream(); xstream.setClassLoader(this.configuration.getClass().getClassLoader()); xstream.setClassLoader(HipChatProjectConfiguration.class.getClassLoader()); xstream.processAnnotations(HipChatConfiguration.class); FileReader fileReader = new FileReader(this.configFilePath); HipChatConfiguration configuration = (HipChatConfiguration) xstream.fromXML(fileReader); fileReader.close(); // Copy the values, because we need it on the original shared (bean), // which is a singleton this.configuration.setApiUrl(configuration.getApiUrl()); this.configuration.setApiToken(configuration.getApiToken()); this.configuration.setDefaultRoomId(configuration.getDefaultRoomId()); this.configuration.setNotifyStatus(configuration.getDefaultNotifyStatus()); this.configuration.setDisabledStatus(configuration.getDisabledStatus()); if (configuration.getEvents() != null) { this.configuration.getEvents().setBuildStartedStatus(configuration.getEvents().getBuildStartedStatus()); this.configuration.getEvents() .setBuildSuccessfulStatus(configuration.getEvents().getBuildSuccessfulStatus()); this.configuration.getEvents().setBuildFailedStatus(configuration.getEvents().getBuildFailedStatus()); this.configuration.getEvents() .setBuildInterruptedStatus(configuration.getEvents().getBuildInterruptedStatus()); this.configuration.getEvents() .setServerStartupStatus(configuration.getEvents().getServerStartupStatus()); this.configuration.getEvents() .setServerShutdownStatus(configuration.getEvents().getServerShutdownStatus()); }/*from w ww.j a v a2s . c o m*/ if (configuration.getProjectRoomMap() != null) { for (HipChatProjectConfiguration projectConfiguration : configuration.getProjectRoomMap()) { this.configuration.setProjectConfiguration(projectConfiguration); } } }
From source file:com.bt.aloha.testing.SimpleSipStackLogEnhancerTest.java
private String readTargetFile() throws IOException { FileReader fr = null; try {// w ww. jav a2 s . co m char[] buff = new char[(int) tempTargetFile.length()]; fr = new FileReader(tempTargetFile); fr.read(buff); String res = new String(buff); log.info("Read:\n" + res); return res; } finally { if (fr != null) fr.close(); } }
From source file:org.apache.torque.generator.control.DeeplyNestedMergepointsTest.java
@Test public void testDeeplyNestedMergepointsGeneration() throws Exception { File targetDir = new File("target/test/deeplyNestedMergepoints"); FileUtils.deleteDirectory(targetDir); Controller controller = new Controller(); List<UnitDescriptor> unitDescriptors = new ArrayList<UnitDescriptor>(); CustomProjectPaths projectPaths = new CustomProjectPaths( new Maven2DirectoryProjectPaths(new File("src/test/deeplyNestedMergepoints"))); projectPaths.setOutputDirectory(null, targetDir); unitDescriptors.add(new UnitDescriptor(UnitDescriptor.Packaging.DIRECTORY, projectPaths, new DefaultTorqueGeneratorPaths())); controller.run(unitDescriptors);//from w w w. j ava2s . c om assertTrue(targetDir.exists()); File targetFile = new File(targetDir, "output.txt"); assertTrue(targetFile.exists()); FileReader fileReader = new FileReader(targetFile); StringBuilder content = new StringBuilder(); int readChars; char[] buffer = new char[50]; do { readChars = fileReader.read(buffer); if (readChars != -1) { content.append(buffer, 0, readChars); } } while (readChars != -1); fileReader.close(); assertEquals("content", content.toString()); }
From source file:com.npower.unicom.sync.FileSyncItemWriter.java
public void close() throws IOException { this.writer.flush(); this.writer.close(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); Writer out = new FileWriter(this.file); out.write("0001"); out.write('\t'); out.write("00000"); out.write('\t'); out.write(format.format(new Date())); out.write('\t'); out.write("ZB"); out.write('\t'); String from = (fromDate != null) ? format.format(fromDate) : "19700101000000"; String to = (toDate != null) ? format.format(toDate) : "19700101000000"; out.write(from);/*from w w w . j a v a2 s . c o m*/ out.write('\t'); out.write(to); out.write('\t'); out.write(Integer.toString(this.totalRecords)); out.write('\t'); out.write('\n'); // FileReader in = new FileReader(this.bodyFile); char[] buf = new char[512]; int len = in.read(buf); while (len > 0) { out.write(buf, 0, len); out.flush(); len = in.read(buf); } in.close(); out.close(); }
From source file:gov.nih.nci.cagrid.sdk4query.processor.PublicDataSDK4QueryProcessor.java
private void initializeCqlToHqlTranslator() throws InitializationException { // get the domain types information document String domainTypesFilename = getConfiguredParameters().getProperty(PROPERTY_DOMAIN_TYPES_INFO_FILENAME); DomainTypesInformation typesInfo = null; try {//from ww w . ja v a2s . c o m FileReader reader = new FileReader(domainTypesFilename); typesInfo = DomainTypesInformationUtil.deserializeDomainTypesInformation(reader); reader.close(); } catch (Exception ex) { throw new InitializationException("Error deserializing domain types information from " + domainTypesFilename + ": " + ex.getMessage(), ex); } // get the domain model DomainModel domainModel = null; try { domainModel = getDomainModel(); } catch (Exception ex) { throw new InitializationException("Error obtaining domain model: " + ex.getMessage(), ex); } RoleNameResolver resolver = new RoleNameResolver(domainModel); // create the query translator instance try { cqlTranslator = new PublicDataCQL2ParameterizedHQL(typesInfo, resolver, useCaseInsensitiveQueries()); } catch (Exception ex) { throw new InitializationException("Error instantiating CQL to HQL translator: " + ex.getMessage(), ex); } LOG.debug("CQL to HQL translator initialized"); }
From source file:com.sindicetech.siren.solr.SolrServerTestCase.java
protected void addJsonFileWoCommit(final String id, final String path) throws IOException, SolrServerException { final FileReader reader = new FileReader(path); try {/*from w w w.ja va 2 s . c o m*/ final String content = IOUtils.toString(reader); final SolrInputDocument document = new SolrInputDocument(); document.addField(ID_FIELD, id); document.addField(JSON_FIELD, content); getWrapper().add(document); } finally { reader.close(); } }
From source file:org.apache.commons.digester3.examples.plugins.pipeline.Pipeline.java
private void execute() throws IOException { FileReader inRaw = new FileReader(source); FileWriter out = new FileWriter(dest); BufferedReader in = new BufferedReader(inRaw); while (true) { String inStr = in.readLine(); if (inStr == null) break; String outStr = transformer.transform(inStr); out.write(outStr);/* w ww .j ava 2 s .c o m*/ out.write('\n'); } inRaw.close(); out.close(); System.out.println( "Contents of file " + source + " have been transformed, and" + " written to file " + dest + "."); }
From source file:model.settings.ReadSettings.java
/** * reads text from a configuration file; if is configuration file * is not valid, return null; otherwise return configuration line. * /*w w w. j ava2s . com*/ * @param _path from which _path is red. * @return the text read form file @ _path. * * @throws IOException is thrown in case of error. */ private static String readFromFile(final String _path) throws IOException { //create Reader FileReader fr = new FileReader(_path); BufferedReader br = new BufferedReader(fr); //create string for line String line = "start value not null."; do { //read line line = br.readLine(); } while (!line.equals(ID_PROGRAM_LOCATION) && line != null); //read line line = br.readLine(); //close reader br.close(); fr.close(); //return return value: in case of correct values return line; }