Author: jerome
Date: 2008-12-14 14:07:31 +0100 (Sun, 14 Dec 2008)
New Revision: 3112
Modified:
software_suite_v2/software/control_center/branches/new_paths/control_center/sources/com/tuxdroid/cc/settings/XMLWriter.java
Log:
* With function it's better :p
Modified:
software_suite_v2/software/control_center/branches/new_paths/control_center/sources/com/tuxdroid/cc/settings/XMLWriter.java
===================================================================
---
software_suite_v2/software/control_center/branches/new_paths/control_center/sources/com/tuxdroid/cc/settings/XMLWriter.java
2008-12-14 12:50:56 UTC (rev 3111)
+++
software_suite_v2/software/control_center/branches/new_paths/control_center/sources/com/tuxdroid/cc/settings/XMLWriter.java
2008-12-14 13:07:31 UTC (rev 3112)
@@ -22,7 +22,11 @@
package com.tuxdroid.cc.settings;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;
@@ -73,6 +77,7 @@
this.writeVerionIfNewer();
if(!this.isValid())
{
+ CcCommons.logger.append("Settings file empty, creating
an other one", true);
this.xmlFile.delete();
//Try again.
this.createBaseSettingsStructure();
@@ -86,6 +91,37 @@
*/
private boolean isValid()
{
+ if(!xmlFile.exists())
+ {
+ return false;
+ }
+
+ int lineCount = 0;
+
+ //Try to read something. If it works, that mean file is not
empty.
+ try
+ {
+ InputStream ips = new FileInputStream(this.xmlFile);
+ InputStreamReader ipsr = new InputStreamReader(ips);
+ BufferedReader br = new BufferedReader(ipsr);
+
+ while (br.readLine() != null)
+ {
+ lineCount += 1;
+ }
+
+ br.close();
+ }
+ catch (Exception e)
+ {
+ return false;
+ }
+
+ if(lineCount > 0)
+ {
+ return true;
+ }
+
return false;
}
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn