OLD | NEW |
(Empty) | |
| 1 library java.io; |
| 2 |
| 3 import "dart:io"; |
| 4 import 'java_core.dart' show JavaIOException, CharSequence; |
| 5 import 'package:path/path.dart' as pathos; |
| 6 |
| 7 class JavaSystemIO { |
| 8 static Map<String, String> _properties = new Map(); |
| 9 static String getProperty(String name) { |
| 10 { |
| 11 String value = _properties[name]; |
| 12 if (value != null) { |
| 13 return value; |
| 14 } |
| 15 } |
| 16 if (name == 'os.name') { |
| 17 return Platform.operatingSystem; |
| 18 } |
| 19 if (name == 'line.separator') { |
| 20 if (Platform.isWindows) { |
| 21 return '\r\n'; |
| 22 } |
| 23 return '\n'; |
| 24 } |
| 25 if (name == 'com.google.dart.sdk') { |
| 26 String exec = Platform.executable; |
| 27 if (exec.length != 0) { |
| 28 String sdkPath; |
| 29 // may be "xcodebuild/ReleaseIA32/dart" with "sdk" sibling |
| 30 { |
| 31 var outDir = pathos.dirname(pathos.dirname(exec)); |
| 32 sdkPath = pathos.join(pathos.dirname(outDir), "sdk"); |
| 33 if (new Directory(sdkPath).existsSync()) { |
| 34 _properties[name] = sdkPath; |
| 35 return sdkPath; |
| 36 } |
| 37 } |
| 38 // probably be "dart-sdk/bin/dart" |
| 39 sdkPath = pathos.dirname(pathos.dirname(exec)); |
| 40 _properties[name] = sdkPath; |
| 41 return sdkPath; |
| 42 } |
| 43 } |
| 44 return null; |
| 45 } |
| 46 static String setProperty(String name, String value) { |
| 47 String oldValue = _properties[name]; |
| 48 _properties[name] = value; |
| 49 return oldValue; |
| 50 } |
| 51 static String getenv(String name) => Platform.environment[name]; |
| 52 } |
| 53 |
| 54 class JavaFile { |
| 55 static final String separator = Platform.pathSeparator; |
| 56 static final int separatorChar = Platform.pathSeparator.codeUnitAt(0); |
| 57 String _path; |
| 58 JavaFile(String path) { |
| 59 _path = path; |
| 60 } |
| 61 JavaFile.relative(JavaFile base, String child) { |
| 62 if (child.isEmpty) { |
| 63 this._path = base._path; |
| 64 } else { |
| 65 this._path = pathos.join(base._path, child); |
| 66 } |
| 67 } |
| 68 JavaFile.fromUri(Uri uri) : this(pathos.fromUri(uri)); |
| 69 String toString() => _path.toString(); |
| 70 int get hashCode => _path.hashCode; |
| 71 bool operator ==(other) { |
| 72 return other is JavaFile && other._path == _path; |
| 73 } |
| 74 String getPath() => _path; |
| 75 String getName() => pathos.basename(_path); |
| 76 String getParent() { |
| 77 var result = pathos.dirname(_path); |
| 78 // "." or "/" or "C:\" |
| 79 if (result.length < 4) return null; |
| 80 return result; |
| 81 } |
| 82 JavaFile getParentFile() { |
| 83 var parent = getParent(); |
| 84 if (parent == null) return null; |
| 85 return new JavaFile(parent); |
| 86 } |
| 87 String getAbsolutePath() { |
| 88 String path = pathos.absolute(_path); |
| 89 path = pathos.normalize(path); |
| 90 return path; |
| 91 } |
| 92 String getCanonicalPath() { |
| 93 try { |
| 94 return _newFile().resolveSymbolicLinksSync(); |
| 95 } catch (e) { |
| 96 throw new JavaIOException('IOException', e); |
| 97 } |
| 98 } |
| 99 JavaFile getAbsoluteFile() => new JavaFile(getAbsolutePath()); |
| 100 JavaFile getCanonicalFile() => new JavaFile(getCanonicalPath()); |
| 101 bool exists() { |
| 102 if (_newFile().existsSync()) { |
| 103 return true; |
| 104 } |
| 105 if (_newDirectory().existsSync()) { |
| 106 return true; |
| 107 } |
| 108 return false; |
| 109 } |
| 110 bool isExecutable() { |
| 111 return _newFile().statSync().mode & 0x111 != 0; |
| 112 } |
| 113 bool isFile() { |
| 114 return _newFile().existsSync(); |
| 115 } |
| 116 bool isDirectory() { |
| 117 return _newDirectory().existsSync(); |
| 118 } |
| 119 Uri toURI() { |
| 120 String path = getAbsolutePath(); |
| 121 return pathos.toUri(path); |
| 122 } |
| 123 String readAsStringSync() => _newFile().readAsStringSync(); |
| 124 int lastModified() { |
| 125 if (!_newFile().existsSync()) return 0; |
| 126 return _newFile().lastModifiedSync().millisecondsSinceEpoch; |
| 127 |
| 128 } |
| 129 List<JavaFile> listFiles() { |
| 130 var files = <JavaFile>[]; |
| 131 var entities = _newDirectory().listSync(); |
| 132 for (FileSystemEntity entity in entities) { |
| 133 files.add(new JavaFile(entity.path)); |
| 134 } |
| 135 return files; |
| 136 } |
| 137 File _newFile() => new File(_path); |
| 138 Directory _newDirectory() => new Directory(_path); |
| 139 } |
OLD | NEW |