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

Side by Side Diff: runtime/bin/file_impl.dart

Issue 11000025: Revert hiding of VM-only coreimpl list implementation types. While I (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/common.dart ('k') | runtime/bin/process_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class _FileInputStream extends _BaseDataInputStream implements InputStream { 5 class _FileInputStream extends _BaseDataInputStream implements InputStream {
6 _FileInputStream(String name) 6 _FileInputStream(String name)
7 : _data = const [], 7 : _data = const [],
8 _position = 0, 8 _position = 0,
9 _filePosition = 0 { 9 _filePosition = 0 {
10 var file = new File(name); 10 var file = new File(name);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 328
329 static const SUCCESS_RESPONSE = 0; 329 static const SUCCESS_RESPONSE = 0;
330 static const ILLEGAL_ARGUMENT_RESPONSE = 1; 330 static const ILLEGAL_ARGUMENT_RESPONSE = 1;
331 static const OSERROR_RESPONSE = 2; 331 static const OSERROR_RESPONSE = 2;
332 static const FILE_CLOSED_RESPONSE = 3; 332 static const FILE_CLOSED_RESPONSE = 3;
333 333
334 static const ERROR_RESPONSE_ERROR_TYPE = 0; 334 static const ERROR_RESPONSE_ERROR_TYPE = 0;
335 static const OSERROR_RESPONSE_ERROR_CODE = 1; 335 static const OSERROR_RESPONSE_ERROR_CODE = 1;
336 static const OSERROR_RESPONSE_MESSAGE = 2; 336 static const OSERROR_RESPONSE_MESSAGE = 2;
337 337
338 static List ensureFastAndSerializableBuffer(
339 List buffer, int offset, int bytes) {
340 // When using the Dart C API to access raw data, using a ByteArray is
341 // currently much faster. This function will make a copy of the
342 // supplied List to a ByteArray if it isn't already.
343 List outBuffer;
344 int outOffset = offset;
345 if (buffer is Uint8List || buffer is ObjectArray) {
346 outBuffer = buffer;
347 } else {
348 outBuffer = new Uint8List(bytes);
349 outOffset = 0;
350 int j = offset;
351 for (int i = 0; i < bytes; i++) {
352 int value = buffer[j];
353 if (value is! int) {
354 throw new FileIOException(
355 "List element is not an integer at index $j");
356 }
357 outBuffer[i] = value;
358 j++;
359 }
360 }
361 return [outBuffer, outOffset];
362 }
363
338 static exists(String name) native "File_Exists"; 364 static exists(String name) native "File_Exists";
339 static open(String name, int mode) native "File_Open"; 365 static open(String name, int mode) native "File_Open";
340 static create(String name) native "File_Create"; 366 static create(String name) native "File_Create";
341 static delete(String name) native "File_Delete"; 367 static delete(String name) native "File_Delete";
342 static fullPath(String name) native "File_FullPath"; 368 static fullPath(String name) native "File_FullPath";
343 static directory(String name) native "File_Directory"; 369 static directory(String name) native "File_Directory";
344 static lengthFromName(String name) native "File_LengthFromName"; 370 static lengthFromName(String name) native "File_LengthFromName";
345 static lastModified(String name) native "File_LastModified"; 371 static lastModified(String name) native "File_LastModified";
346 static int close(int id) native "File_Close"; 372 static int close(int id) native "File_Close";
347 static readByte(int id) native "File_ReadByte"; 373 static readByte(int id) native "File_ReadByte";
348 static readList(int id, List<int> buffer, int offset, int bytes) 374 static readList(int id, List<int> buffer, int offset, int bytes)
349 native "File_ReadList"; 375 native "File_ReadList";
350 static writeByte(int id, int value) native "File_WriteByte"; 376 static writeByte(int id, int value) native "File_WriteByte";
351 static writeList(int id, List<int> buffer, int offset, int bytes) { 377 static writeList(int id, List<int> buffer, int offset, int bytes) {
352 List result = _ensureFastAndSerializableBuffer(buffer, offset, bytes); 378 List result =
379 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes);
353 List outBuffer = result[0]; 380 List outBuffer = result[0];
354 int outOffset = result[1]; 381 int outOffset = result[1];
355 return writeListNative(id, outBuffer, outOffset, bytes); 382 return writeListNative(id, outBuffer, outOffset, bytes);
356 } 383 }
357 static writeListNative(int id, List<int> buffer, int offset, int bytes) 384 static writeListNative(int id, List<int> buffer, int offset, int bytes)
358 native "File_WriteList"; 385 native "File_WriteList";
359 static writeString(int id, String string) native "File_WriteString"; 386 static writeString(int id, String string) native "File_WriteString";
360 static position(int id) native "File_Position"; 387 static position(int id) native "File_Position";
361 static setPosition(int id, int position) native "File_SetPosition"; 388 static setPosition(int id, int position) native "File_SetPosition";
362 static truncate(int id, int length) native "File_Truncate"; 389 static truncate(int id, int length) native "File_Truncate";
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 new Timer(0, (t) { 939 new Timer(0, (t) {
913 completer.completeException(new FileIOException( 940 completer.completeException(new FileIOException(
914 "Invalid arguments to writeList for file '$_name'")); 941 "Invalid arguments to writeList for file '$_name'"));
915 }); 942 });
916 return completer.future; 943 return completer.future;
917 } 944 }
918 if (closed) return _completeWithClosedException(completer); 945 if (closed) return _completeWithClosedException(completer);
919 946
920 List result; 947 List result;
921 try { 948 try {
922 result = _ensureFastAndSerializableBuffer(buffer, offset, bytes); 949 result =
950 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes);
923 } catch (e) { 951 } catch (e) {
924 // Complete asynchronously so the user has a chance to setup 952 // Complete asynchronously so the user has a chance to setup
925 // handlers without getting exceptions when registering the 953 // handlers without getting exceptions when registering the
926 // then handler. 954 // then handler.
927 new Timer(0, (t) => completer.completeException(e)); 955 new Timer(0, (t) => completer.completeException(e));
928 return completer.future; 956 return completer.future;
929 } 957 }
930 List outBuffer = result[0]; 958 List outBuffer = result[0];
931 int outOffset = result[1]; 959 int outOffset = result[1];
932 960
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 new FileIOException("File closed '$_name'")); 1165 new FileIOException("File closed '$_name'"));
1138 }); 1166 });
1139 return completer.future; 1167 return completer.future;
1140 } 1168 }
1141 1169
1142 final String _name; 1170 final String _name;
1143 int _id; 1171 int _id;
1144 1172
1145 SendPort _fileService; 1173 SendPort _fileService;
1146 } 1174 }
OLDNEW
« no previous file with comments | « runtime/bin/common.dart ('k') | runtime/bin/process_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698