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

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

Issue 14018007: Rename RandomAccessFile.readList and RandomAccessFile.writeList to RandomAccessFile.readInto and Ra… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 7 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 | « sdk/lib/io/file.dart ('k') | tests/standalone/io/dart_std_io_pipe_test.dart » ('j') | 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 75ecab6a4bd12f7b3c20b0f1617918f573b81dea..23ce711f06898ec9b7189956871da28aa232708a 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -168,7 +168,7 @@ class _FileStreamConsumer extends StreamConsumer<List<int>> {
_subscription = stream.listen(
(d) {
_subscription.pause();
- openedFile.writeList(d, 0, d.length)
+ openedFile.writeFrom(d, 0, d.length)
.then((_) => _subscription.resume())
.catchError((e) {
openedFile.close();
@@ -563,7 +563,7 @@ class _File extends _FileBase implements File {
void writeAsBytesSync(List<int> bytes, {FileMode mode: FileMode.WRITE}) {
RandomAccessFile opened = openSync(mode: mode);
- opened.writeListSync(bytes, 0, bytes.length);
+ opened.writeFromSync(bytes, 0, bytes.length);
opened.closeSync();
}
@@ -711,57 +711,59 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
return result;
}
- Future<int> readList(List<int> buffer, int offset, int bytes) {
+ Future<int> readInto(List<int> buffer, [int start, int end]) {
_ensureFileService();
- Completer<int> completer = new Completer<int>();
- if (buffer is !List || offset is !int || bytes is !int) {
- // Complete asynchronously so the user has a chance to setup
- // handlers without getting exceptions when registering the
- // then handler.
- Timer.run(() {
- completer.completeError(new FileIOException(
- "Invalid arguments to readList for file '$_path'"));
- });
- return completer.future;
+ if (buffer is !List ||
+ (start != null && start is !int) ||
+ (end != null && end is !int)) {
+ return new Future.immediateError(new FileIOException(
+ "Invalid arguments to readInto for file '$_path'"));
};
+ Completer<int> completer = new Completer<int>();
if (closed) return _completeWithClosedException(completer);
List request = new List(3);
+ if (start == null) start = 0;
+ if (end == null) end = buffer.length;
request[0] = _READ_LIST_REQUEST;
request[1] = _id;
- request[2] = bytes;
+ request[2] = end - start;
return _fileService.call(request).then((response) {
if (_isErrorResponse(response)) {
throw _exceptionFromResponse(response,
- "readList failed for file '$_path'");
+ "readInto failed for file '$_path'");
}
var read = response[1];
var data = response[2];
- buffer.setRange(offset, offset + read, data);
+ buffer.setRange(start, start + read, data);
return read;
});
}
- static void _checkReadWriteListArguments(int length, int offset, int bytes) {
- if (offset < 0) throw new RangeError.value(offset);
- if (bytes < 0) throw new RangeError.value(bytes);
- if ((offset + bytes) > length) {
- throw new RangeError.value(offset + bytes);
+ static void _checkReadWriteListArguments(int length, int start, int end) {
+ if (start < 0) throw new RangeError.value(start);
+ if (end < start) throw new RangeError.value(end);
+ if (end > length) {
+ throw new RangeError.value(end);
}
}
- external static _readList(int id, List<int> buffer, int offset, int bytes);
+ external static _readInto(int id, List<int> buffer, int start, int end);
- int readListSync(List<int> buffer, int offset, int bytes) {
+ int readIntoSync(List<int> buffer, [int start, int end]) {
_checkNotClosed();
- if (buffer is !List || offset is !int || bytes is !int) {
+ if (buffer is !List ||
+ (start != null && start is !int) ||
+ (end != null && end is !int)) {
throw new FileIOException(
- "Invalid arguments to readList for file '$_path'");
+ "Invalid arguments to readInto for file '$_path'");
}
- if (bytes == 0) return 0;
- _checkReadWriteListArguments(buffer.length, offset, bytes);
- var result = _readList(_id, buffer, offset, bytes);
+ if (start == null) start = 0;
+ if (end == null) end = buffer.length;
+ if (end == start) return 0;
+ _checkReadWriteListArguments(buffer.length, start, end);
+ var result = _readInto(_id, buffer, start, end);
if (result is OSError) {
- throw new FileIOException("readList failed for file '$_path'",
+ throw new FileIOException("readInto failed for file '$_path'",
result);
}
return result;
@@ -810,67 +812,63 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
return result;
}
- Future<RandomAccessFile> writeList(List<int> buffer, int offset, int bytes) {
+ Future<RandomAccessFile> writeFrom(List<int> buffer, [int start, int end]) {
_ensureFileService();
- Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
if ((buffer is !List && buffer is !ByteData) ||
- offset is !int ||
- bytes is !int) {
- // Complete asynchronously so the user has a chance to setup
- // handlers without getting exceptions when registering the
- // then handler.
- Timer.run(() {
- completer.completeError(new FileIOException(
- "Invalid arguments to writeList for file '$_path'"));
- });
- return completer.future;
+ (start != null && start is !int) ||
+ (end != null && end is !int)) {
+ return new Future.immediateError(new FileIOException(
+ "Invalid arguments to writeFrom for file '$_path'"));
}
+ Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
+
if (closed) return _completeWithClosedException(completer);
- _BufferAndOffset result;
+ _BufferAndStart result;
try {
- result = _ensureFastAndSerializableBuffer(buffer, offset, bytes);
+ result = _ensureFastAndSerializableBuffer(buffer, start, end);
} catch (e) {
- // Complete asynchronously so the user has a chance to setup
- // handlers without getting exceptions when registering the
- // then handler.
- Timer.run(() => completer.completeError(e));
- return completer.future;
+ return new Future.immediateError(e);
}
List request = new List(5);
request[0] = _WRITE_LIST_REQUEST;
request[1] = _id;
request[2] = result.buffer;
- request[3] = result.offset;
- request[4] = bytes;
+ request[3] = result.start;
+ request[4] = end - (start - result.start);
return _fileService.call(request).then((response) {
if (_isErrorResponse(response)) {
throw _exceptionFromResponse(response,
- "writeList failed for file '$_path'");
+ "writeFrom failed for file '$_path'");
}
return this;
});
}
- external static _writeList(int id, List<int> buffer, int offset, int bytes);
+ external static _writeFrom(int id, List<int> buffer, int start, int end);
- int writeListSync(List<int> buffer, int offset, int bytes) {
+ void writeFromSync(List<int> buffer, [int start, int end]) {
_checkNotClosed();
- if (buffer is !List || offset is !int || bytes is !int) {
+ if (buffer is !List ||
+ (start != null && start is !int) ||
+ (end != null && end is !int)) {
throw new FileIOException(
- "Invalid arguments to writeList for file '$_path'");
+ "Invalid arguments to writeFrom for file '$_path'");
}
- if (bytes == 0) return 0;
- _checkReadWriteListArguments(buffer.length, offset, bytes);
- _BufferAndOffset bufferAndOffset =
- _ensureFastAndSerializableBuffer(buffer, offset, bytes);
- var result =
- _writeList(_id, bufferAndOffset.buffer, bufferAndOffset.offset, bytes);
+ if (start == null) start = 0;
+ if (end == null) end = buffer.length;
+ if (end == start) return;
+ _checkReadWriteListArguments(buffer.length, start, end);
+ _BufferAndStart bufferAndStart =
+ _ensureFastAndSerializableBuffer(buffer, start, end);
+ var result = _writeFrom(_id,
+ bufferAndStart.buffer,
+ bufferAndStart.start,
+ end - (start - bufferAndStart.start));
if (result is OSError) {
- throw new FileIOException("writeList failed for file '$_path'", result);
+ throw new FileIOException("writeFrom failed for file '$_path'", result);
}
- return result;
}
Future<RandomAccessFile> writeString(String string,
@@ -884,16 +882,16 @@ class _RandomAccessFile extends _FileBase implements RandomAccessFile {
return completer.future;
}
var data = _encodeString(string, encoding);
- return writeList(data, 0, data.length);
+ return writeFrom(data, 0, data.length);
}
- int writeStringSync(String string, {Encoding encoding: Encoding.UTF_8}) {
+ void writeStringSync(String string, {Encoding encoding: Encoding.UTF_8}) {
if (encoding is! Encoding) {
throw new FileIOException(
"Invalid encoding in writeStringSync: $encoding");
}
var data = _encodeString(string, encoding);
- return writeListSync(data, 0, data.length);
+ writeFromSync(data, 0, data.length);
}
Future<int> position() {
« no previous file with comments | « sdk/lib/io/file.dart ('k') | tests/standalone/io/dart_std_io_pipe_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698