Rename File.readAsText to File.readAsString. There is no Text type in Dart
and the methods return Strings.
R=sgjesse@google.com
BUG=
Review URL: https://codereview.chromium.org//11412033
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15011 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pkg/intl/lib/src/file_data_reader.dart b/pkg/intl/lib/src/file_data_reader.dart
index e5d3e51..4448081 100644
--- a/pkg/intl/lib/src/file_data_reader.dart
+++ b/pkg/intl/lib/src/file_data_reader.dart
@@ -22,6 +22,6 @@
/// Read the locale data found for [locale] on our [path].
Future read(String locale) {
var file = new File('$path$locale.json');
- return file.readAsText();
+ return file.readAsString();
}
}
diff --git a/sdk/lib/io/file.dart b/sdk/lib/io/file.dart
index 43ff45b..97fc18c 100644
--- a/sdk/lib/io/file.dart
+++ b/sdk/lib/io/file.dart
@@ -184,19 +184,19 @@
List<int> readAsBytesSync();
/**
- * Read the entire file contents as text using the given
+ * Read the entire file contents as a string using the given
* [encoding].
*
* Returns a [:Future<String>:] that completes with the string once
* the file contents has been read.
*/
- Future<String> readAsText([Encoding encoding = Encoding.UTF_8]);
+ Future<String> readAsString([Encoding encoding = Encoding.UTF_8]);
/**
- * Synchronously read the entire file contents as text using the
+ * Synchronously read the entire file contents as a string using the
* given [encoding].
*/
- String readAsTextSync([Encoding encoding = Encoding.UTF_8]);
+ String readAsStringSync([Encoding encoding = Encoding.UTF_8]);
/**
* Read the entire file contents as lines of text using the give
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index 63c161b..27bace9 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -609,7 +609,7 @@
return result;
}
- Future<String> readAsText([Encoding encoding = Encoding.UTF_8]) {
+ Future<String> readAsString([Encoding encoding = Encoding.UTF_8]) {
_ensureFileService();
return readAsBytes().transform((bytes) {
if (bytes.length == 0) return "";
@@ -619,7 +619,7 @@
});
}
- String readAsTextSync([Encoding encoding = Encoding.UTF_8]) {
+ String readAsStringSync([Encoding encoding = Encoding.UTF_8]) {
var decoder = _StringDecoders.decoder(encoding);
List<int> bytes = readAsBytesSync();
if (bytes.length == 0) return "";
diff --git a/tests/standalone/io/file_error_test.dart b/tests/standalone/io/file_error_test.dart
index 4a6a309..3c8d084 100644
--- a/tests/standalone/io/file_error_test.dart
+++ b/tests/standalone/io/file_error_test.dart
@@ -273,12 +273,12 @@
var file = new File("${temp.path}/nonExistentFile4");
// Non-existing file should throw exception.
- Expect.throws(() => file.readAsTextSync(),
+ Expect.throws(() => file.readAsStringSync(),
(e) => checkOpenNonExistentFileException(e));
- var readAsTextFuture = file.readAsText(Encoding.ASCII);
- readAsTextFuture.then((data) => Expect.fail("Unreachable code"));
- readAsTextFuture.handleException((e) {
+ var readAsStringFuture = file.readAsString(Encoding.ASCII);
+ readAsStringFuture.then((data) => Expect.fail("Unreachable code"));
+ readAsStringFuture.handleException((e) {
checkOpenNonExistentFileException(e);
p.toSendPort().send(null);
return true;
diff --git a/tests/standalone/io/file_fuzz_test.dart b/tests/standalone/io/file_fuzz_test.dart
index faed2ef..abb6fc0 100644
--- a/tests/standalone/io/file_fuzz_test.dart
+++ b/tests/standalone/io/file_fuzz_test.dart
@@ -23,12 +23,12 @@
doItSync(f.fullPathSync);
doItSync(() => f.openInputStream().onError = (e) => null);
doItSync(f.readAsBytesSync);
- doItSync(f.readAsTextSync);
+ doItSync(f.readAsStringSync);
doItSync(f.readAsLinesSync);
typeMapping.forEach((k2, v2) {
doItSync(() => f.openSync(v2));
doItSync(() => f.openOutputStream(v2).onError = (e) => null);
- doItSync(() => f.readAsTextSync(v2));
+ doItSync(() => f.readAsStringSync(v2));
doItSync(() => f.readAsLinesSync(v2));
});
});
@@ -50,10 +50,10 @@
futures.add(doItAsync(f.fullPath));
futures.add(doItAsync(f.readAsBytes));
futures.add(doItAsync(f.readAsLines));
- futures.add(doItAsync(f.readAsText));
+ futures.add(doItAsync(f.readAsString));
typeMapping.forEach((k2, v2) {
futures.add(doItAsync(() => f.open(v2)));
- futures.add(doItAsync(() => f.readAsText(v2)));
+ futures.add(doItAsync(() => f.readAsString(v2)));
futures.add(doItAsync(() => f.readAsLines(v2)));
});
});
diff --git a/tests/standalone/io/file_non_ascii_sync_test.dart b/tests/standalone/io/file_non_ascii_sync_test.dart
index 1708652..3a10b93 100644
--- a/tests/standalone/io/file_non_ascii_sync_test.dart
+++ b/tests/standalone/io/file_non_ascii_sync_test.dart
@@ -21,5 +21,5 @@
Expect.isTrue(f.fullPathSync().endsWith('${precomposed}.dat') ||
f.fullPathSync().endsWith('${decomposed}.dat'));
// The contents of the file is precomposed utf8.
- Expect.equals(precomposed, f.readAsTextSync());
+ Expect.equals(precomposed, f.readAsStringSync());
}
diff --git a/tests/standalone/io/file_non_ascii_test.dart b/tests/standalone/io/file_non_ascii_test.dart
index 437528f..d082080 100644
--- a/tests/standalone/io/file_non_ascii_test.dart
+++ b/tests/standalone/io/file_non_ascii_test.dart
@@ -25,7 +25,7 @@
f.fullPath().then((p) {
Expect.isTrue(p.endsWith('${precomposed}.dat') ||
p.endsWith('${decomposed}.dat'));
- f.readAsText().then((contents) {
+ f.readAsString().then((contents) {
Expect.equals(precomposed, contents);
port.close();
});
diff --git a/tests/standalone/io/file_test.dart b/tests/standalone/io/file_test.dart
index 2f210f4..2cfd32d 100644
--- a/tests/standalone/io/file_test.dart
+++ b/tests/standalone/io/file_test.dart
@@ -1037,24 +1037,24 @@
});
var name = getFilename("tests/vm/data/fixed_length_file");
var f = new File(name);
- f.readAsText(Encoding.UTF_8).then((text) {
+ f.readAsString(Encoding.UTF_8).then((text) {
Expect.isTrue(text.endsWith("42 bytes."));
Expect.equals(42, text.length);
var name = getDataFilename("tests/standalone/io/read_as_text.dat");
var f = new File(name);
- f.readAsText(Encoding.UTF_8).then((text) {
+ f.readAsString(Encoding.UTF_8).then((text) {
Expect.equals(6, text.length);
var expected = [955, 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.charCodes);
- f.readAsText(Encoding.ISO_8859_1).then((text) {
+ f.readAsString(Encoding.ISO_8859_1).then((text) {
Expect.equals(7, text.length);
var expected = [206, 187, 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.charCodes);
- var readAsTextFuture = f.readAsText(Encoding.ASCII);
- readAsTextFuture.then((text) {
+ var readAsStringFuture = f.readAsString(Encoding.ASCII);
+ readAsStringFuture.then((text) {
Expect.fail("Non-ascii char should cause error");
});
- readAsTextFuture.handleException((e) {
+ readAsStringFuture.handleException((e) {
port.toSendPort().send(1);
return true;
});
@@ -1071,7 +1071,7 @@
});
var name = getFilename("tests/vm/data/empty_file");
var f = new File(name);
- f.readAsText(Encoding.UTF_8).then((text) {
+ f.readAsString(Encoding.UTF_8).then((text) {
port.toSendPort().send(text.length);
return true;
});
@@ -1079,16 +1079,16 @@
static void testReadAsTextSync() {
var name = getFilename("tests/vm/data/fixed_length_file");
- var text = new File(name).readAsTextSync();
+ var text = new File(name).readAsStringSync();
Expect.isTrue(text.endsWith("42 bytes."));
Expect.equals(42, text.length);
name = getDataFilename("tests/standalone/io/read_as_text.dat");
- text = new File(name).readAsTextSync();
+ text = new File(name).readAsStringSync();
Expect.equals(6, text.length);
var expected = [955, 120, 46, 32, 120, 10];
Expect.listEquals(expected, text.charCodes);
- Expect.throws(() { new File(name).readAsTextSync(Encoding.ASCII); });
- text = new File(name).readAsTextSync(Encoding.ISO_8859_1);
+ Expect.throws(() { new File(name).readAsStringSync(Encoding.ASCII); });
+ text = new File(name).readAsStringSync(Encoding.ISO_8859_1);
expected = [206, 187, 120, 46, 32, 120, 10];
Expect.equals(7, text.length);
Expect.listEquals(expected, text.charCodes);
@@ -1096,7 +1096,7 @@
static void testReadAsTextSyncEmptyFile() {
var name = getFilename("tests/vm/data/empty_file");
- var text = new File(name).readAsTextSync();
+ var text = new File(name).readAsStringSync();
Expect.equals(0, text.length);
}
@@ -1137,14 +1137,14 @@
});
var f = new File('.');
Expect.throws(f.readAsBytesSync, (e) => e is FileIOException);
- Expect.throws(f.readAsTextSync, (e) => e is FileIOException);
+ Expect.throws(f.readAsStringSync, (e) => e is FileIOException);
Expect.throws(f.readAsLinesSync, (e) => e is FileIOException);
var readAsBytesFuture = f.readAsBytes();
readAsBytesFuture.then((bytes) => Expect.fail("no bytes expected"));
readAsBytesFuture.handleException((e) {
- var readAsTextFuture = f.readAsText(Encoding.UTF_8);
- readAsTextFuture.then((text) => Expect.fail("no text expected"));
- readAsTextFuture.handleException((e) {
+ var readAsStringFuture = f.readAsString(Encoding.UTF_8);
+ readAsStringFuture.then((text) => Expect.fail("no text expected"));
+ readAsStringFuture.handleException((e) {
var readAsLinesFuture = f.readAsLines(Encoding.UTF_8);
readAsLinesFuture.then((lines) => Expect.fail("no lines expected"));
readAsLinesFuture.handleException((e) {
@@ -1232,7 +1232,7 @@
openedFile.length().then((l) {
Expect.equals(4, l);
openedFile.close().then((_) {
- file.readAsText().then((readBack) {
+ file.readAsString().then((readBack) {
Expect.stringEquals(readBack, '$string$string');
file.delete().then((_) {
file.exists().then((e) {
@@ -1265,7 +1265,7 @@
openedFile.writeStringSync(string);
Expect.equals(4, openedFile.lengthSync());
openedFile.closeSync();
- var readBack = file.readAsTextSync();
+ var readBack = file.readAsStringSync();
Expect.stringEquals(readBack, '$string$string');
file.deleteSync();
Expect.isFalse(file.existsSync());
diff --git "a/tests/standalone/io/\303\246\303\270\303\245.dart" "b/tests/standalone/io/\303\246\303\270\303\245.dart"
index abf731c..d03e720 100644
--- "a/tests/standalone/io/\303\246\303\270\303\245.dart"
+++ "b/tests/standalone/io/\303\246\303\270\303\245.dart"
@@ -5,5 +5,5 @@
import 'dart:io';
main() {
- Expect.equals('æøå', new File('æøå.dat').readAsTextSync());
+ Expect.equals('æøå', new File('æøå.dat').readAsStringSync());
}
diff --git a/utils/apidoc/apidoc.dart b/utils/apidoc/apidoc.dart
index 7a9e5cb..742e519 100644
--- a/utils/apidoc/apidoc.dart
+++ b/utils/apidoc/apidoc.dart
@@ -85,7 +85,7 @@
print('Parsing MDN data...');
final mdnFile = new File.fromPath(doc.scriptDir.append('mdn/database.json'));
- final mdn = JSON.parse(mdnFile.readAsTextSync());
+ final mdn = JSON.parse(mdnFile.readAsStringSync());
print('Cross-referencing dart:html...');
HtmlDiff.initialize(libPath);
diff --git a/utils/apidoc/mdn/postProcess.dart b/utils/apidoc/mdn/postProcess.dart
index 95e3558..d70cf74 100644
--- a/utils/apidoc/mdn/postProcess.dart
+++ b/utils/apidoc/mdn/postProcess.dart
@@ -13,7 +13,7 @@
void main() {
// Database of code documentation.
Map<String, List> database = JSON.parse(
- new File('output/database.json').readAsTextSync());
+ new File('output/database.json').readAsStringSync());
final filteredDb = {};
final obsolete = [];
for (String type in database.keys) {
diff --git a/utils/apidoc/mdn/prettyPrint.dart b/utils/apidoc/mdn/prettyPrint.dart
index e95d23b..d0a413c 100644
--- a/utils/apidoc/mdn/prettyPrint.dart
+++ b/utils/apidoc/mdn/prettyPrint.dart
@@ -52,7 +52,7 @@
void main() {
// Database of code documentation.
final Map<String, Map> database = JSON.parse(
- new File('output/database.filtered.json').readAsTextSync());
+ new File('output/database.filtered.json').readAsStringSync());
// Types we have documentation for.
matchedTypes = new Set<String>();
diff --git a/utils/apidoc/mdn/util.dart b/utils/apidoc/mdn/util.dart
index 3b5c72d..69a4c6c 100644
--- a/utils/apidoc/mdn/util.dart
+++ b/utils/apidoc/mdn/util.dart
@@ -9,7 +9,7 @@
if (_allProps == null) {
// Database of expected property names for each type in WebKit.
_allProps = JSON.parse(
- new File('data/dartIdl.json').readAsTextSync());
+ new File('data/dartIdl.json').readAsStringSync());
}
return _allProps;
}
diff --git a/utils/pub/io.dart b/utils/pub/io.dart
index 3296bb8..793c7263 100644
--- a/utils/pub/io.dart
+++ b/utils/pub/io.dart
@@ -118,7 +118,7 @@
* a [File].
*/
Future<String> readTextFile(file) {
- return new File(_getPath(file)).readAsText(Encoding.UTF_8);
+ return new File(_getPath(file)).readAsString(Encoding.UTF_8);
}
/**