Files
libreoffice/scripting/workben/installer/ZipData.java

94 lines
2.5 KiB
Java
Raw Normal View History

2002-11-15 12:28:36 +00:00
package installer;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ZipData
{
public ZipData(String file) {
}
public boolean extractEntry(String entry, String destination,
JLabel statusLabel) {
OutputStream out = null;
InputStream in = null;
System.out.println("Copying: " + entry);
System.out.println("To: " + destination);
2002-11-22 10:34:36 +00:00
if (statusLabel != null) {
statusLabel.setText("Copying " + entry);
System.out.println("Copying " + entry);
}
if (entry.lastIndexOf("/") != -1) {
String name = entry.substring(entry.lastIndexOf("/") + 1);
destination = destination.concat(name);
}
else {
destination = destination.concat(entry);
}
System.out.println("Unzipping " + entry + " to " + destination);
try {
out = new FileOutputStream(destination);
2002-11-22 10:34:36 +00:00
}
catch (IOException ioe) {
System.err.println("Error opening " + destination +
": " + ioe.getMessage());
if (statusLabel != null)
statusLabel.setText("Error opening" + destination +
"see SFramework.log for more information");
return false;
}
if (entry.startsWith("/") == false)
entry = "/" + entry;
in = this.getClass().getResourceAsStream(entry);
if (in == null) {
System.err.println("File " + entry + " not found in jar file");
if (statusLabel != null)
statusLabel.setText("Failed extracting " + entry +
"see SFramework.log for more information");
return false;
}
try {
byte[] bytes = new byte[1024];
int len;
while ((len = in.read(bytes)) != -1)
out.write(bytes, 0, len);
}
catch (IOException ioe) {
System.err.println("Error writing " + destination + ": " +
ioe.getMessage());
if (statusLabel != null)
statusLabel.setText("Failed writing " + destination +
"see SFramework.log for more information");
return false;
}
finally {
try {
in.close();
out.close();
}
catch (IOException ioe) {
}
}
return true;
}
}