comparison java/src/java/io/File.d @ 21:9b96950f2c3c

the 'java' tree compiles on both D1-Tango and D2-Phobos
author Frank Benoit <benoit@tionex.de>
date Thu, 19 Mar 2009 20:38:55 +0100
parents 6dd524f61e62
children
comparison
equal deleted inserted replaced
20:dccb717aa902 21:9b96950f2c3c
3 */ 3 */
4 module java.io.File; 4 module java.io.File;
5 5
6 import java.lang.all; 6 import java.lang.all;
7 7
8 static import tango.io.model.IFile; 8 version(Tango){
9 static import tango.io.FilePath; 9 static import tango.io.model.IFile;
10 static import tango.io.Path; 10 static import tango.io.FilePath;
11 static import tango.io.FileSystem; 11 static import tango.io.Path;
12 static import tango.io.FileSystem;
13 } else { // Phobos
14 static import std.file;
15 static import std.path;
16 }
12 17
13 public class File { 18 public class File {
14 19
15 public static char separatorChar; 20 public static char separatorChar;
16 public static String separator; 21 public static String separator;
17 public static char pathSeparatorChar; 22 public static char pathSeparatorChar;
18 public static String pathSeparator; 23 public static String pathSeparator;
19 24
20 private tango.io.FilePath.FilePath mFilePath; 25 private String mFilePath;
21 26
22 static this(){ 27 static this(){
23 separator = tango.io.model.IFile.FileConst.PathSeparatorString; 28 version(Tango){
24 separatorChar = tango.io.model.IFile.FileConst.PathSeparatorChar; 29 separator = tango.io.model.IFile.FileConst.PathSeparatorString;
25 pathSeparator = tango.io.model.IFile.FileConst.SystemPathString; 30 separatorChar = tango.io.model.IFile.FileConst.PathSeparatorChar;
26 pathSeparatorChar = tango.io.model.IFile.FileConst.SystemPathChar; 31 pathSeparator = tango.io.model.IFile.FileConst.SystemPathString;
32 pathSeparatorChar = tango.io.model.IFile.FileConst.SystemPathChar;
33 } else { // Phobos
34 version(Windows){
35 separator = "\\";
36 separatorChar = '\\';
37 pathSeparator = ";";
38 pathSeparatorChar = ';';
39 }
40 else{
41 separator = "/";
42 separatorChar = '/';
43 pathSeparator = ":";
44 pathSeparatorChar = ':';
45 }
46 }
47 }
48
49 private static String toStd( String path ){
50 version(Tango){
51 return tango.io.Path.standard( path );
52 } else { // Phobos
53 return path;
54 }
55 }
56 private static String join( String path, String file ){
57 version(Tango){
58 return tango.io.Path.join( path, file );
59 } else { // Phobos
60 return std.path.join( path, file );
61 }
27 } 62 }
28 63
29 public this ( String pathname ){ 64 public this ( String pathname ){
30 mFilePath = new tango.io.FilePath.FilePath( tango.io.Path.standard( pathname )); 65 mFilePath = toStd( pathname );
31 } 66 }
32 67
33 public this ( String parent, String child ){ 68 public this ( String parent, String child ){
34 mFilePath = new tango.io.FilePath.FilePath( tango.io.FilePath.FilePath.join( parent, child ) ); 69 mFilePath = join( toStd(parent), toStd(child) );
35 } 70 }
36 71
37 public this ( java.io.File.File parent, String child ){ 72 public this ( java.io.File.File parent, String child ){
38 mFilePath = new tango.io.FilePath.FilePath( tango.io.FilePath.FilePath.join( parent.mFilePath.toString, child ) ); 73 mFilePath = join( parent.mFilePath, toStd(child) );
39 } 74 }
40 75
41 public int getPrefixLength(){ 76 public int getPrefixLength(){
42 implMissing( __FILE__, __LINE__ ); 77 implMissing( __FILE__, __LINE__ );
43 return 0; 78 return 0;
67 implMissing( __FILE__, __LINE__ ); 102 implMissing( __FILE__, __LINE__ );
68 return false; 103 return false;
69 } 104 }
70 105
71 public String getAbsolutePath(){ 106 public String getAbsolutePath(){
72 return tango.io.FileSystem.FileSystem.toAbsolute( mFilePath ).toString; 107 version(Tango){
108 return tango.io.FileSystem.FileSystem.toAbsolute( mFilePath );
109 } else { // Phobos
110 implMissing( __FILE__, __LINE__ );
111 return "";
112 }
73 } 113 }
74 114
75 public java.io.File.File getAbsoluteFile(){ 115 public java.io.File.File getAbsoluteFile(){
76 return new File( getAbsolutePath() ); 116 version(Tango){
117 return new File( getAbsolutePath() );
118 } else { // Phobos
119 implMissing( __FILE__, __LINE__ );
120 return null;
121 }
77 } 122 }
78 123
79 public String getCanonicalPath(){ 124 public String getCanonicalPath(){
80 implMissing( __FILE__, __LINE__ ); 125 implMissing( __FILE__, __LINE__ );
81 return null; 126 return null;
90 implMissing( __FILE__, __LINE__ ); 135 implMissing( __FILE__, __LINE__ );
91 return false; 136 return false;
92 } 137 }
93 138
94 public bool canWrite(){ 139 public bool canWrite(){
95 return mFilePath.isWritable; 140 version(Tango){
141 return tango.io.Path.isWritable(mFilePath);
142 } else { // Phobos
143 implMissing( __FILE__, __LINE__ );
144 return false;
145 }
96 } 146 }
97 147
98 public bool exists(){ 148 public bool exists(){
99 return mFilePath.exists; 149 version(Tango){
150 return tango.io.Path.exists(mFilePath);
151 } else { // Phobos
152 implMissing( __FILE__, __LINE__ );
153 return false;
154 }
100 } 155 }
101 156
102 public bool isDirectory(){ 157 public bool isDirectory(){
103 return mFilePath.isFolder; 158 version(Tango){
159 return tango.io.Path.isFolder(mFilePath);
160 } else { // Phobos
161 implMissing( __FILE__, __LINE__ );
162 return false;
163 }
104 } 164 }
105 165
106 public bool isFile(){ 166 public bool isFile(){
107 implMissing( __FILE__, __LINE__ ); 167 implMissing( __FILE__, __LINE__ );
108 return false; 168 return false;