use of com.codename1.io.tar.TarInputStream in project CodenameOne by codenameone.
the class CodenameOneImplementation method installTar.
/**
* Installs a tar file from the build server into the file system storage so it can be used with respect for hierarchy
*/
public void installTar() throws IOException {
String p = Preferences.get("cn1$InstallKey", null);
String buildKey = Display.getInstance().getProperty("build_key", null);
if (p == null || !p.equals(buildKey)) {
FileSystemStorage fs = FileSystemStorage.getInstance();
String tardir = fs.getAppHomePath() + "cn1html/";
fs.mkdir(tardir);
TarInputStream is = new TarInputStream(Display.getInstance().getResourceAsStream(getClass(), "/html.tar"));
TarEntry t = is.getNextEntry();
byte[] data = new byte[8192];
while (t != null) {
String name = t.getName();
if (t.isDirectory()) {
fs.mkdir(tardir + name);
} else {
String path = tardir + name;
String dir = path.substring(0, path.lastIndexOf('/'));
if (!fs.exists(dir)) {
mkdirs(fs, dir);
}
OutputStream os = fs.openOutputStream(tardir + name);
int count;
while ((count = is.read(data)) != -1) {
os.write(data, 0, count);
}
os.close();
}
t = is.getNextEntry();
}
Util.cleanup(is);
Preferences.set("cn1$InstallKey", buildKey);
}
}
Aggregations