2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
41 import java.io.FileInputStream;
42 import java.io.FileOutputStream;
43 import java.io.IOException;
44 import java.io.InputStream;
45 import java.io.OutputStream;
46 import java.io.Reader;
47 import java.io.Writer;
49 import java.util.jar.JarEntry;
50 import java.util.jar.JarInputStream;
52 public class ExtractJar {
54 public static int bufferSize = 8192;
55 public static String JARFILE = "raptor_upgrade.jar";
57 public static void main(String[] args) throws Exception {
58 if (args.length > 0 && args[0] != null && args[0].length() > 0)
59 extractFilesFromJar(args[0]);
61 System.out.println("Current Directory is taken as webapp path");
62 String currentDir = new File(".").getAbsolutePath();
63 extractFilesFromJar(currentDir);
67 public static void readJar(File jarFile) throws Exception {
68 JarInputStream in = new JarInputStream(new FileInputStream(jarFile));
70 while ((je = in.getNextJarEntry()) != null) {
71 if (je.isDirectory() == false) {
72 if (je.getName().startsWith("att/raptor/config/")) {
73 // while((je=in.getNextJarEntry( ))!=null) {
74 System.out.println(je.getName() + " " + je.getTime());
83 public static void extractFilesFromJar(String directory) throws IOException {
84 // JarFile jar = new JarFile(jarFile);
85 Class clazz = ExtractJar.class;
86 String classContainer = clazz.getProtectionDomain().getCodeSource().getLocation().toString();
87 // System.out.println("classContainer ---------> " + classContainer);
88 URL jarUrl = clazz.getProtectionDomain().getCodeSource().getLocation();
90 JarInputStream entryStream = new JarInputStream(jarUrl.openStream());
93 entry = entryStream.getNextJarEntry();
96 if (entry.getName().indexOf("jarutil") < 0) {
97 System.out.println(entry.getName());
98 File file = new File(directory, entry.getName());
99 if (entry.isDirectory()) {
103 // make directory (some jars don't list dirs)
104 File dir = new File(file.getParent());
110 FileOutputStream fout = new FileOutputStream(file);
111 copy(entryStream, fout);
115 if (entry.getTime() >= 0)
116 file.setLastModified(entry.getTime());
120 entryStream.closeEntry();
123 System.out.println("************************************************");
124 System.out.println("* *");
125 System.out.println("* *");
126 System.out.println("* RAPTOR SETUP COMPLETE. *");
127 System.out.println("* *");
128 System.out.println("* Thank you for upgrading. *");
129 System.out.println("* *");
130 System.out.println("************************************************");
133 public static void copy(InputStream in, OutputStream out, long byteCount) throws IOException {
134 byte buffer[] = new byte[bufferSize];
135 int len = bufferSize;
136 if (byteCount >= 0) {
137 while (byteCount > 0) {
138 if (byteCount < bufferSize)
139 len = in.read(buffer, 0, (int) byteCount);
141 len = in.read(buffer, 0, bufferSize);
146 out.write(buffer, 0, len);
150 len = in.read(buffer, 0, bufferSize);
153 out.write(buffer, 0, len);
158 /* ------------------------------------------------------------------- */
160 * Copy Reader to Writer for byteCount bytes or until EOF or exception.
162 public static void copy(Reader in, Writer out, long byteCount) throws IOException {
163 char buffer[] = new char[bufferSize];
164 int len = bufferSize;
165 if (byteCount >= 0) {
166 while (byteCount > 0) {
167 if (byteCount < bufferSize)
168 len = in.read(buffer, 0, (int) byteCount);
170 len = in.read(buffer, 0, bufferSize);
175 out.write(buffer, 0, len);
179 len = in.read(buffer, 0, bufferSize);
182 out.write(buffer, 0, len);
187 /* ------------------------------------------------------------------- */
189 * Copy Stream in to Stream out until EOF or exception.
191 public static void copy(InputStream in, OutputStream out) throws IOException {
195 // Deletes all files and subdirectories under dir.
196 // Returns true if all deletions were successful.
197 // If a deletion fails, the method stops attempting to delete and returns false.
198 public static boolean deleteDir(File dir) {
199 if (dir.isDirectory()) {
200 String[] children = dir.list();
201 for (int i = 0; i < children.length; i++) {
202 boolean success = deleteDir(new File(dir, children[i]));
209 // The directory is now empty so delete it