Author: tchemit Date: 2008-01-24 00:49:15 +0000 (Thu, 24 Jan 2008) New Revision: 478 Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/DownloadAction.java Log: action presque termin?\195?\169e Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/DownloadAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/DownloadAction.java 2008-01-24 00:36:05 UTC (rev 477) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/application/DownloadAction.java 2008-01-24 00:49:15 UTC (rev 478) @@ -18,6 +18,8 @@ * ##% */ package fr.cemagref.simexplorer.is.ui.swing.action.application; +import com.healthmarketscience.rmiio.RemoteInputStream; +import com.healthmarketscience.rmiio.RemoteInputStreamClient; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; import fr.cemagref.simexplorer.is.entities.metadata.Version; import fr.cemagref.simexplorer.is.service.StorageService; @@ -29,7 +31,11 @@ import javax.swing.JTree; import java.awt.event.ActionEvent; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; import java.text.MessageFormat; /** @@ -57,6 +63,7 @@ LoggableElement element; String uuid; Version version; + private static final int BUFFER_SIZE = 8 * 1024; public DownloadAction(String name) { super(name, null); @@ -92,9 +99,32 @@ @Override protected void doAction(ActionEvent e) throws Exception { super.doAction(e); - //StorageService service = getStorageService(((DetailTabModel) getModel()).isRemote()); - //TODO Where to save ??? - + StorageService service = getStorageService(((DetailTabModel) getModel()).isRemote()); + RemoteInputStream ris = service.retrieveData(getContext().getToken(), uuid, version.toString(), "_xml"); + if (ris == null) { + // todo log error + log.warn("could not get incoming data for " + uuid); + return; + } + InputStream stream = RemoteInputStreamClient.wrap(ris); + FileOutputStream fos = new FileOutputStream(file); + BufferedInputStream bis = new BufferedInputStream(stream); + BufferedOutputStream bos = new BufferedOutputStream(fos); + try { + byte[] buffer = new byte[BUFFER_SIZE]; + while (bis.read(buffer, 0, BUFFER_SIZE) != -1) { + bos.write(buffer); + bos.flush(); + } + } finally { + if (bis != null) { + bis.close(); + } + if (bos != null) { + bos.flush(); + bos.close(); + } + } } @Override @@ -104,7 +134,7 @@ node = null; file = null; element = null; - version=null; - uuid=null; + version = null; + uuid = null; } } \ No newline at end of file