Search in sources :

Example 46 with FileReader

use of java.io.FileReader in project databus by linkedin.

the class FileMaxSCNHandler method loadInitialValue.

/**
   * Reads scn value from SCN File name according to configuration. If SCN file does not
   * exist, it creates the SCN file w/the initial value specified in the configuration. An
   * exception is thrown if we the SCN file exists but we fail to read the SCN value from
   * it.
   *
   * @throws IOException
   *           if we fail to open or read from the SCN file
   * @throws RuntimeException
   *           if the SCN value cannot be read or parsed from the file
   */
protected void loadInitialValue() throws IOException, DatabusException {
    Long initVal = null;
    LOG.info("Trying to read initial SCN from file: " + _scnFileName);
    File file = new File(_scnFileName);
    if (file.exists()) {
        FileReader fileReader = new FileReader(file);
        try {
            BufferedReader reader = new BufferedReader(fileReader);
            String scnLine = reader.readLine();
            if (null != scnLine) {
                try {
                    String scnString = scnLine.substring(0, scnLine.indexOf(SCN_SEPARATOR));
                    _scn.set(Long.parseLong(scnString));
                    LOG.info("Starting from MAX SCN:" + scnString);
                } catch (Exception e) {
                    LOG.error("Could not read initial SCN value. Value missing or not in expected format; scnLine = " + scnLine, e);
                    throw new DatabusException("Failed to load initial SCN value. Value misisng or not in expected format.", e);
                }
            } else {
                LOG.warn("SCN file empty; defaulting to initial value from configuration:" + _staticConfig.getInitVal());
                _scn.set(_staticConfig.getInitVal());
            }
            reader.close();
        } finally {
            fileReader.close();
        }
    } else {
        LOG.info("Initial max SCN does not exist. Defaulting to initial value from configuration: " + _staticConfig.getInitVal());
        _scn.set(_staticConfig.getInitVal());
        writeScnToFile();
    }
}
Also used : DatabusException(com.linkedin.databus2.core.DatabusException) AtomicLong(java.util.concurrent.atomic.AtomicLong) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) DatabusException(com.linkedin.databus2.core.DatabusException) InvalidConfigException(com.linkedin.databus.core.util.InvalidConfigException) IOException(java.io.IOException)

Example 47 with FileReader

use of java.io.FileReader in project libgdx by libgdx.

the class TexturePacker method main.

public static void main(String[] args) throws Exception {
    Settings settings = null;
    String input = null, output = null, packFileName = "pack.atlas";
    switch(args.length) {
        case 4:
            settings = new Json().fromJson(Settings.class, new FileReader(args[3]));
        case 3:
            packFileName = args[2];
        case 2:
            output = args[1];
        case 1:
            input = args[0];
            break;
        default:
            System.out.println("Usage: inputDir [outputDir] [packFileName] [settingsFileName]");
            System.exit(0);
    }
    if (output == null) {
        File inputFile = new File(input);
        output = new File(inputFile.getParentFile(), inputFile.getName() + "-packed").getAbsolutePath();
    }
    if (settings == null)
        settings = new Settings();
    process(settings, input, output, packFileName);
}
Also used : FileReader(java.io.FileReader) Json(com.badlogic.gdx.utils.Json) File(java.io.File)

Example 48 with FileReader

use of java.io.FileReader in project zoj by licheng.

the class DatabaseHelper method resetAllTables.

/**
	 * Clears all tables
	 * @param flag;
	 * @throws Exception to JUnit
	 */
public static void resetAllTables(boolean flag) throws Exception {
    if (!allTablesCleared || flag) {
        for (int i = 0; i < tables.length; ++i) {
            clearTable(tables[i]);
        }
        BufferedReader reader = new BufferedReader(new FileReader(INITIAL_INSERTS));
        for (; ; ) {
            String cmd = reader.readLine();
            if (cmd == null) {
                break;
            }
            cmd = cmd.trim();
            if (cmd.length() > 0) {
                executeUpdate(cmd);
                if (cmd.startsWith("INSERT INTO")) {
                    String table = cmd.substring(12, cmd.indexOf('('));
                    List list = (List) initialInserts.get(table);
                    if (list == null) {
                        list = new ArrayList();
                        initialInserts.put(table, list);
                    }
                    list.add(cmd);
                }
            }
        }
        allTablesCleared = true;
    }
}
Also used : BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 49 with FileReader

