use of okio.BufferedSink in project okhttp by square.
the class DiskLruCache method newJournalWriter.
private BufferedSink newJournalWriter() throws FileNotFoundException {
Sink fileSink = fileSystem.appendingSink(journalFile);
Sink faultHidingSink = new FaultHidingSink(fileSink) {
@Override
protected void onException(IOException e) {
assert (Thread.holdsLock(DiskLruCache.this));
hasJournalErrors = true;
}
};
return Okio.buffer(faultHidingSink);
}
use of okio.BufferedSink in project okhttp by square.
the class DiskLruCache method rebuildJournal.
/**
* Creates a new journal that omits redundant information. This replaces the current journal if it
* exists.
*/
synchronized void rebuildJournal() throws IOException {
if (journalWriter != null) {
journalWriter.close();
}
BufferedSink writer = Okio.buffer(fileSystem.sink(journalFileTmp));
try {
writer.writeUtf8(MAGIC).writeByte('\n');
writer.writeUtf8(VERSION_1).writeByte('\n');
writer.writeDecimalLong(appVersion).writeByte('\n');
writer.writeDecimalLong(valueCount).writeByte('\n');
writer.writeByte('\n');
for (Entry entry : lruEntries.values()) {
if (entry.currentEditor != null) {
writer.writeUtf8(DIRTY).writeByte(' ');
writer.writeUtf8(entry.key);
writer.writeByte('\n');
} else {
writer.writeUtf8(CLEAN).writeByte(' ');
writer.writeUtf8(entry.key);
entry.writeLengths(writer);
writer.writeByte('\n');
}
}
} finally {
writer.close();
}
if (fileSystem.exists(journalFile)) {
fileSystem.rename(journalFile, journalFileBackup);
}
fileSystem.rename(journalFileTmp, journalFile);
fileSystem.delete(journalFileBackup);
journalWriter = newJournalWriter();
hasJournalErrors = false;
mostRecentRebuildFailed = false;
}
use of okio.BufferedSink in project wire by square.
the class ServiceGeneratorTest method schema.
private Schema schema(Map<String, String> fileToProto) throws IOException {
SchemaLoader schemaLoader = new SchemaLoader();
schemaLoader.addSource(temporaryFolder.getRoot());
for (Map.Entry<String, String> entry : fileToProto.entrySet()) {
File file = new File(temporaryFolder.getRoot(), entry.getKey());
file.getParentFile().mkdirs();
try (BufferedSink out = Okio.buffer(Okio.sink(file))) {
out.writeUtf8(entry.getValue());
}
schemaLoader.addProto(entry.getKey());
}
return schemaLoader.load();
}
use of okio.BufferedSink in project wire by square.
the class ProtoAdapter method encode.
/** Encode {@code value} and write it to {@code stream}. */
public final void encode(OutputStream stream, E value) throws IOException {
checkNotNull(value, "value == null");
checkNotNull(stream, "stream == null");
BufferedSink buffer = Okio.buffer(Okio.sink(stream));
encode(buffer, value);
buffer.emit();
}
use of okio.BufferedSink in project u2020 by JakeWharton.
the class SocketActivityHierarchyServer method writeValue.
private static boolean writeValue(Socket client, String value) {
boolean result;
BufferedSink out = null;
try {
out = Okio.buffer(Okio.sink(client));
out.writeUtf8(value);
out.writeByte('\n');
out.flush();
result = true;
} catch (Exception e) {
result = false;
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
result = false;
}
}
}
return result;
}
Aggregations