1 19 20 package org.netbeans.modules.derby; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 import java.util.zip.ZipEntry ; 27 import java.util.zip.ZipInputStream ; 28 import org.openide.DialogDisplayer; 29 import org.openide.NotifyDescriptor; 30 import org.openide.filesystems.FileLock; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 import org.openide.util.Mutex; 34 35 39 public class Util { 40 41 private Util() { 42 } 43 44 public static boolean hasInstallLocation() { 45 return getCheckedLocation() != null; 46 } 47 48 private static File getCheckedLocation() { 49 File location = new File (DerbyOptions.getDefault().getLocation()); 50 if (location.isAbsolute() && location.isDirectory() && location.exists()) { 51 return location; 52 } 53 return null; 54 } 55 56 public static File getDerbyFile(String relPath) { 57 File location = getCheckedLocation(); 58 if (location != null) { 59 return new File (location, relPath); 60 } 61 return null; 62 } 63 64 public static void showInformation(final String msg){ 65 Mutex.EVENT.readAccess(new Runnable () { 66 public void run() { 67 NotifyDescriptor d = new NotifyDescriptor.Message(msg, NotifyDescriptor.INFORMATION_MESSAGE); 68 DialogDisplayer.getDefault().notify(d); 69 } 70 }); 71 } 72 73 public static void extractZip(File source, FileObject target) throws IOException { 74 FileInputStream is = new FileInputStream (source); 75 try { 76 ZipInputStream zis = new ZipInputStream (is); 77 ZipEntry ze; 78 79 while ((ze = zis.getNextEntry()) != null) { 80 String name = ze.getName(); 81 82 if (ze.isDirectory()) { 84 FileUtil.createFolder(target, name); 85 continue; 86 } 87 88 FileObject fd = FileUtil.createData(target, name); 90 FileLock lock = fd.lock(); 91 try { 92 OutputStream os = fd.getOutputStream(lock); 93 try { 94 FileUtil.copy(zis, os); 95 } finally { 96 os.close(); 97 } 98 } finally { 99 lock.releaseLock(); 100 } 101 } 102 } finally { 103 is.close(); 104 } 105 } 106 } 107 | Popular Tags |