gvsig-projects-pool / org.gvsig.jvmpreferences / trunk / org.gvsig.jvmpreferences.native / org.gvsig.jvmpreferences.native.lib / org.gvsig.jvmpreferences.native.lib.impl.windows / src / main / java / org / gvsig / jvmpreferences / nativeprefs / MemoryPreferencesWindows.java @ 6
History | View | Annotate | Download (2.19 KB)
1 |
package org.gvsig.jvmpreferences.nativeprefs; |
---|---|
2 |
|
3 |
|
4 |
import java.io.BufferedReader; |
5 |
import java.io.BufferedWriter; |
6 |
import java.io.File; |
7 |
import java.io.FileNotFoundException; |
8 |
import java.io.FileReader; |
9 |
import java.io.FileWriter; |
10 |
import java.io.IOException; |
11 |
import java.lang.management.ManagementFactory; |
12 |
import java.text.SimpleDateFormat; |
13 |
import java.util.Date; |
14 |
|
15 |
import javax.management.AttributeNotFoundException; |
16 |
import javax.management.InstanceNotFoundException; |
17 |
import javax.management.MBeanException; |
18 |
import javax.management.MBeanServer; |
19 |
import javax.management.MalformedObjectNameException; |
20 |
import javax.management.ObjectName; |
21 |
import javax.management.ReflectionException; |
22 |
|
23 |
import org.gvsig.andami.Launcher; |
24 |
import org.gvsig.i18n.Messages; |
25 |
import org.gvsig.jvmpreferences.nativeprefs.BaseMemoryPreferences; |
26 |
import org.gvsig.utils.DateTime; |
27 |
import org.slf4j.LoggerFactory; |
28 |
|
29 |
/**
|
30 |
* This class abstracts the complexity of reading/storing
|
31 |
* memory preferences for different operating systems.
|
32 |
* Windows implementation
|
33 |
*
|
34 |
* @author Cesar Martinez Izquierdo
|
35 |
*
|
36 |
*/
|
37 |
public class MemoryPreferencesWindows extends BaseMemoryPreferences { |
38 |
public static final String CONFIG_FILE_WINDOWS="gvsig-desktop.l4j.ini"; |
39 |
private File configFile; |
40 |
|
41 |
public MemoryPreferencesWindows() {
|
42 |
super();
|
43 |
configFile = new File(Launcher.getApplicationDirectory() + File.separator + CONFIG_FILE_WINDOWS); |
44 |
} |
45 |
|
46 |
public File getConfigFile() { |
47 |
return configFile;
|
48 |
} |
49 |
|
50 |
/* (non-Javadoc)
|
51 |
* @see org.gvsig.preferences.nativeprefs.general.memory.MemoryPreferences#isConfigWritable()
|
52 |
*/
|
53 |
public boolean isConfigWritable(){ |
54 |
// We can't use getConfigFile().canWrite() because the file
|
55 |
// is writable *at file system level* (so this method returns true),
|
56 |
// but writing fails as the user has no effective permissions (on Win7)
|
57 |
try {
|
58 |
File f = getConfigFile();
|
59 |
File test = new File(f.getAbsolutePath()+".test"); |
60 |
if (f.renameTo(test) && test.renameTo(f)) {
|
61 |
return true; |
62 |
} |
63 |
} |
64 |
catch (Exception ex) { |
65 |
} |
66 |
return false; |
67 |
} |
68 |
|
69 |
@Override
|
70 |
protected String getMaxMemoryRegexp() { |
71 |
return "\\s*#?\\s*-Xmx(\\d+)([mMkKgG]?)\\s*"; |
72 |
} |
73 |
|
74 |
@Override
|
75 |
protected String getEncodedMaxMemoryLine(int maximumMemory) { |
76 |
return " -Xmx"+maximumMemory+"m"; |
77 |
} |
78 |
|
79 |
} |