00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 package org.openmobileis.bundle.update.terminal;
00027
00028 import java.io.BufferedOutputStream;
00029 import java.io.File;
00030 import java.io.FileOutputStream;
00031 import java.io.IOException;
00032 import java.io.InputStream;
00033 import java.util.Enumeration;
00034 import java.util.jar.JarEntry;
00035 import java.util.jar.JarFile;
00036
00041 public final class UpdateJarOpenMisRestarter {
00042
00046 public UpdateJarOpenMisRestarter() {
00047 }
00048
00049 public void updateApplication() {
00050 try {
00051 String path = System.getProperty("user.dir") + File.separator + "temp/"+ApplicationUpdateJarUtil.APPLICATION_JAR_FILENAME;
00052 File file = new File(path);
00053 if (file.exists()) {
00054
00055
00056
00057
00058
00059
00060 this.unzipInstallJar();
00061 }
00062
00063 } catch (Throwable ex){
00064
00065 }
00066 }
00067
00068 private void unzipInstallJar() throws IOException {
00069 String basepath = System.getProperty("user.dir") + File.separator;
00070 String path = basepath + "temp/" + ApplicationUpdateJarUtil.APPLICATION_JAR_FILENAME;
00071 File file = new File(path);
00072 if (file.exists()) {
00073 JarFile jarFile = new JarFile(path);
00074 try {
00075 for (Enumeration e = jarFile.entries(); e.hasMoreElements();) {
00076 JarEntry jarEntry = (JarEntry) e.nextElement();
00077 String completeName = jarEntry.getName();
00078
00079 if (jarEntry.isDirectory()) {
00080 File dirToCreate = new File(basepath + completeName);
00081 if (!dirToCreate.exists()) {
00082 dirToCreate.mkdirs();
00083 }
00084 continue;
00085 }
00086 int index = completeName.lastIndexOf("/");
00087 if (index != -1) {
00088 File repToCreate = new File(basepath + completeName.substring(0, index));
00089 if (!repToCreate.exists()) {
00090 repToCreate.mkdirs();
00091 }
00092 }
00093 FileOutputStream stream = new FileOutputStream(basepath + completeName);
00094 BufferedOutputStream bos = null;
00095 InputStream in = jarFile.getInputStream(jarEntry);
00096 try {
00097 int read_bytes = 0;
00098 byte[] buffer = new byte[4096];
00099 bos = new BufferedOutputStream(stream, buffer.length);
00100
00101 while ((read_bytes = in.read(buffer, 0, buffer.length)) != -1) {
00102 bos.write(buffer, 0, read_bytes);
00103 }
00104
00105 } finally {
00106 if (bos != null) {
00107 bos.flush();
00108 bos.close();
00109 stream.close();
00110 }
00111 in.close();
00112 }
00113 }
00114 } finally {
00115 if (jarFile != null) {
00116 try {
00117 jarFile.close();
00118 } catch (IOException ioe) {
00119 }
00120 }
00121 }
00122 }
00123 }
00124 }