use of java.io.FileReader in project RxCache by VictorAlbertos.
the class BuiltInEncryptorTest method getFileContent.
private String getFileContent(File file) {
StringBuilder builder = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file.getAbsoluteFile()));
String aux;
while ((aux = reader.readLine()) != null) {
builder.append(aux);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return builder.toString();
}
use of java.io.FileReader in project Fairphone by Kwamecorp.
the class GappsInstallerHelper method getGappsUrlFromConfigFile.
private String[] getGappsUrlFromConfigFile(String filePath) {
String[] result = new String[2];
File configFile = new File(filePath);
try {
BufferedReader br = new BufferedReader(new FileReader(configFile));
result[0] = br.readLine();
result[1] = br.readLine();
br.close();
} catch (FileNotFoundException e) {
Log.e(TAG, "Configuration file not find", e);
result = null;
} catch (IOException e) {
Log.e(TAG, "Configuration file could not be read", e);
result = null;
}
return result;
}
use of java.io.FileReader in project MinecraftForge by MinecraftForge.
the class Loader method disableRequestedMods.
private void disableRequestedMods() {
String forcedModList = System.getProperty("fml.modStates", "");
FMLLog.finer("Received a system property request \'%s\'", forcedModList);
Map<String, String> sysPropertyStateList = Splitter.on(CharMatcher.anyOf(";:")).omitEmptyStrings().trimResults().withKeyValueSeparator("=").split(forcedModList);
FMLLog.finer("System property request managing the state of %d mods", sysPropertyStateList.size());
Map<String, String> modStates = Maps.newHashMap();
forcedModFile = new File(canonicalConfigDir, "fmlModState.properties");
Properties forcedModListProperties = new Properties();
if (forcedModFile.exists() && forcedModFile.isFile()) {
FMLLog.finer("Found a mod state file %s", forcedModFile.getName());
try {
forcedModListProperties.load(new FileReader(forcedModFile));
FMLLog.finer("Loaded states for %d mods from file", forcedModListProperties.size());
} catch (Exception e) {
FMLLog.log(Level.INFO, e, "An error occurred reading the fmlModState.properties file");
}
}
modStates.putAll(Maps.fromProperties(forcedModListProperties));
modStates.putAll(sysPropertyStateList);
FMLLog.fine("After merging, found state information for %d mods", modStates.size());
Map<String, Boolean> isEnabled = Maps.transformValues(modStates, new Function<String, Boolean>() {
@Override
public Boolean apply(String input) {
return Boolean.parseBoolean(input);
}
});
for (Map.Entry<String, Boolean> entry : isEnabled.entrySet()) {
if (namedMods.containsKey(entry.getKey())) {
FMLLog.info("Setting mod %s to enabled state %b", entry.getKey(), entry.getValue());
namedMods.get(entry.getKey()).setEnabledState(entry.getValue());
}
}
}
use of java.io.FileReader in project Mycat-Server by MyCATApache.
the class PackageBufINf method showLogSum.
private static PackageBufINf showLogSum(ManagerConnection c, ByteBuffer buffer, byte packetId) {
PackageBufINf bufINf = new PackageBufINf();
File[] logFiles = new File(SystemConfig.getHomePath(), "logs").listFiles();
String fileNames = "";
for (File f : logFiles) {
if (f.isFile()) {
fileNames += " " + f.getName();
}
}
File file = getLogFile(DEFAULT_LOGFILE);
BufferedReader br = null;
int totalLines = 0;
CircularArrayList<String> queue = new CircularArrayList<String>(50);
try {
br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {
totalLines++;
if (queue.size() == queue.capacity()) {
queue.remove(0);
}
queue.add(line);
}
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode("files in log dir:" + totalLines + fileNames, c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode("Total lines " + totalLines + " ,tail " + queue.size() + " line is following:", c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
int size = queue.size() - 1;
for (int i = size; i >= 0; i--) {
String data = queue.get(i);
row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(data, c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
bufINf.buffer = buffer;
bufINf.packetId = packetId;
return bufINf;
} catch (Exception e) {
LOGGER.error("showLogSumError", e);
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(e.toString(), c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
bufINf.buffer = buffer;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
LOGGER.error("showLogSumError", e);
}
}
}
bufINf.packetId = packetId;
return bufINf;
}
use of java.io.FileReader in project Mycat-Server by MyCATApache.
the class ConfFileHandler method showConfigFile.
private static PackageBufINf showConfigFile(ManagerConnection c, ByteBuffer buffer, byte packetId, String fileName) {
File file = new File(SystemConfig.getHomePath(), "conf" + File.separator + fileName);
BufferedReader br = null;
PackageBufINf bufINf = new PackageBufINf();
try {
br = new BufferedReader(new FileReader(file));
String line = null;
while ((line = br.readLine()) != null) {
if (line.isEmpty()) {
continue;
}
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(line, c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
bufINf.buffer = buffer;
bufINf.packetId = packetId;
return bufINf;
} catch (Exception e) {
LOGGER.error("showConfigFileError", e);
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(e.toString(), c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
bufINf.buffer = buffer;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
LOGGER.error("showConfigFileError", e);
}
}
}
bufINf.packetId = packetId;
return bufINf;
}
Aggregations