Przeglądaj źródła

added something to FileTK and patched ZipFileHandler

git-svn-id: http://repo.nplusc.de/svn/iZink@215 8b19561d-0d00-6744-8ac1-9afc8f58a8aa
masterX244 11 lat temu
rodzic
commit
69562539ef

+ 20 - 0
ToolKit/src/de/nplusc/izc/tools/IOtools/FileTK.java

@@ -6,6 +6,7 @@ package de.nplusc.izc.tools.IOtools;
  */
 import de.nplusc.izc.tools.baseTools.Tools;
 import java.io.*;
+import java.nio.CharBuffer;
 import java.nio.channels.FileChannel;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -583,4 +584,23 @@ public class FileTK
     }
     
     
+    public String fileAsString(String path) throws FileNotFoundException, IOException
+    {
+        return fileAsString(new File(path));
+    }
+    
+    public String fileAsString(File path) throws FileNotFoundException, IOException
+    {
+        String out="";
+            if(path.length()>Integer.MAX_VALUE)
+            {
+                throw new IOException(" File too large for specified operation");
+            }
+            FileReader fr = new FileReader(path);
+            CharBuffer c = CharBuffer.allocate((int)path.length());
+            fr.read(c);
+            c.rewind();
+            return c+"";
+    }
+    
 }

+ 26 - 7
ToolKit/src/de/nplusc/izc/tools/IOtools/ZipFileHandler.java

@@ -9,6 +9,7 @@ package de.nplusc.izc.tools.IOtools;
  * @author LH
  */
 import de.nplusc.izc.tools.baseTools.Tools;
+import java.awt.EventQueue;
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -47,12 +48,20 @@ public class ZipFileHandler
      * @param outDir wohin gezippt werden soll
      * @param monitorBar fprs monitoring via GUI;kann auch null sein
      */
+    
     public void extractAllToDiskWithMonitoringProgressbar(String outDir, JProgressBar monitorBar)
     {
         if (monitorBar == null)
         {
             monitorBar = new JProgressBar();//Dummy-Bar um NPXe zu stoppen
         }
+        extractAllToDiskWithMonitoringProgressbarImpl(outDir, monitorBar);
+    }
+    
+    private int promlilleDone=0;
+    private void extractAllToDiskWithMonitoringProgressbarImpl(String outDir, final JProgressBar monitorBar)
+    {
+
         ArrayList<ZipEntry> data = new ArrayList<>();
         Enumeration<ZipEntry> tmp = (Enumeration<ZipEntry>) zipFile.entries();
         while (tmp.hasMoreElements())
@@ -61,7 +70,7 @@ public class ZipFileHandler
         }
         long completeSize = 0;
         long bytesRead = 0;
-        int PromlilleDone = 0;
+        //int PromlilleDone = 0;
         for (ZipEntry entry : data)
         {
             completeSize += entry.getSize();
@@ -118,16 +127,26 @@ public class ZipFileHandler
                     bytesRead += chunkSize;
                     Tools.DebugHelperPrint(bytesRead+"", true, "Toolkit.enableFinerDebug");
                     bytesSinceLastPbarUpdate += chunkSize;
-                    int oldPbarVal = monitorBar.getValue();
-                    PromlilleDone = (int) (((float) bytesRead / (float) completeSize) * (float) 1000);
-                    if (PromlilleDone > oldPbarVal && bytesSinceLastPbarUpdate > 100000)//maximales update alle 100 kb
+                    Tools.DebugHelperPrint(bytesSinceLastPbarUpdate+"", true, "Toolkit.enableFinerDebug");
+                    //int oldPbarVal = ;
+                    promlilleDone = (int) (((float) bytesRead / (float) completeSize) * (float) 1000);
+                    if (bytesSinceLastPbarUpdate > 100000)//maximales update alle 100 kb
                     {
-                        Tools.DebugHelperPrint(PromlilleDone+"", true, "Toolkit.enableCoreDebug");
-                        monitorBar.setValue(PromlilleDone);
+                        Tools.DebugHelperPrint(promlilleDone+"", true, "Toolkit.enableCoreDebug");
+                        EventQueue.invokeLater(new 
+                        Runnable()
+                        {
+                            public void run()
+                            {
+                                if(promlilleDone > monitorBar.getValue())
+                                monitorBar.setValue(promlilleDone);
+                            }
+                        });
+                        
                         bytesSinceLastPbarUpdate = 0;//Zähler resetten
                     }
                 }
-                monitorBar.setValue(PromlilleDone);//am ende jeder datei auch aktulisieren
+                monitorBar.setValue(promlilleDone);//am ende jeder datei auch aktulisieren
                 bytesSinceLastPbarUpdate = 0;//Zähler resetten
                 bis.close(); //close BufferedInputStream
                 fos.close();

+ 8 - 2
ToolKit/src/de/nplusc/izc/tools/IOtools/iZformats/IZImageGenerated.java

@@ -259,8 +259,14 @@ public class IZImageGenerated
         zos.closeEntry();
         zos.close();
         ZipFile destination = new ZipFile(targetFilePath);
-        
-        statusdetail.setText("Done!");
+        if(status!=null)
+        {
+            status.setValue(status.getValue());
+        }
+        if(statusdetail!=null)
+        {
+            statusdetail.setText("Done!");
+        }
         return new IZImageGenerated(destination);
         
     }