use of java.io.FileWriter in project iosched by google.
the class DiskLruCacheTest method openWithTruncatedLineDiscardsThatLine.
@Test
public void openWithTruncatedLineDiscardsThatLine() throws Exception {
cache.close();
writeFile(getCleanFile("k1", 0), "A");
writeFile(getCleanFile("k1", 1), "B");
Writer writer = new FileWriter(journalFile);
// no trailing newline
writer.write(MAGIC + "\n" + VERSION_1 + "\n100\n2\n\nCLEAN k1 1 1");
writer.close();
cache = DiskLruCache.open(cacheDir, appVersion, 2, Integer.MAX_VALUE);
assertThat(cache.get("k1")).isNull();
}
use of java.io.FileWriter in project iosched by google.
the class DiskLruCacheTest method createJournalWithHeader.
private void createJournalWithHeader(String magic, String version, String appVersion, String valueCount, String blank, String... bodyLines) throws Exception {
Writer writer = new FileWriter(journalFile);
writer.write(magic + "\n");
writer.write(version + "\n");
writer.write(appVersion + "\n");
writer.write(valueCount + "\n");
writer.write(blank + "\n");
for (String line : bodyLines) {
writer.write(line);
writer.write('\n');
}
writer.close();
}
use of java.io.FileWriter in project j2objc by google.
the class EnvironmentCheck method main.
/**
* Command line runnability: checks for [-out outFilename] arg.
* <p>Command line entrypoint; Sets output and calls
* {@link #checkEnvironment(PrintWriter)}.</p>
* @param args command line args
*/
public static void main(String[] args) {
// Default to System.out, autoflushing
PrintWriter sendOutputTo = new PrintWriter(System.out, true);
// Read our simplistic input args, if supplied
for (int i = 0; i < args.length; i++) {
if ("-out".equalsIgnoreCase(args[i])) {
i++;
if (i < args.length) {
try {
sendOutputTo = new PrintWriter(new FileWriter(args[i], true));
} catch (Exception e) {
System.err.println("# WARNING: -out " + args[i] + " threw " + e.toString());
}
} else {
System.err.println("# WARNING: -out argument should have a filename, output sent to console");
}
}
}
EnvironmentCheck app = new EnvironmentCheck();
app.checkEnvironment(sendOutputTo);
}
use of java.io.FileWriter in project j2objc by google.
the class OldFileWriterTest method test_ConstructorLjava_io_FileZ_IOException.
public void test_ConstructorLjava_io_FileZ_IOException() {
File dir = new File(System.getProperty("java.io.tmpdir"));
try {
fw = new FileWriter(dir, true);
fail("Test 1: IOException expected.");
} catch (IOException e) {
// Expected.
}
}
use of java.io.FileWriter in project j2objc by google.
the class OldFileWriterTest method test_handleEarlyEOFChar_2.
public void test_handleEarlyEOFChar_2() throws IOException {
int capacity = 65536;
byte[] bytes = new byte[capacity];
byte[] bs = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
for (int i = 0; i < bytes.length; i++) {
bytes[i] = bs[i / 8192];
}
String inputStr = new String(bytes);
int len = inputStr.length();
File f = File.createTempFile("FileWriterBugTest ", null);
FileWriter writer = new FileWriter(f);
writer.write(inputStr);
writer.close();
long flen = f.length();
FileReader reader = new FileReader(f);
char[] outChars = new char[capacity];
int outCount = reader.read(outChars);
String outStr = new String(outChars, 0, outCount);
f.deleteOnExit();
assertEquals(len, flen);
assertEquals(inputStr, outStr);
}
Aggregations