Search in sources :

Example 86 with FileWriter

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

Example 87 with FileWriter

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));
}
Also used : FileWriter(java.io.FileWriter) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) Writer(java.io.Writer) BufferedWriter(java.io.BufferedWriter)

Example 88 with FileWriter

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;
}
Also used : IndentedWriter(sharpen.core.io.IndentedWriter) APIDefinition(sharpen.xobotos.api.APIDefinition) FileWriter(java.io.FileWriter) IOException(java.io.IOException) CSharpPrinter(sharpen.core.csharp.CSharpPrinter) URI(java.net.URI) File(java.io.File) ConfigFile(sharpen.xobotos.config.ConfigFile)

Example 89 with FileWriter

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();
}
Also used : XStream(com.thoughtworks.xstream.XStream) FileWriter(java.io.FileWriter)

Example 90 with FileWriter

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);
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Aggregations

FileWriter (java.io.FileWriter)1994 File (java.io.File)1195 IOException (java.io.IOException)866 BufferedWriter (java.io.BufferedWriter)798 PrintWriter (java.io.PrintWriter)329 Test (org.junit.Test)243 Writer (java.io.Writer)181 FileReader (java.io.FileReader)148 BufferedReader (java.io.BufferedReader)128 ArrayList (java.util.ArrayList)121 FileNotFoundException (java.io.FileNotFoundException)78 Date (java.util.Date)68 FileOutputStream (java.io.FileOutputStream)65 Properties (java.util.Properties)65 HashMap (java.util.HashMap)61 FileInputStream (java.io.FileInputStream)54 StringWriter (java.io.StringWriter)51 Path (org.apache.hadoop.fs.Path)50 Map (java.util.Map)42 InputStreamReader (java.io.InputStreamReader)34