Subversion Repository Public Repository

litesoft

Diff Revisions 314 vs 315 for /trunk/Java/ScarPlus/src/com/esotericsoftware/utils/Util.java

Diff revisions: vs.
  @@ -1,8 +1,5 @@
1 1 package com.esotericsoftware.utils;
2 2
3 - import java.io.*;
4 - import java.nio.channels.*;
5 -
6 3 import org.litesoft.logger.*;
7 4
8 5 @SuppressWarnings({"UnusedDeclaration"})
  @@ -15,20 +12,6 @@
15 12 PROGRESS_LINE_SINK.addLine( pMessage );
16 13 }
17 14
18 - public static final File CANONICAL_USER_DIR;
19 -
20 - static
21 - {
22 - try
23 - {
24 - CANONICAL_USER_DIR = new File( System.getProperty( "user.dir" ) ).getCanonicalFile();
25 - }
26 - catch ( IOException e )
27 - {
28 - throw new Error( e );
29 - }
30 - }
31 -
32 15 /**
33 16 * True if running on a Mac OS.
34 17 */
  @@ -43,45 +26,6 @@
43 26
44 27 public static final Logger LOGGER = LoggerFactory.getLogger( Util.class );
45 28
46 - private static final IFileSystem FILE_SYSTEM = new IFileSystem()
47 - {
48 - @Override
49 - public boolean isWindows()
50 - {
51 - return isWindows;
52 - }
53 -
54 - @Override
55 - public char separatorChar()
56 - {
57 - return File.separatorChar;
58 - }
59 -
60 - @Override
61 - public String canonicalCurrentPath()
62 - {
63 - return CANONICAL_USER_DIR.getPath();
64 - }
65 -
66 - @Override
67 - public boolean exists( String path )
68 - {
69 - return new File( path ).exists();
70 - }
71 -
72 - @Override
73 - public String canonicalizeNormalizedExisting( String path )
74 - throws IOException
75 - {
76 - File zFile = new File( path );
77 - if ( zFile.exists() )
78 - {
79 - return zFile.getCanonicalPath();
80 - }
81 - throw new FileNotFoundException( path );
82 - }
83 - };
84 -
85 29 public static String noEmpty( String pToTest )
86 30 {
87 31 if ( pToTest != null )
  @@ -143,16 +87,6 @@
143 87 }
144 88 }
145 89
146 - public static File assertExists( String pWhat, File pToTest )
147 - {
148 - assertNotNull( pWhat, pToTest );
149 - if ( !pToTest.exists() )
150 - {
151 - throw new IllegalArgumentException( pWhat + " not found: " + pToTest.getAbsolutePath() );
152 - }
153 - return pToTest;
154 - }
155 -
156 90 public static String replace( String pSource, String pOfInterest, String pReplaceWith )
157 91 {
158 92 for ( int at; -1 != (at = pSource.indexOf( pOfInterest )); )
  @@ -162,101 +96,8 @@
162 96 return pSource;
163 97 }
164 98
165 - /**
166 - * Copies one file to another.
167 - */
168 - @SuppressWarnings({"ResultOfMethodCallIgnored"})
169 - public static void copyFile( File in, File out )
170 - throws IOException
171 - {
172 - out.getParentFile().mkdirs();
173 - FileChannel sourceChannel = new FileInputStream( in ).getChannel();
174 - FileChannel destinationChannel = new FileOutputStream( out ).getChannel();
175 - sourceChannel.transferTo( 0, sourceChannel.size(), destinationChannel );
176 - sourceChannel.close();
177 - destinationChannel.close();
178 - }
179 -
180 - /**
181 - * Creates the directories in the specified path.
182 - */
183 - public static String mkdir( String path )
184 - {
185 - if ( new File( path = assertNotEmpty( "path", path ) ).mkdirs() )
186 - {
187 - LOGGER.trace.log( "Created directory: ", path );
188 - }
189 - return path;
190 - }
191 -
192 - /**
193 - * Deletes a directory and all files and directories it contains.
194 - */
195 - public static boolean delete( File pFile )
196 - {
197 - assertNotNull( "File", pFile );
198 - if ( pFile.isDirectory() )
199 - {
200 - File[] zFiles = pFile.listFiles();
201 - for ( File zFile : zFiles )
202 - {
203 - if ( !delete( zFile ) )
204 - {
205 - return false;
206 - }
207 - }
208 - }
209 - LOGGER.trace.log( "Deleting file: ", pFile );
210 - return pFile.delete();
211 - }
212 -
213 - /**
214 - * Deletes a file or directory and all files and subdirecties under it.
215 - */
216 - public static boolean delete( String fileName )
217 - {
218 - return delete( new File( assertNotEmpty( "fileName", fileName ) ) );
219 - }
220 -
221 - public static Closeable dispose( Closeable pCloseable )
222 - {
223 - if ( pCloseable != null )
224 - {
225 - try
226 - {
227 - pCloseable.close();
228 - }
229 - catch ( IOException ignore )
230 - {
231 - // Whatever!
232 - }
233 - pCloseable = null;
234 - }
235 - return pCloseable;
236 - }
237 -
238 - public static boolean isAbsolutePath( String path )
239 - {
240 - assertNotNull( "path", path );
241 - return FileSupport.isAbsoluteNormalizedPath( FILE_SYSTEM, CANONICAL_USER_DIR.getPath(), FileSupport.normalizePath( FILE_SYSTEM, path ) );
242 - }
243 -
244 - public static String normalizePath( String path )
245 - {
246 - assertNotNull( "path", path );
247 - return FileSupport.normalizePath( FILE_SYSTEM, path );
248 - }
249 -
250 - public static File canonicalizePath( String path )
251 - throws IOException
252 - {
253 - return canonicalizePath( CANONICAL_USER_DIR, path );
254 - }
255 -
256 - public static File canonicalizePath( File pCanonicalParentDirIfPathRelative, String path )
257 - throws IOException
99 + public static String toString( Object o )
258 100 {
259 - assertNotNull( "path", path );
260 - return new File( FileSupport.canonicalizeNormalizedPath( FILE_SYSTEM, pCanonicalParentDirIfPathRelative.getPath(), FileSupport.normalizePath( FILE_SYSTEM, path ) ) );
101 + return (o != null) ? o.toString() : null;
261 102 }
262 103 }