[Jiemamy-notify:1440] commit [2669] ファイル保存まわりのストリームを整備。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 2月 14日 (土) 11:21:18 JST


Revision: 2669
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2669
Author:   daisuke_m
Date:     2009-02-14 11:21:18 +0900 (Sat, 14 Feb 2009)

Log Message:
-----------
ファイル保存まわりのストリームを整備。

Modified Paths:
--------------
    vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java
    vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java


-------------- next part --------------
Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java
===================================================================
--- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java	2009-02-14 02:15:06 UTC (rev 2668)
+++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/DiagramEditor.java	2009-02-14 02:21:18 UTC (rev 2669)
@@ -20,8 +20,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.EventObject;
@@ -193,12 +191,10 @@
 		ByteArrayInputStream in = null;
 		try {
 			out = new ByteArrayOutputStream();
-			
-			IFile file = ((IFileEditorInput) getEditorInput()).getFile();
 			jiemamy.getSerializer().serialize(rootModel, out);
 			
 			in = new ByteArrayInputStream(out.toByteArray());
-			
+			IFile file = ((IFileEditorInput) getEditorInput()).getFile();
 			file.setContents(in, true, true, monitor);
 			getCommandStack().markSaveLocation();
 		} catch (Exception e) {
@@ -230,19 +226,19 @@
 						
 							@Override
 							public void execute(IProgressMonitor monitor) {
+								ByteArrayOutputStream out = null;
+								ByteArrayInputStream in = null;
 								try {
-									PipedInputStream in = new PipedInputStream();
-									PipedOutputStream out = new PipedOutputStream(in);
-									
+									out = new ByteArrayOutputStream();
 									jiemamy.getSerializer().serialize(rootModel, out);
 									
-									out.close();
-									
+									in = new ByteArrayInputStream(out.toByteArray());
 									file.create(in, true, monitor);
-									
-									in.close();
 								} catch (Exception e) {
 									ExceptionHandler.handleException(e);
+								} finally {
+									IOUtils.closeQuietly(in);
+									IOUtils.closeQuietly(out);
 								}
 							}
 						});

Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java
===================================================================
--- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java	2009-02-14 02:15:06 UTC (rev 2668)
+++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/MultiDiagramEditor.java	2009-02-14 02:21:18 UTC (rev 2669)
@@ -18,11 +18,12 @@
  */
 package org.jiemamy.eclipse.editor;
 
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.SerializationException;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResourceChangeEvent;
@@ -90,24 +91,24 @@
 	 */
 	@Override
 	public void doSave(IProgressMonitor monitor) {
+		ByteArrayOutputStream out = null;
+		ByteArrayInputStream in = null;
 		try {
-			PipedInputStream in = new PipedInputStream();
-			PipedOutputStream out = new PipedOutputStream(in);
-			
+			out = new ByteArrayOutputStream();
 			jiemamy.getSerializer().serialize(rootModel, out);
 			
-			out.close();
-			
+			in = new ByteArrayInputStream(out.toByteArray());
 			IFile file = ((IFileEditorInput) getEditorInput()).getFile();
 			file.setContents(in, true, true, monitor);
 			
-			in.close();
-			
 			for (DiagramEditor2 editor : editors) {
 				editor.doSave(monitor);
 			}
 		} catch (Exception e) {
 			ExceptionHandler.handleException(e);
+		} finally {
+			IOUtils.closeQuietly(in);
+			IOUtils.closeQuietly(out);
 		}
 	}
 	
@@ -132,19 +133,19 @@
 						
 							@Override
 							public void execute(IProgressMonitor monitor) {
+								ByteArrayOutputStream out = null;
+								ByteArrayInputStream in = null;
 								try {
-									PipedInputStream in = new PipedInputStream();
-									PipedOutputStream out = new PipedOutputStream(in);
-									
+									out = new ByteArrayOutputStream();
 									jiemamy.getSerializer().serialize(rootModel, out);
 									
-									out.close();
-									
+									in = new ByteArrayInputStream(out.toByteArray());
 									file.create(in, true, monitor);
-									
-									in.close();
 								} catch (Exception e) {
 									ExceptionHandler.handleException(e);
+								} finally {
+									IOUtils.closeQuietly(in);
+									IOUtils.closeQuietly(out);
 								}
 							}
 						});



Jiemamy-notify メーリングリストの案内
Back to archive index