Revision 10042 trunk/frameworks/_fwAndami/src/com/iver/andami/Launcher.java
Launcher.java | ||
---|---|---|
66 | 66 |
import java.net.PasswordAuthentication; |
67 | 67 |
import java.net.URL; |
68 | 68 |
import java.net.URLConnection; |
69 |
import java.nio.channels.FileChannel; |
|
69 | 70 |
import java.security.AllPermission; |
70 | 71 |
import java.security.CodeSource; |
71 | 72 |
import java.security.PermissionCollection; |
... | ... | |
1307 | 1308 |
|
1308 | 1309 |
FileWriter writer = new FileWriter(tmpFile); |
1309 | 1310 |
andamiConfig.marshal(writer); |
1310 |
// if marshaling process finished correctly, move the file to the correct one |
|
1311 |
tmpFile.renameTo(xml); |
|
1311 |
writer.close(); |
|
1312 |
|
|
1313 |
// if marshaling process finished correctly, move the file to the correct one |
|
1314 |
xml.delete(); |
|
1315 |
if (!tmpFile.renameTo(xml)) { |
|
1316 |
// if rename was not succesful, try copying it |
|
1317 |
FileChannel sourceChannel = new FileInputStream(tmpFile).getChannel(); |
|
1318 |
FileChannel destinationChannel = new FileOutputStream(xml).getChannel(); |
|
1319 |
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel); |
|
1320 |
sourceChannel.close(); |
|
1321 |
destinationChannel.close(); |
|
1322 |
} |
|
1312 | 1323 |
} |
1313 | 1324 |
|
1314 | 1325 |
/** |
... | ... | |
1322 | 1333 |
throws ConfigurationException { |
1323 | 1334 |
File xml = new File(file); |
1324 | 1335 |
|
1336 |
FileReader reader = null; |
|
1325 | 1337 |
try { |
1326 | 1338 |
//Se lee la configuraci?n |
1327 |
FileReader reader = new FileReader(xml);
|
|
1339 |
reader = new FileReader(xml); |
|
1328 | 1340 |
andamiConfig = (AndamiConfig) AndamiConfig.unmarshal(reader); |
1329 | 1341 |
} catch (FileNotFoundException e) { |
1330 | 1342 |
//Si no existe se ponen los valores por defecto |
1331 | 1343 |
andamiConfig = getDefaultAndamiConfig(); |
1332 | 1344 |
} catch (MarshalException e) { |
1345 |
// try to close the stream, maybe it remains open |
|
1346 |
if (reader!=null) { |
|
1347 |
try { reader.close(); } catch (IOException e1) {} |
|
1348 |
} |
|
1333 | 1349 |
// if there was a problem reading the file, backup it and create a new one with default values |
1334 | 1350 |
String backupFile = file+"-"+DateTime.getCurrentDate().getTime(); |
1335 | 1351 |
NotificationManager.addError(Messages.getString("Error_reading_andami_config_New_file_created_A_backup_was_made_on_")+backupFile, new ConfigurationException(e)); |
... | ... | |
1375 | 1391 |
File xml = new File(pluginsPersistencePath); |
1376 | 1392 |
|
1377 | 1393 |
if (xml.exists()) { |
1378 |
FileReader reader; |
|
1394 |
FileReader reader = null;
|
|
1379 | 1395 |
|
1380 | 1396 |
try { |
1381 | 1397 |
reader = new FileReader(xml); |
... | ... | |
1386 | 1402 |
} catch (FileNotFoundException e) { |
1387 | 1403 |
throw new ConfigurationException(e); |
1388 | 1404 |
} catch (MarshalException e) { |
1405 |
// try to close the stream, maybe it remains open |
|
1406 |
if (reader!=null) { |
|
1407 |
try { reader.close(); } catch (IOException e1) {} |
|
1408 |
} |
|
1389 | 1409 |
String backupFile = pluginsPersistencePath+"-"+DateTime.getCurrentDate().getTime(); |
1390 | 1410 |
NotificationManager.addError(Messages.getString("Error_reading_plugin_persinstence_New_file_created_A_backup_was_made_on_")+backupFile, new ConfigurationException(e)); |
1391 | 1411 |
xml.renameTo(new File(backupFile)); |
... | ... | |
1411 | 1431 |
File tmpFile = new File(pluginsPersistencePath+"-"+DateTime.getCurrentDate().getTime()); |
1412 | 1432 |
|
1413 | 1433 |
File xml = new File(pluginsPersistencePath); |
1414 |
|
|
1415 |
FileWriter writer; |
|
1416 |
|
|
1434 |
FileWriter writer=null; |
|
1417 | 1435 |
try { |
1418 | 1436 |
writer = new FileWriter(tmpFile); |
1419 | 1437 |
entity.getXmlTag().marshal(writer); |
1438 |
writer.close(); |
|
1439 |
|
|
1420 | 1440 |
// if marshaling process finished correctly, move the file to the correct one |
1421 |
tmpFile.renameTo(xml); |
|
1441 |
xml.delete(); |
|
1442 |
if (!tmpFile.renameTo(xml)) { |
|
1443 |
// if rename was not succesful, try copying it |
|
1444 |
FileChannel sourceChannel = new FileInputStream(tmpFile).getChannel(); |
|
1445 |
FileChannel destinationChannel = new FileOutputStream(xml).getChannel(); |
|
1446 |
sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel); |
|
1447 |
sourceChannel.close(); |
|
1448 |
destinationChannel.close(); |
|
1449 |
|
|
1450 |
} |
|
1422 | 1451 |
} catch (FileNotFoundException e) { |
1423 | 1452 |
throw new ConfigurationException(e); |
1424 | 1453 |
} catch (MarshalException e) { |
1425 |
throw new ConfigurationException(e); |
|
1454 |
// try to close the stream, maybe it remains open |
|
1455 |
if (writer!=null) { |
|
1456 |
try { writer.close(); } catch (IOException e1) {} |
|
1457 |
} |
|
1426 | 1458 |
} catch (ValidationException e) { |
1427 | 1459 |
throw new ConfigurationException(e); |
1428 | 1460 |
} catch (IOException e) { |
Also available in: Unified diff