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();
}
}
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);
}
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;
}
}
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;
}
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());
}
}
Aggregations