Lines 43-48
Link Here
|
43 |
|
43 |
|
44 |
import java.io.BufferedOutputStream; |
44 |
import java.io.BufferedOutputStream; |
45 |
import java.io.File; |
45 |
import java.io.File; |
|
|
46 |
import java.io.FileInputStream; |
46 |
import java.io.FileOutputStream; |
47 |
import java.io.FileOutputStream; |
47 |
import java.io.IOException; |
48 |
import java.io.IOException; |
48 |
import java.io.InputStream; |
49 |
import java.io.InputStream; |
Lines 78-84
Link Here
|
78 |
assert cacheDir != null && cacheDir.exists (); |
79 |
assert cacheDir != null && cacheDir.exists (); |
79 |
return cacheDir; |
80 |
return cacheDir; |
80 |
} |
81 |
} |
81 |
|
82 |
|
|
|
83 |
private File getLicenseDir() { |
84 |
return new File(getCatalogCache(), "licenses"); |
85 |
} |
86 |
private File getLicenseFile(String name) { |
87 |
return new File(getLicenseDir(), name); |
88 |
} |
89 |
|
90 |
public String getLicense(String name) { |
91 |
synchronized (name.intern()) { |
92 |
File file = getLicenseFile(name); |
93 |
if(!file.exists()) { |
94 |
return null; |
95 |
} |
96 |
try { |
97 |
FileInputStream fr = new FileInputStream(file); |
98 |
byte[] buffer = new byte[8192]; |
99 |
int n = 0; |
100 |
StringBuilder sb = new StringBuilder(); |
101 |
while ((n = fr.read(buffer)) != -1) { |
102 |
sb.append(new String(buffer, 0, n, "utf-8"));//NOI18N |
103 |
} |
104 |
return sb.toString(); |
105 |
} catch (IOException e) { |
106 |
err.log(Level.INFO, "Can`t read license from file " + file, e); |
107 |
return null; |
108 |
} |
109 |
} |
110 |
} |
111 |
|
112 |
public void storeLicense(String name, String content) { |
113 |
synchronized (name.intern()) { |
114 |
File file = getLicenseFile(name); |
115 |
if (file.exists() || content==null) { |
116 |
return; |
117 |
} |
118 |
|
119 |
FileOutputStream fw = null; |
120 |
try { |
121 |
fw = new FileOutputStream(file); |
122 |
fw.write(content.getBytes("utf-8")); //NOI18N |
123 |
} catch (IOException e) { |
124 |
err.log(Level.INFO, "Can`t write license " + name + " to " + file, e); |
125 |
} finally { |
126 |
if (fw != null) { |
127 |
try { |
128 |
fw.flush(); |
129 |
fw.close(); |
130 |
} catch (IOException e) { |
131 |
err.log(Level.INFO, "Can`t output stream for " + file, e); |
132 |
} |
133 |
} |
134 |
} |
135 |
} |
136 |
} |
137 |
|
82 |
private void initCacheDirectory () { |
138 |
private void initCacheDirectory () { |
83 |
assert cacheDir == null : "Do initCacheDirectory only once!"; |
139 |
assert cacheDir == null : "Do initCacheDirectory only once!"; |
84 |
String userDir = System.getProperty("netbeans.user"); // NOI18N |
140 |
String userDir = System.getProperty("netbeans.user"); // NOI18N |
Lines 89-94
Link Here
|
89 |
cacheDir = new File(dir, "catalogcache"); // NOI18N |
145 |
cacheDir = new File(dir, "catalogcache"); // NOI18N |
90 |
} |
146 |
} |
91 |
cacheDir.mkdirs(); |
147 |
cacheDir.mkdirs(); |
|
|
148 |
getLicenseDir().mkdirs(); |
92 |
err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ()); |
149 |
err.log (Level.FINE, "getCacheDirectory: " + cacheDir.getPath ()); |
93 |
return; |
150 |
return; |
94 |
} |
151 |
} |