1 28 package org.jruby.util; 29 30 import java.io.File ; 31 import java.io.FileFilter ; 32 import java.io.FilenameFilter ; 33 import java.io.IOException ; 34 import java.net.URI ; 35 36 40 public class NormalizedFile extends File { 41 private static final long serialVersionUID = 7630618150344842227L; 42 43 public NormalizedFile(String pathname) { 44 super(pathname); 45 } 46 47 public NormalizedFile(URI uri) { 48 super(uri); 49 } 50 51 public NormalizedFile(File parent, String child) { 52 super(parent, child); 53 } 54 55 public NormalizedFile(String parent, String child) { 56 super(parent, child); 57 } 58 59 public String getAbsolutePath() { 60 return super.getAbsolutePath().replace(File.separatorChar, '/'); 61 } 62 63 public String getCanonicalPath() throws IOException { 64 return super.getCanonicalPath().replace(File.separatorChar, '/'); 65 } 66 67 public String getPath() { 68 return super.getPath().replace(File.separatorChar, '/'); 69 } 70 71 public String toString() { 72 return super.toString().replace(File.separatorChar, '/'); 73 } 74 75 public File getAbsoluteFile() { 76 return new NormalizedFile(getAbsolutePath()); 77 } 78 79 public File getCanonicalFile() throws IOException { 80 return new NormalizedFile(getCanonicalPath()); 81 } 82 83 public String getParent() { 84 return super.getParent().replace(File.separatorChar, '/'); 85 } 86 87 public File getParentFile() { 88 return new NormalizedFile(getParent()); 89 } 90 91 public static File [] listRoots() { 92 File [] roots = File.listRoots(); 93 NormalizedFile[] smartRoots = new NormalizedFile[roots.length]; 94 for (int i = 0; i < roots.length; i++) { 95 smartRoots[i] = new NormalizedFile(roots[i].getPath()); 96 } 97 98 return smartRoots; 99 } 100 101 public static File createTempFile(String prefix, String suffix, File directory) throws IOException { 102 File file = File.createTempFile(prefix, suffix, directory); 103 return new NormalizedFile(file.getPath()); 104 } 105 106 public static File createTempFile(String prefix, String suffix) throws IOException { 107 File file = File.createTempFile(prefix, suffix); 108 return new NormalizedFile(file.getPath()); 109 } 110 111 public String [] list() { 112 return super.list(); 113 } 114 115 public String [] list(FilenameFilter filter) { 116 String [] files = super.list(filter); 117 118 if (files == null) { 119 return null; 120 } else { 121 String [] smartFiles = new String [files.length]; 122 for (int i = 0; i < files.length; i++) { 123 smartFiles[i] = files[i].replace(File.separatorChar, '/'); 124 } 125 return smartFiles; 126 } 127 } 128 129 public File [] listFiles() { 130 File [] files = super.listFiles(); 131 132 if (files == null) { 133 return null; 134 } else { 135 NormalizedFile[] smartFiles = new NormalizedFile[files.length]; 136 for (int i = 0; i < files.length; i++) { 137 smartFiles[i] = new NormalizedFile(files[i].getPath()); 138 } 139 return smartFiles; 140 } 141 } 142 143 public File [] listFiles(FileFilter filter) { 144 File [] files = super.listFiles(filter); 145 146 if (files == null) { 147 return null; 148 } else { 149 NormalizedFile[] smartFiles = new NormalizedFile[files.length]; 150 for (int i = 0; i < files.length; i++) { 151 smartFiles[i] = new NormalizedFile(files[i].getPath()); 152 } 153 return smartFiles; 154 } 155 } 156 157 public File [] listFiles(FilenameFilter filter) { 158 File [] files = super.listFiles(filter); 159 160 if (files == null) { 161 return null; 162 } else { 163 NormalizedFile[] smartFiles = new NormalizedFile[files.length]; 164 for (int i = 0; i < files.length; i++) { 165 smartFiles[i] = new NormalizedFile(files[i].getPath()); 166 } 167 return smartFiles; 168 } 169 } 170 171 public static String getFileProperty(String property) { 172 String value = System.getProperty(property); 173 174 return value.replace(File.separatorChar, '/'); 175 } 176 } 177 | Popular Tags |