Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1167)

Unified Diff: runtime/bin/file_impl.dart

Issue 9969202: Add method flush to output stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | runtime/bin/output_stream.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index 66fb6bdfa11844e12399d43bff46378ca9cc4260..26928519349a88bcd216539958624396e366273a 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -91,9 +91,16 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
}
+class _PendingOperation {
+ const _PendingOperation();
+ static final _PendingOperation CLOSE = const _PendingOperation();
+ static final _PendingOperation FLUSH = const _PendingOperation();
+}
+
+
class _FileOutputStream extends _BaseOutputStream implements OutputStream {
_FileOutputStream(String name, FileMode mode) {
- _pendingOperations = new List<List<int>>();
+ _pendingOperations = new List();
var f = new File(name);
f.open(mode, (openedFile) {
_file = openedFile;
@@ -150,9 +157,17 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream {
return write(copy);
}
+ void flush() {
+ if (_file == null) {
+ _pendingOperations.add(_PendingOperation.FLUSH);
+ } else {
+ _file.flush();
Mads Ager (google) 2012/04/17 11:56:44 Isn't _file a RandomAccessFile? Doesn't flush take
Søren Gjesse 2012/04/17 13:14:19 It does - not sure why no tests failed. Turend ou
+ }
+ }
+
void close() {
if (_file == null) {
- _pendingOperations.add(null);
+ _pendingOperations.add(_PendingOperation.CLOSE);
} else if (!_streamMarkedClosed) {
_file.close(() {
if (_onClosed != null) _onClosed();
@@ -175,7 +190,16 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream {
void _processPendingOperations() {
_pendingOperations.forEach((buffer) {
- (buffer != null) ? write(buffer) : close();
+ if (buffer is _PendingOperation) {
+ if (buffer === _PendingOperation.CLOSE) {
+ close();
+ } else {
+ assert(buffer === _PendingOperation.FLUSH);
+ flush();
+ }
+ } else {
+ write(buffer);
+ }
});
_pendingOperations = null;
}
@@ -196,7 +220,7 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream {
// List of pending writes that were issued before the underlying
// file was successfully opened.
- List<List<int>> _pendingOperations;
+ List _pendingOperations;
Function _onNoPendingWrites;
Function _onClosed;
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | runtime/bin/output_stream.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698