use of java.io.FileWriter in project platform_frameworks_base by android.
the class DropBoxTest method testAddEntriesInTheFuture.
public void testAddEntriesInTheFuture() throws Exception {
File dir = getEmptyDir("testAddEntriesInTheFuture");
long before = System.currentTimeMillis();
// Near future: should be allowed to persist
FileWriter w0 = new FileWriter(new File(dir, "DropBoxTest@" + (before + 5000) + ".txt"));
w0.write("FUTURE0");
w0.close();
// Far future: should be collapsed
FileWriter w1 = new FileWriter(new File(dir, "DropBoxTest@" + (before + 100000) + ".txt"));
w1.write("FUTURE1");
w1.close();
// Another far future item, this one gzipped
File f2 = new File(dir, "DropBoxTest@" + (before + 100001) + ".txt.gz");
GZIPOutputStream gz2 = new GZIPOutputStream(new FileOutputStream(f2));
gz2.write("FUTURE2".getBytes());
gz2.close();
// Tombstone in the far future
new FileOutputStream(new File(dir, "DropBoxTest@" + (before + 100002) + ".lost")).close();
DropBoxManagerService service = new DropBoxManagerService(getContext(), dir);
DropBoxManager dropbox = new DropBoxManager(getContext(), service.getServiceStub());
// Until a write, the timestamps are taken at face value
DropBoxManager.Entry e0 = dropbox.getNextEntry(null, before);
DropBoxManager.Entry e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
DropBoxManager.Entry e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
DropBoxManager.Entry e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
assertTrue(null == dropbox.getNextEntry(null, e3.getTimeMillis()));
assertEquals("FUTURE0", e0.getText(80));
assertEquals("FUTURE1", e1.getText(80));
assertEquals("FUTURE2", e2.getText(80));
assertEquals(null, e3.getText(80));
assertEquals(before + 5000, e0.getTimeMillis());
assertEquals(before + 100000, e1.getTimeMillis());
assertEquals(before + 100001, e2.getTimeMillis());
assertEquals(before + 100002, e3.getTimeMillis());
e0.close();
e1.close();
e2.close();
e3.close();
// Write something to force a collapse
dropbox.addText("NotDropBoxTest", "FUTURE");
e0 = dropbox.getNextEntry(null, before);
e1 = dropbox.getNextEntry(null, e0.getTimeMillis());
e2 = dropbox.getNextEntry(null, e1.getTimeMillis());
e3 = dropbox.getNextEntry(null, e2.getTimeMillis());
assertTrue(null == dropbox.getNextEntry("DropBoxTest", e3.getTimeMillis()));
assertEquals("FUTURE0", e0.getText(80));
assertEquals("FUTURE1", e1.getText(80));
assertEquals("FUTURE2", e2.getText(80));
assertEquals(null, e3.getText(80));
assertEquals(before + 5000, e0.getTimeMillis());
assertEquals(before + 5001, e1.getTimeMillis());
assertEquals(before + 5002, e2.getTimeMillis());
assertEquals(before + 5003, e3.getTimeMillis());
e0.close();
e1.close();
e2.close();
e3.close();
}
use of java.io.FileWriter in project frodo by android10.
the class DataPresenter method executeDiskIOTaskOnUiThread.
public void executeDiskIOTaskOnUiThread() {
try {
File file = File.createTempFile("test", ".txt");
FileWriter writer = new FileWriter(file);
writer.write("This is Fernando Cejas testing something");
writer.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
use of java.io.FileWriter in project jstorm by alibaba.
the class SandBoxMaker method generatePolicyFile.
public String generatePolicyFile(Map<String, String> replaceMap) throws IOException {
// dynamic generate policy file, no static file
String tmpPolicy = StormConfig.supervisorTmpDir(conf) + File.separator + UUID.randomUUID().toString();
InputStream inputStream = SandBoxMaker.class.getClassLoader().getResourceAsStream(SANBOX_TEMPLATE_NAME);
PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(tmpPolicy)));
BufferedReader reader = null;
InputStreamReader inputReader = null;
try {
inputReader = new InputStreamReader(inputStream);
reader = new BufferedReader(new LineNumberReader(inputReader));
String line = null;
while ((line = reader.readLine()) != null) {
String replaced = replaceLine(line, replaceMap);
writer.println(replaced);
}
return tmpPolicy;
} catch (Exception e) {
LOG.error("Failed to generate policy file\n", e);
throw new IOException(e);
} finally {
if (inputStream != null) {
inputStream.close();
}
if (writer != null) {
writer.close();
}
if (reader != null) {
reader.close();
}
if (inputReader != null) {
inputReader.close();
}
}
}
use of java.io.FileWriter in project gradle by gradle.
the class BrowserEvaluate method doEvaluate.
@TaskAction
void doEvaluate() {
HttpFileServer fileServer = new SimpleHttpFileServerFactory().start(getContent(), 0);
try {
Writer resultWriter = new FileWriter(getResult());
getEvaluator().evaluate(fileServer.getResourceUrl(getResource()), resultWriter);
resultWriter.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
} finally {
fileServer.stop();
}
setDidWork(true);
}
use of java.io.FileWriter in project groovy-core by groovy.
the class SourceUnit method saveAsXML.
private void saveAsXML(String name, ModuleNode ast) {
XStream xstream = new XStream();
try {
xstream.toXML(ast, new FileWriter(name + ".xml"));
System.out.println("Written AST to " + name + ".xml");
} catch (Exception e) {
System.out.println("Couldn't write to " + name + ".xml");
e.printStackTrace();
}
}
Aggregations