Example usage for java.io FileReader close

List of usage examples for java.io FileReader close

Introduction

In this page you can find the example usage for java.io FileReader close.

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:org.apache.axis2.corba.receivers.CorbaUtil.java

public static org.omg.CORBA.Object resolveObject(AxisService service, org.omg.CORBA_2_3.ORB orb)
        throws CorbaInvocationException {
    org.omg.CORBA.Object obj;/*from w w w.  j  a  v a2 s.  c  o  m*/
    try {
        Parameter namingServiceUrl = service.getParameter(NAMING_SERVICE_URL);
        Parameter objectName = service.getParameter(OBJECT_NAME);
        Parameter iorFilePath = service.getParameter(IOR_FILE_PATH);
        Parameter iorString = service.getParameter(IOR_STRING);

        if (namingServiceUrl != null && objectName != null) {
            obj = orb.string_to_object(((String) namingServiceUrl.getValue()).trim());
            NamingContextExt nc = NamingContextExtHelper.narrow(obj);
            obj = nc.resolve(nc.to_name(((String) objectName.getValue()).trim()));
        } else if (iorFilePath != null) {
            FileReader fileReader = new FileReader(((String) iorFilePath.getValue()).trim());
            char[] buf = new char[1000];
            fileReader.read(buf);
            obj = orb.string_to_object((new String(buf)).trim());
            fileReader.close();
        } else if (iorString != null) {
            obj = orb.string_to_object(((String) iorString.getValue()).trim());
        } else {
            throw new CorbaInvocationException("cannot resolve object");
        }

    } catch (NotFound notFound) {
        throw new CorbaInvocationException("cannot resolve object", notFound);
    } catch (CannotProceed cannotProceed) {
        throw new CorbaInvocationException("cannot resolve object", cannotProceed);
    } catch (InvalidName invalidName) {
        throw new CorbaInvocationException("cannot resolve object", invalidName);
    } catch (IOException e) {
        throw new CorbaInvocationException("cannot resolve object", e);
    }
    return obj;
}

From source file:opennlp.tools.parse_thicket.opinion_processor.StopList.java

