use of java.io.FileWriter in project XobotOS by xamarin.
the class DiskLruCache method open.
/**
* Opens the cache in {@code directory}, creating a cache if none exists
* there.
*
* @param directory a writable directory
* @param appVersion
* @param valueCount the number of values per cache entry. Must be positive.
* @param maxSize the maximum number of bytes this cache should use to store
* @throws IOException if reading or writing the cache directory fails
*/
public static DiskLruCache open(File directory, int appVersion, int valueCount, long maxSize) throws IOException {
if (maxSize <= 0) {
throw new IllegalArgumentException("maxSize <= 0");
}
if (valueCount <= 0) {
throw new IllegalArgumentException("valueCount <= 0");
}
// prefer to pick up where we left off
DiskLruCache cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
if (cache.journalFile.exists()) {
try {
cache.readJournal();
cache.processJournal();
cache.journalWriter = new BufferedWriter(new FileWriter(cache.journalFile, true));
return cache;
} catch (IOException journalIsCorrupt) {
System.logW("DiskLruCache " + directory + " is corrupt: " + journalIsCorrupt.getMessage() + ", removing");
cache.delete();
}
}
// create a new empty cache
directory.mkdirs();
cache = new DiskLruCache(directory, appVersion, valueCount, maxSize);
cache.rebuildJournal();
return cache;
}
use of java.io.FileWriter in project XobotOS by xamarin.
the class DiskLruCache method rebuildJournal.
/**
* Creates a new journal that omits redundant information. This replaces the
* current journal if it exists.
*/
private synchronized void rebuildJournal() throws IOException {
if (journalWriter != null) {
journalWriter.close();
}
Writer writer = new BufferedWriter(new FileWriter(journalFileTmp));
writer.write(MAGIC);
writer.write("\n");
writer.write(VERSION_1);
writer.write("\n");
writer.write(Integer.toString(appVersion));
writer.write("\n");
writer.write(Integer.toString(valueCount));
writer.write("\n");
writer.write("\n");
for (Entry entry : lruEntries.values()) {
if (entry.currentEditor != null) {
writer.write(DIRTY + ' ' + entry.key + '\n');
} else {
writer.write(CLEAN + ' ' + entry.key + entry.getLengths() + '\n');
}
}
writer.close();
journalFileTmp.renameTo(journalFile);
journalWriter = new BufferedWriter(new FileWriter(journalFile, true));
}
use of java.io.FileWriter in project XobotOS by xamarin.
the class NativeBuilder method printNativeType.
private static boolean printNativeType(NativeConfiguration config, Node unit, String fileName) {
final URI projectRoot = my(APIDefinition.class).getProjectRoot();
final String outputDir = my(ConfigFile.class).getSourceInfo().getOutputFolder();
final String outputPath = projectRoot.getPath() + File.separatorChar + outputDir + File.separatorChar + config.getOutputDir();
if (!new File(outputPath).exists())
new File(outputPath).mkdirs();
final String fullSourceName = outputPath + File.separatorChar + fileName;
FileWriter output;
try {
output = new FileWriter(fullSourceName);
} catch (IOException e) {
Sharpen.Log(e, "Cannot create native glue file '%s'", fullSourceName);
return false;
}
IndentedWriter writer = new IndentedWriter(output);
Printer printer = new Printer(writer);
unit.accept(printer);
try {
output.close();
} catch (IOException e) {
Sharpen.Log(e, "Cannot create native glue file '%s'", fullSourceName);
return false;
}
return true;
}
use of java.io.FileWriter in project XobotOS by xamarin.
the class XStreamUtils method write.
public static <T extends IConfigurationFile> void write(String fileName, T config) throws IOException {
FileWriter writer = new FileWriter(fileName);
XStream xstream = prepareXStream();
xstream.toXML(config, writer);
writer.close();
}
use of java.io.FileWriter in project LookLook by xinghongfei.
the class CacheUtil method put.
// =======================================
// ============ String数据 读写 ==============
// =======================================
/**
* 保存 String数据 到 缓存中
*
* @param key 保存的key
* @param value 保存的String数据
*/
public void put(String key, String value) {
File file = mCache.newFile(key);
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(file), 1024);
out.write(value);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
}
Aggregations