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