Search in sources :

Example 66 with FileReader

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

the class FilestoreManager method start.

@Override
public IManager start() {
    // Try to load any existing metadata
    File dir = getStorageFolder();
    dir.mkdirs();
    File metadata = new File(dir, METAFILE);
    if (metadata.exists()) {
        Collection<FilestoreModel> items = null;
        Gson gson = gson();
        try (FileReader file = new FileReader(metadata)) {
            items = gson.fromJson(file, METAFILE_TYPE);
            file.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        for (Iterator<FilestoreModel> itr = items.iterator(); itr.hasNext(); ) {
            FilestoreModel model = itr.next();
            fileCache.put(model.oid, model);
        }
        logger.info("Loaded {} items from filestore metadata file", fileCache.size());
    } else {
        logger.info("No filestore metadata file found");
    }
    return this;
}
Also used : FilestoreModel(com.gitblit.models.FilestoreModel) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 67 with FileReader

use of java.io.FileReader in project buck by facebook.

the class Main method readPathsFromFile.

private static void readPathsFromFile(String fileName, Collection<String> paths) throws IOException {
    BufferedReader bfr = null;
    try {
        FileReader fr = new FileReader(fileName);
        bfr = new BufferedReader(fr);
        String line;
        while (null != (line = bfr.readLine())) {
            paths.add(fixPath(line));
        }
    } finally {
        if (bfr != null) {
            bfr.close();
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) CstString(com.android.dx.rop.cst.CstString)

Example 68 with FileReader

use of java.io.FileReader in project jooc-legacy by fasterthanlime.

the class FileUtils method read.

/**
	 * Read a file contents and return it as a string
	 * @param file
	 * @return
	 * @throws IOException
	 */
public static String read(File file) throws IOException {
    StringBuilder builder = new StringBuilder((int) file.length());
    FileReader reader = new FileReader(file);
    int n;
    char[] cbuf = new char[4096];
    while ((n = reader.read(cbuf)) != -1) {
        builder.append(cbuf, 0, n);
    }
    reader.close();
    return builder.toString();
}
Also used : FileReader(java.io.FileReader)

Example 69 with FileReader

use of java.io.FileReader in project meclipse by flaper87.

the class MeclipsePlugin method loadSavedServers.

private MongoInstance[] loadSavedServers() {
    CsvReader reader = null;
    try {
        IPath libPath = MeclipsePlugin.getDefault().getStateLocation();
        libPath = libPath.append("servers.cfg");
        File file = libPath.toFile();
        if (!file.exists())
            return new MongoInstance[0];
        reader = new CsvReader(new BufferedReader(new FileReader(file)));
        java.util.List<MongoInstance> savedServersList = new ArrayList<MongoInstance>();
        while (reader.readRecord()) {
            MongoInstance server = new MongoInstance(reader.get(0));
            server.setHost(reader.get(1));
            try {
                server.setPort(Integer.valueOf(reader.get(2)));
            } catch (NumberFormatException e) {
                System.out.println(e);
            }
            savedServersList.add(server);
        }
        return savedServersList.toArray(new MongoInstance[savedServersList.size()]);
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
    return new MongoInstance[0];
}
Also used : CsvReader(com.csvreader.CsvReader) IPath(org.eclipse.core.runtime.IPath) MongoInstance(org.mongodb.meclipse.preferences.MongoInstance) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 70 with FileReader

use of java.io.FileReader in project gexf4j by francesco-ficarola.

the class GexfImplFileUtf8Test method testStaticGexfGraph.

/**
     * Test of getGraph method, of class GexfImpl.
     */
@Test
public void testStaticGexfGraph() throws IOException, SAXException {
    System.out.println("getGraph");
    StaxGraphWriter graphWriter = new StaxGraphWriter();
    StringWriter stringWriter = new StringWriter();
    graphWriter.writeToStream(gexf, new FileWriter("target/testStaticUtf.gexf"), "UTF-8");
    graphWriter.writeToStream(gexf, stringWriter, "UTF-8");
    String found = IOUtils.toString(new FileReader("target/testStaticUtf.gexf"));
    String start = stringWriter.toString();
    Diff myDiff = new Diff(found, start);
    //        myDiff.overrideElementQualifier(new ElementNameAndTextQualifier());
    assertTrue("XML similar " + myDiff.toString(), myDiff.similar());
}
Also used : StringWriter(java.io.StringWriter) Diff(org.custommonkey.xmlunit.Diff) FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) StaxGraphWriter(it.uniroma1.dis.wsngroup.gexf4j.core.impl.StaxGraphWriter) Test(org.junit.Test)

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