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

Unified Diff: sdk/lib/io/file_impl.dart

Issue 230583002: Merge r34868 to trunk. (Closed) Base URL: https://dart.googlecode.com/svn/trunk/dart
Patch Set: Created 6 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/file_impl.dart
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index 71e3ffefd6c0b7203efb08a0c32d0c19bea8a336..5846131978a4f4172c3446916a7d6a6634ada935 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -452,13 +452,16 @@ class _File extends FileSystemEntity implements File {
List<int> readAsBytesSync() {
var opened = openSync();
- var builder = new BytesBuilder();
- var data;
- while ((data = opened.readSync(_BLOCK_SIZE)).length > 0) {
- builder.add(data);
+ try {
+ var builder = new BytesBuilder();
+ var data;
+ while ((data = opened.readSync(_BLOCK_SIZE)).length > 0) {
+ builder.add(data);
+ }
+ return builder.takeBytes();
+ } finally {
+ opened.closeSync();
}
- opened.closeSync();
- return builder.takeBytes();
}
String _tryDecode(List<int> bytes, Encoding encoding) {
@@ -526,9 +529,12 @@ class _File extends FileSystemEntity implements File {
{FileMode mode: FileMode.WRITE,
bool flush: false}) {
RandomAccessFile opened = openSync(mode: mode);
- opened.writeFromSync(bytes, 0, bytes.length);
- if (flush) opened.flushSync();
- opened.closeSync();
+ try {
+ opened.writeFromSync(bytes, 0, bytes.length);
+ if (flush) opened.flushSync();
+ } finally {
+ opened.closeSync();
+ }
}
Future<File> writeAsString(String contents,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698