|
@@ -4,13 +4,11 @@ |
4 |
4 |
|
import java.io.*; |
5 |
5 |
|
import java.util.*; |
6 |
6 |
|
|
7 |
|
- |
import org.litesoft.core.util.stringmatching.*; |
8 |
7 |
|
import org.litesoft.core.util.*; |
|
8 |
+ |
import org.litesoft.core.util.stringmatching.*; |
9 |
9 |
|
|
10 |
|
- |
public class FileUtils |
|
10 |
+ |
public class FileUtils extends FileUtil |
11 |
11 |
|
{ |
12 |
|
- |
public static final String UTF_8 = "UTF-8"; |
13 |
|
- |
|
14 |
12 |
|
public static Reader[] filesToReaders( File pDir, String... pFileNames ) |
15 |
13 |
|
throws FileNotFoundException |
16 |
14 |
|
{ |
|
@@ -109,8 +107,7 @@ |
109 |
107 |
|
long fSize = pFile.length(); |
110 |
108 |
|
if ( fSize > pMaxAllowedSize ) |
111 |
109 |
|
{ |
112 |
|
- |
throw new FileSystemException( |
113 |
|
- |
"File Too large (" + fSize + "), but max set to: " + pMaxAllowedSize ); |
|
110 |
+ |
throw new FileSystemException( "File Too large (" + fSize + "), but max set to: " + pMaxAllowedSize ); |
114 |
111 |
|
} |
115 |
112 |
|
int fileSize = (int) fSize; |
116 |
113 |
|
byte[] b = new byte[fileSize]; |
|
@@ -127,8 +124,7 @@ |
127 |
124 |
|
is.close(); |
128 |
125 |
|
if ( offset != fileSize ) |
129 |
126 |
|
{ |
130 |
|
- |
throw new FileSystemException( "Unable to read the entire file. Expected " + fileSize + |
131 |
|
- |
", but only got: " + offset ); |
|
127 |
+ |
throw new FileSystemException( "Unable to read the entire file. Expected " + fileSize + ", but only got: " + offset ); |
132 |
128 |
|
} |
133 |
129 |
|
} |
134 |
130 |
|
finally |
|
@@ -168,9 +164,7 @@ |
168 |
164 |
|
{ |
169 |
165 |
|
try |
170 |
166 |
|
{ |
171 |
|
- |
OutputStreamWriter ow = new OutputStreamWriter( new FileOutputStream( pFile, pAppend ), UTF_8 ); |
172 |
|
- |
BufferedWriter writer = new BufferedWriter( ow ); |
173 |
|
- |
addLines( writer, pLines ); |
|
167 |
+ |
addLines( createWriter( pFile, pAppend ), pLines ); |
174 |
168 |
|
} |
175 |
169 |
|
catch ( IOException e ) |
176 |
170 |
|
{ |
|
@@ -215,8 +209,7 @@ |
215 |
209 |
|
throw new FileNotFoundException( pFile.getAbsolutePath() ); |
216 |
210 |
|
} |
217 |
211 |
|
List<String> lines = new LinkedList<String>(); |
218 |
|
- |
InputStreamReader r = new InputStreamReader( new FileInputStream( pFile ), UTF_8 ); |
219 |
|
- |
BufferedReader reader = new BufferedReader( r ); |
|
212 |
+ |
BufferedReader reader = createReader( pFile ); |
220 |
213 |
|
boolean closed = false; |
221 |
214 |
|
try |
222 |
215 |
|
{ |
|
@@ -261,8 +254,7 @@ |
261 |
254 |
|
} |
262 |
255 |
|
|
263 |
256 |
|
StringBuilder buffer = new StringBuilder(); |
264 |
|
- |
InputStreamReader r = new InputStreamReader( new FileInputStream( pFile ), UTF_8 ); |
265 |
|
- |
BufferedReader reader = new BufferedReader( r ); |
|
257 |
+ |
BufferedReader reader = createReader( pFile ); |
266 |
258 |
|
boolean closed = false; |
267 |
259 |
|
try |
268 |
260 |
|
{ |
|
@@ -328,8 +320,7 @@ |
328 |
320 |
|
@SuppressWarnings({"ResultOfMethodCallIgnored"}) |
329 |
321 |
|
private static void attemptToRollBack( File pNewFile, File pTargetFile, File pBackupFile ) |
330 |
322 |
|
{ |
331 |
|
- |
switch ( (pNewFile.exists() ? 0 : 4) + (pTargetFile.exists() ? 0 : 2) + |
332 |
|
- |
(pBackupFile.exists() ? 0 : 1) ) |
|
323 |
+ |
switch ( (pNewFile.exists() ? 0 : 4) + (pTargetFile.exists() ? 0 : 2) + (pBackupFile.exists() ? 0 : 1) ) |
333 |
324 |
|
{ |
334 |
325 |
|
// What Happen'd |
335 |
326 |
|
case 0: // There: ------------- Nobody -------------- |
|
@@ -370,8 +361,7 @@ |
370 |
361 |
|
} |
371 |
362 |
|
if ( pDestinationFile.exists() ) |
372 |
363 |
|
{ |
373 |
|
- |
throw new FileSystemException( |
374 |
|
- |
"DestinationFile already exists: " + pDestinationFile.getAbsolutePath() ); |
|
364 |
+ |
throw new FileSystemException( "DestinationFile already exists: " + pDestinationFile.getAbsolutePath() ); |
375 |
365 |
|
} |
376 |
366 |
|
// Win 2 Start |
377 |
367 |
|
if ( !pSourceFile.renameTo( pDestinationFile ) ) // Win 1 End |
|
@@ -383,21 +373,17 @@ |
383 |
373 |
|
// Win 2 End |
384 |
374 |
|
if ( sThere ) |
385 |
375 |
|
{ |
386 |
|
- |
throw renameFailed( pSourceFile, pDestinationFile, "claims Succeess, but Source still there" + ( |
387 |
|
- |
dThere ? " and so is the Destination!" : "!") ); |
|
376 |
+ |
throw renameFailed( pSourceFile, pDestinationFile, "claims Succeess, but Source still there" + (dThere ? " and so is the Destination!" : "!") ); |
388 |
377 |
|
} |
389 |
378 |
|
if ( !dThere ) |
390 |
379 |
|
{ |
391 |
|
- |
throw renameFailed( pSourceFile, pDestinationFile, |
392 |
|
- |
"claims Succeess, but the Destination is NOT there!" ); |
|
380 |
+ |
throw renameFailed( pSourceFile, pDestinationFile, "claims Succeess, but the Destination is NOT there!" ); |
393 |
381 |
|
} |
394 |
382 |
|
} |
395 |
383 |
|
|
396 |
|
- |
private static FileSystemException renameFailed( File pSourceFile, File pDestinationFile, |
397 |
|
- |
String pAdditionalExplanation ) |
|
384 |
+ |
private static FileSystemException renameFailed( File pSourceFile, File pDestinationFile, String pAdditionalExplanation ) |
398 |
385 |
|
{ |
399 |
|
- |
throw new FileSystemException( "Rename (" + pSourceFile.getAbsolutePath() + ") to (" + |
400 |
|
- |
pDestinationFile.getAbsolutePath() + ") " + pAdditionalExplanation ); |
|
386 |
+ |
throw new FileSystemException( "Rename (" + pSourceFile.getAbsolutePath() + ") to (" + pDestinationFile.getAbsolutePath() + ") " + pAdditionalExplanation ); |
401 |
387 |
|
} |
402 |
388 |
|
|
403 |
389 |
|
private static class StringMatcherFilenameFilter implements FilenameFilter |
|
@@ -487,8 +473,7 @@ |
487 |
473 |
|
} |
488 |
474 |
|
return; |
489 |
475 |
|
} |
490 |
|
- |
if ( isAttributeOneOf( zLine, "fkonly", "isContainer", "IsContainer", "ReferenceSortColumn", |
491 |
|
- |
"ThemDependsOnUs", "UsDependsOnThem", "table", "updateReferencedPO" ) ) |
|
476 |
+ |
if ( isAttributeOneOf( zLine, "fkonly", "isContainer", "IsContainer", "ReferenceSortColumn", "ThemDependsOnUs", "UsDependsOnThem", "table", "updateReferencedPO" ) ) |
492 |
477 |
|
{ |
493 |
478 |
|
pLines[i] = null; |
494 |
479 |
|
} |
|
@@ -504,8 +489,7 @@ |
504 |
489 |
|
if ( zLine != null ) |
505 |
490 |
|
{ |
506 |
491 |
|
zLine = zLine.trim(); |
507 |
|
- |
if ( isAttributeOneOf( zLine, "fkonly", "isContainer", "IsContainer", "defaultValue", |
508 |
|
- |
"enumeration", "len" ) ) |
|
492 |
+ |
if ( isAttributeOneOf( zLine, "fkonly", "isContainer", "IsContainer", "defaultValue", "enumeration", "len" ) ) |
509 |
493 |
|
{ |
510 |
494 |
|
pLines[i] = null; |
511 |
495 |
|
} |