update dev300-m58
[ooovba.git] / scripting / workben / installer / ZipData.java
blobef22bd0e44062b53c3f289d8371c3c878b8d0656
1 package installer;
3 import java.io.*;
4 import java.util.*;
5 import java.util.zip.*;
6 import java.awt.*;
7 import java.awt.event.*;
8 import javax.swing.*;
10 public class ZipData
12 public ZipData(String file) {
15 public boolean extractEntry(String entry, String destination,
16 JLabel statusLabel) {
18 OutputStream out = null;
19 InputStream in = null;
21 System.out.println("Copying: " + entry);
22 System.out.println("To: " + destination);
24 if (statusLabel != null) {
25 statusLabel.setText("Copying " + entry);
28 String entryName;
29 if (entry.lastIndexOf("/") != -1) {
30 entryName = entry.substring(entry.lastIndexOf("/") + 1);
32 else {
33 entryName = entry;
36 String destName;
37 if (destination.lastIndexOf(File.separator) != -1) {
38 destName = destination.substring(destination.lastIndexOf(File.separator) + 1);
40 else {
41 destName = destination;
44 if (!destName.equals(entryName))
45 destination = destination.concat(entryName);
47 System.out.println("Unzipping " + entry + " to " + destination);
49 try {
50 out = new FileOutputStream(destination);
52 catch (IOException ioe) {
53 System.err.println("Error opening " + destination +
54 ": " + ioe.getMessage());
56 if (statusLabel != null)
57 statusLabel.setText("Error opening" + destination +
58 "see SFramework.log for more information");
60 return false;
63 if (entry.startsWith("/") == false)
64 entry = "/" + entry;
66 in = this.getClass().getResourceAsStream(entry);
67 if (in == null) {
68 System.err.println("File " + entry + " not found in jar file");
70 if (statusLabel != null)
71 statusLabel.setText("Failed extracting " + entry +
72 "see SFramework.log for more information");
74 return false;
77 try {
78 byte[] bytes = new byte[1024];
79 int len;
81 while ((len = in.read(bytes)) != -1)
82 out.write(bytes, 0, len);
84 catch (IOException ioe) {
85 System.err.println("Error writing " + destination + ": " +
86 ioe.getMessage());
88 if (statusLabel != null)
89 statusLabel.setText("Failed writing " + destination +
90 "see SFramework.log for more information");
91 return false;
93 finally {
94 try {
95 in.close();
96 out.close();
98 catch (IOException ioe) {
101 return true;