private static void loadStopListFile(File f) throws FileNotFoundException {

    FileReader fileReader = new FileReader(f);
    BufferedReader in = new BufferedReader(fileReader);

    String str = new String();
    boolean fLine = true;
    HashSet<String> t = new HashSet<String>();
    String listName = "";

    try {//from ww  w  .j  av  a  2  s .com
        while ((str = in.readLine()) != null) {
            if (fLine && str.length() > 0) {
                fLine = false;
                listName = str;
            } else {
                t.add(str);
            }
        }
    } catch (IOException ioe) {

    } finally {
        try {
            if (in != null) {
                in.close();
            }
            if (fileReader != null) {
                fileReader.close();
            }
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }

    if (listName.length() > 0) {
        HashSet<String> l = m_stopHash.get(listName);
        if (l != null) {
            synchronized (l) {
                m_stopHash.put(listName, t);
            }
        } else {
            m_stopHash.put(listName, t);
        }
    }
}

From source file:Main.java

Main() {
    gui.setBorder(new EmptyBorder(2, 3, 2, 3));

    String userDirLocation = System.getProperty("user.dir");
    File userDir = new File(userDirLocation);
    // default to user directory
    fileChooser = new JFileChooser(userDir);

    Action open = new AbstractAction("Open") {
        @Override/* w ww .ja  v a2  s.c o  m*/
        public void actionPerformed(ActionEvent e) {
            int result = fileChooser.showOpenDialog(gui);
            if (result == JFileChooser.APPROVE_OPTION) {
                try {
                    File f = fileChooser.getSelectedFile();
                    FileReader fr = new FileReader(f);
                    output.read(fr, f);
                    fr.close();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    };

    Action save = new AbstractAction("Save") {
        @Override
        public void actionPerformed(ActionEvent e) {
            int result = fileChooser.showSaveDialog(gui);
            System.out.println("Not supported yet.");
        }
    };

    JToolBar tb = new JToolBar();
    gui.add(tb, BorderLayout.PAGE_START);
    tb.add(open);
    tb.add(save);

    gui.add(new JScrollPane(output));
}

From source file:de.dekarlab.moneybuilder.model.parser.JsonBookLoader.java

/**
 * Load book from JSON file./*from   ww  w  .  j a v a 2s.c o m*/
 * 
 * @return
 */
public static Book loadBook(File file) throws Exception {
    Book book = new Book();
    if (!file.exists()) {
        book.setName("Book");
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(new Date());
        cal.set(Calendar.DAY_OF_MONTH, 1);
        // create period
        Period newPeriod = new Period(cal.getTime());
        newPeriod.setId(Formatter.formatDateId(cal.getTime()));
        book.getPeriodList().add(newPeriod);
        book.setCurrPeriod(newPeriod);
        book.getAssetList().setName(App.getGuiProp("default.assets"));
        book.getLiabilityList().setName(App.getGuiProp("default.liability"));
        book.getExpenseList().setName(App.getGuiProp("default.expenses"));
        book.getIncomeList().setName(App.getGuiProp("default.income"));
        return book;
    }
    FileReader fr = null;
    try {
        fr = new FileReader(file);
        JSONTokener jsonTokener = new JSONTokener(fr);
        JSONObject root = new JSONObject(jsonTokener);
        JSONObject jsonBook = root.getJSONObject("book");
        book.setName(jsonBook.getString("name"));
        book.setCurrPeriodId(jsonBook.getString("currPeriodId"));
        parseAccounts(jsonBook.getJSONObject("assets"), book.getAssetList());
        parseAccounts(jsonBook.getJSONObject("liability"), book.getLiabilityList());
        parseAccounts(jsonBook.getJSONObject("income"), book.getIncomeList());
        parseAccounts(jsonBook.getJSONObject("expenses"), book.getExpenseList());
        parsePeriods(jsonBook.getJSONArray("periodList"), book.getPeriodList(), book);
    } finally {
        if (fr != null) {
            fr.close();
        }
    }
    return book;
}

From source file:com.grarak.kerneladiutor.utils.Utils.java

public static String readFile(String file, RootUtils.SU su) {
    if (su != null)
        return new RootFile(file, su).readFile();

    StringBuilder s = null;/*ww  w  .  ja  v a2s .co m*/
    FileReader fileReader = null;
    BufferedReader buf = null;
    try {
        fileReader = new FileReader(file);
        buf = new BufferedReader(fileReader);

        String line;
        s = new StringBuilder();
        while ((line = buf.readLine()) != null)
            s.append(line).append("\n");
    } catch (FileNotFoundException ignored) {
        Log.e(TAG, "File does not exist " + file);
    } catch (IOException e) {
        Log.e(TAG, "Failed to read " + file);
    } finally {
        try {
            if (fileReader != null)
                fileReader.close();
            if (buf != null)
                buf.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return s == null ? null : s.toString().trim();
}

From source file:org.kepler.Kepler.java

/**
 * read the osextension.txt file and return a hashtable of the properties
 * //from   w w w  .  jav a 2 s .  c o m
 * NOTE this method is duplicated in CompileModules.java. Change both if you
 * change one.
 */
private static Hashtable<String, String> readOSExtensionFile(File f) throws Exception {
    // String newline = System.getProperty("line.separator");
    Hashtable<String, String> properties = new Hashtable<String, String>();
    FileReader fr = new FileReader(f);
    StringBuffer sb = new StringBuffer();
    char[] c = new char[1024];
    int numread = fr.read(c, 0, 1024);
    while (numread != -1) {
        sb.append(c, 0, numread);
        numread = fr.read(c, 0, 1024);
    }
    fr.close();

    String propertiesStr = sb.toString();
    // String[] props = propertiesStr.split(newline);
    String[] props = propertiesStr.split(";");
    for (int i = 0; i < props.length; i++) {
        String token1 = props[i];
        StringTokenizer st2 = new StringTokenizer(token1, ",");
        String key = st2.nextToken();
        String val = st2.nextToken();
        properties.put(key, val);
    }

    return properties;
}

From source file:com.flipkart.polyguice.config.YamlConfiguration.java

public YamlConfiguration(String path) throws IOException {
    FileReader reader = new FileReader(path);
    load(reader);//from   w  ww .  ja  va 2 s  .co  m
    reader.close();
}

From source file:com.flipkart.polyguice.config.YamlConfiguration.java

public YamlConfiguration(File file) throws IOException {
    FileReader reader = new FileReader(file);
    load(reader);/*from   w w  w. j a  va 2  s . c o  m*/
    reader.close();
}

From source file:org.jenkinsci.plugins.vssj.VssChangeLogParser.java

List<VssJournalEntry> parseFile(File changelogFile) throws IOException, SAXException {
    List<VssJournalEntry> changeList = new ArrayList<VssJournalEntry>();
    Digester digester = new Digester2();
    digester.push(changeList);// w  ww. jav a  2 s .c  o  m

    digester.addObjectCreate("*/change", VssJournalEntry.class);
    digester.addBeanPropertySetter("*/change/action");
    digester.addBeanPropertySetter("*/change/comment");
    digester.addBeanPropertySetter("*/change/user");
    digester.addBeanPropertySetter("*/change/filename");
    digester.addBeanPropertySetter("*/change/version");
    digester.addBeanPropertySetter("*/change/date", "datetimeString");
    digester.addSetNext("*/change", "add");

    // Do the actual parsing
    FileReader reader = new FileReader(changelogFile);
    digester.parse(reader);
    reader.close();
    return changeList;
}

From source file:com.flipkart.polyguice.config.JsonConfiguration.java

public JsonConfiguration(String path) throws IOException {
    FileReader reader = new FileReader(path);
    load(reader);/*from w ww  .  ja v  a  2 s  .  c om*/
    reader.close();
}