Search in sources :

Example 96 with FileReader

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();
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) IOException(java.io.IOException)

Example 97 with FileReader

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;
}
Also used : BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 98 with FileReader

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());
        }
    }
}
Also used : FileReader(java.io.FileReader) Properties(java.util.Properties) File(java.io.File) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashBiMap(com.google.common.collect.HashBiMap) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ModSortingException(net.minecraftforge.fml.common.toposort.ModSortingException)

Example 99 with FileReader

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;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) CircularArrayList(io.mycat.util.CircularArrayList) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 100 with FileReader

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;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

FileReader (java.io.FileReader)1602 BufferedReader (java.io.BufferedReader)1114 IOException (java.io.IOException)762 File (java.io.File)701 FileNotFoundException (java.io.FileNotFoundException)264 ArrayList (java.util.ArrayList)250 Test (org.junit.Test)154 FileWriter (java.io.FileWriter)121 HashMap (java.util.HashMap)103 Reader (java.io.Reader)86 BufferedWriter (java.io.BufferedWriter)78 Properties (java.util.Properties)57 InputStreamReader (java.io.InputStreamReader)54 Map (java.util.Map)54 List (java.util.List)51 Matcher (java.util.regex.Matcher)49 LineNumberReader (java.io.LineNumberReader)46 HashSet (java.util.HashSet)43 FileInputStream (java.io.FileInputStream)41 PrintWriter (java.io.PrintWriter)40