use of java.io.FileReader in project Truck-Factor by aserg-ufmg.

the class LinguistExtractor method execute.

public List<NewFileInfo> execute() {
    List<NewFileInfo> linguistFiles = new ArrayList<NewFileInfo>();
    try {
        Map<String, List<String>> languageMap = new HashMap<String, List<String>>();
        //System.out.format("%s (%s): Extracting file language information...\n",repositoryName, new Date());
        BufferedReader br = new BufferedReader(new FileReader(repositoryPath + fileName));
        String sCurrentLine;
        String[] values;
        while ((sCurrentLine = br.readLine()) != null) {
            values = sCurrentLine.split(";");
            String language = values[0];
            if (language.contains("\'"))
                language = language.replace("'", "''");
            String path = values[1];
            linguistFiles.add(new NewFileInfo(repositoryName, path, language));
        }
        br.close();
    } catch (FileNotFoundException e) {
        LOGGER.warn(fileName + " not found. Executing without Linguist filter.");
        linguistFiles = null;
    } catch (Exception e) {
        LOGGER.error("Erro no projeto " + repositoryName, e);
        linguistFiles = null;
    }
    return linguistFiles;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NewFileInfo(aserg.gtf.model.NewFileInfo)

Example 50 with FileReader

use of java.io.FileReader in project Truck-Factor by aserg-ufmg.

the class LinguistExtractor method extractAndPersist.

public void extractAndPersist() throws IOException {
    NewFileInfoDAO fiDAO = new NewFileInfoDAO();
    fiDAO.setAllAsNotLinguist();
    List<NewFileInfo> files = execute();
    try {
        Map<String, List<String>> languageMap = new HashMap<String, List<String>>();
        System.out.format("%s (%s): Extracting file language information...", repositoryName, new Date());
        BufferedReader br = new BufferedReader(new FileReader(repositoryPath + fileName));
        String sCurrentLine;
        String[] values;
        while ((sCurrentLine = br.readLine()) != null) {
            values = sCurrentLine.split(";");
            String language = values[0];
            if (language.contains("\'"))
                language = language.replace("'", "''");
            String path = values[1];
            List<String> paths;
            if (languageMap.containsKey(language))
                paths = languageMap.get(language);
            else {
                paths = new ArrayList<String>();
                languageMap.put(language, paths);
            }
            paths.add(path);
            files.add(new NewFileInfo(repositoryName, path, language));
        }
        br.close();
        for (Entry<String, List<String>> entry : languageMap.entrySet()) {
            fiDAO.updateLanguageFileInfo(repositoryName, entry.getKey(), entry.getValue());
        }
    } catch (Exception e) {
        System.err.println("Erro no projeto " + repositoryName);
        System.err.println(e.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) NewFileInfoDAO(aserg.gtf.dao.NewFileInfoDAO) Date(java.util.Date) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) NewFileInfo(aserg.gtf.model.NewFileInfo)

Aggregations

FileReader (java.io.FileReader)1873 BufferedReader (java.io.BufferedReader)1289 IOException (java.io.IOException)893 File (java.io.File)811 FileNotFoundException (java.io.FileNotFoundException)304 ArrayList (java.util.ArrayList)274 Test (org.junit.Test)197 FileWriter (java.io.FileWriter)148 HashMap (java.util.HashMap)116 Reader (java.io.Reader)99 BufferedWriter (java.io.BufferedWriter)98 Properties (java.util.Properties)66 InputStreamReader (java.io.InputStreamReader)64 LineNumberReader (java.io.LineNumberReader)61 Matcher (java.util.regex.Matcher)61 Map (java.util.Map)59 List (java.util.List)56 PrintWriter (java.io.PrintWriter)51 StringTokenizer (java.util.StringTokenizer)51 HashSet (java.util.HashSet)50