Changeset 380
- Timestamp:
- 07/25/10 12:06:34 (2 years ago)
- Files:
-
- kahina/trunk/src/org/kahina/core/KahinaInstance.java (modified) (6 diffs)
- kahina/trunk/src/org/kahina/core/data/DataManager.java (modified) (1 diff)
- kahina/trunk/src/org/kahina/core/util/FileUtilities.java (modified) (4 diffs)
- kahina/trunk/src/org/kahina/tralesld/bridge/TraleSLDBridge.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
kahina/trunk/src/org/kahina/core/KahinaInstance.java
r379 r380 5 5 import java.io.FileOutputStream; 6 6 import java.io.IOException; 7 import java.io.ObjectInputStream; 7 8 import java.io.ObjectOutputStream; 8 9 import java.util.Set; 10 import java.util.zip.ZipException; 11 import java.util.zip.ZipFile; 9 12 10 13 import javax.swing.JOptionPane; … … 131 134 private void loadSession(File file) 132 135 { 133 // TODO Auto-generated method stub 134 136 ZipFile zipFile = null; 137 try 138 { 139 zipFile = new ZipFile(file); 140 ObjectInputStream in = new ObjectInputStream(zipFile.getInputStream(zipFile.getEntry("state"))); 141 state = castToStateType(in.readObject()); 142 in.close(); 143 File directory = FileUtilities.createTemporaryDirectory(); 144 FileUtilities.unzipToDirectory(zipFile, directory, "steps/"); 145 // TODO load steps into magazine 146 } catch (Exception e) 147 { 148 gui.showMessageDialog(SwingUtilities.visualError("Session could not be loaded due to the following problem: ", e), "Error", JOptionPane.ERROR_MESSAGE); 149 return; 150 } finally 151 { 152 if (zipFile != null) 153 { 154 try 155 { 156 zipFile.close(); 157 } catch (IOException e) 158 { 159 gui.showMessageDialog(SwingUtilities.visualError("Session could not be loaded due to the following problem: ", e), "Error", JOptionPane.ERROR_MESSAGE); 160 } 161 } 162 } 163 } 164 165 @SuppressWarnings("unchecked") 166 private S castToStateType(Object object) 167 { 168 return (S) object; 135 169 } 136 170 … … 143 177 } catch (IOException e) 144 178 { 145 gui.showMessageDialog(SwingUtilities.visualError("S tatecould not be saved due to the following problem:", e), "Error", JOptionPane.ERROR_MESSAGE);179 gui.showMessageDialog(SwingUtilities.visualError("Session could not be saved due to the following problem:", e), "Error", JOptionPane.ERROR_MESSAGE); 146 180 return; 147 181 } … … 157 191 if (!stepFolder.mkdir()) 158 192 { 159 gui.showMessageDialog("Failed to create directory " + directory + ". S tatenot saved.", "Error", JOptionPane.ERROR_MESSAGE);193 gui.showMessageDialog("Failed to create directory " + directory + ". Session not saved.", "Error", JOptionPane.ERROR_MESSAGE); 160 194 return; 161 195 } 162 196 DataManager dm = KahinaRunner.getDataManager(); 163 ProgressMonitorWrapper monitor = gui.createProgressMonitorWrapper("Saving s tate", null, 0, dm.persistSteps() * 2 + 2);197 ProgressMonitorWrapper monitor = gui.createProgressMonitorWrapper("Saving session", null, 0, dm.persistSteps() * 2 + 2); 164 198 ObjectOutputStream out = null; 165 199 try … … 181 215 { 182 216 monitor.close(); 183 gui.showMessageDialog(SwingUtilities.visualError("S tatecould not be saved due to the following problem: ", e), "Error", JOptionPane.ERROR_MESSAGE);217 gui.showMessageDialog(SwingUtilities.visualError("Session could not be saved due to the following problem: ", e), "Error", JOptionPane.ERROR_MESSAGE); 184 218 } finally 185 219 { … … 191 225 } catch (IOException e) 192 226 { 193 gui.showMessageDialog(SwingUtilities.visualError("S tatecould not be saved due to the following problem: ", e), "Error", JOptionPane.ERROR_MESSAGE);227 gui.showMessageDialog(SwingUtilities.visualError("Session could not be saved due to the following problem: ", e), "Error", JOptionPane.ERROR_MESSAGE); 194 228 } 195 229 } kahina/trunk/src/org/kahina/core/data/DataManager.java
r375 r380 159 159 // do nothing 160 160 } 161 162 public void load(File directory) 163 { 164 throw new UnsupportedOperationException("This data manager does not support persistence."); 165 } 161 166 } kahina/trunk/src/org/kahina/core/util/FileUtilities.java
r376 r380 9 9 import java.io.InputStream; 10 10 import java.io.OutputStream; 11 import java.util.Enumeration; 11 12 import java.util.zip.ZipEntry; 13 import java.util.zip.ZipFile; 12 14 import java.util.zip.ZipOutputStream; 13 15 … … 33 35 out.close(); 34 36 } 35 } // Java is absurd.37 } 36 38 } 37 39 38 private static void copy(File file, OutputStream out) throws IOException40 private static void copy(File sourcee, OutputStream out) throws IOException 39 41 { 40 InputStream in = new BufferedInputStream(new FileInputStream(file)); 41 int length; 42 byte[] buffer = new byte[4096]; 42 InputStream in = new BufferedInputStream(new FileInputStream(sourcee)); 43 43 try 44 44 { 45 while ((length = in.read(buffer)) > 0) 46 { 47 out.write(buffer, 0, length); 48 } 45 copy(in, out); 49 46 } catch (IOException e) 50 47 { … … 53 50 { 54 51 in.close(); 52 } 53 } 54 55 private static void copy(InputStream in, File destination) throws IOException 56 { 57 OutputStream out = new BufferedOutputStream(new FileOutputStream(destination)); 58 try 59 { 60 copy(in, out); 61 } catch (IOException e) 62 { 63 throw e; 64 } finally 65 { 66 out.close(); 67 } 68 } 69 70 private static void copy(InputStream in, OutputStream out) throws IOException 71 { 72 int length; 73 byte[] buffer = new byte[4096]; 74 while ((length = in.read(buffer)) > 0) 75 { 76 out.write(buffer, 0, length); 55 77 } 56 78 } … … 116 138 } 117 139 140 /** 141 * Unzips zip entries whose names start with the given prefix to a given 142 * directory. At the moment, this supports only flat structures without 143 * further subdirectories. 144 * 145 * @param zipFile 146 * @param directory 147 * @param prefix 148 * @throws IOException 149 */ 150 public static void unzipToDirectory(ZipFile zipFile, File directory, String prefix) throws IOException 151 { 152 int length = prefix.length(); 153 Enumeration<? extends ZipEntry> entries = zipFile.entries(); 154 while (entries.hasMoreElements()) 155 { 156 ZipEntry entry = entries.nextElement(); 157 String name = entry.getName(); 158 if (name.startsWith(prefix)) 159 { 160 File file = new File(directory, name.substring(length)); 161 InputStream in = null; 162 try 163 { 164 in = zipFile.getInputStream(entry); 165 copy(in, file); 166 } catch (IOException e) 167 { 168 throw e; 169 } finally 170 { 171 if (in != null) 172 { 173 in.close(); 174 } 175 } 176 } 177 } 178 } 179 118 180 } kahina/trunk/src/org/kahina/tralesld/bridge/TraleSLDBridge.java
r370 r380 50 50 private TraleSLDFSPacker packer; 51 51 52 private int lastStepIDWithFreshPacker = 0;53 54 52 private Sharer<TraleSLDVariableBinding> bindingSharer; 55 56 private int lastStepIDWithFreshSharer = 0;57 53 58 54 public TraleSLDBridge(TraleSLDState state) … … 332 328 private TraleSLDFS createFSObject(String grisuMessage, int stepID) 333 329 { 334 if (KahinaRunner.getDataHandlingMethod() == KahinaDataHandlingMethod.MAGAZINE)330 /*if (KahinaRunner.getDataHandlingMethod() == KahinaDataHandlingMethod.MAGAZINE) 335 331 { 336 332 // YUCK! … … 340 336 lastStepIDWithFreshPacker = stepID; 341 337 } 342 } 338 }*/ 343 339 return packer.pack(grisuMessage); 344 340 } … … 346 342 private TraleSLDVariableBinding createBindingObject(TraleSLDVariableBinding traleSLDVariableBinding, int stepID) 347 343 { 348 if (KahinaRunner.getDataHandlingMethod() == KahinaDataHandlingMethod.MAGAZINE)344 /*if (KahinaRunner.getDataHandlingMethod() == KahinaDataHandlingMethod.MAGAZINE) 349 345 { 350 346 if (stepID - lastStepIDWithFreshSharer >= 1000) … … 353 349 lastStepIDWithFreshSharer = stepID; 354 350 } 355 } 351 }*/ 356 352 return bindingSharer.share(traleSLDVariableBinding); 357 353 }
