From: Richard Millet Date: Mon, 6 Dec 2010 06:09:57 +0000 (+0000) Subject: CSPACE-3245: More changes to deal with remote streaming issues related to large files. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=1eae0a9f88c90acef48240c79087655fdaf3310e;p=tmp%2Fjakarta-migration.git CSPACE-3245: More changes to deal with remote streaming issues related to large files. --- diff --git a/services/authorization/service/.classpath b/services/authorization/service/.classpath index 505c7192a..425cd1620 100644 --- a/services/authorization/service/.classpath +++ b/services/authorization/service/.classpath @@ -4,7 +4,7 @@ + - diff --git a/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java b/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java index 832ef645e..2e93722a2 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/FileUtils.java @@ -6,9 +6,12 @@ import javax.servlet.http.HttpServletRequest; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.UUID; //import java.io.IOException; import java.io.File; +import java.io.InputStream; +import java.io.FileOutputStream; //import javax.servlet.ServletException; //import javax.servlet.http.HttpServlet; @@ -24,6 +27,30 @@ public class FileUtils { /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(FileUtils.class); + private static final String TMP_FILE_PREFIX = "cspace_blob_"; + + static public File createTmpFile(InputStream streamIn) { + File tmpFile = null; + String tmpDir = System.getProperty("java.io.tmpdir"); + tmpFile = new File(tmpDir, UUID.randomUUID().toString()); + + try { + FileOutputStream streamOut = new FileOutputStream(tmpFile); + int c; + while ((c = streamIn.read()) != -1) + { + streamOut.write(c); + } + + streamIn.close(); + streamOut.close(); + } catch (Exception e) { + logger.error(e.getMessage(), e); + } + + return tmpFile; + } + static public File createTmpFile(HttpServletRequest request) { File result = null; diff --git a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java index d72966005..21bf709f1 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/imaging/nuxeo/NuxeoImageUtils.java @@ -40,8 +40,9 @@ import java.util.Map; import org.nuxeo.runtime.api.Framework; import org.nuxeo.runtime.api.ServiceManager; import org.nuxeo.runtime.api.ServiceDescriptor; +import org.nuxeo.runtime.services.streaming.RemoteInputStream; -import org.nuxeo.common.utils.FileUtils; +//import org.nuxeo.common.utils.FileUtils; import org.nuxeo.ecm.platform.picture.api.adapters.PictureResourceAdapter; import org.nuxeo.ecm.platform.mimetype.MimetypeDetectionException; @@ -103,6 +104,7 @@ import org.slf4j.LoggerFactory; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentUtils; +import org.collectionspace.services.common.FileUtils; // TODO: Auto-generated Javadoc /** @@ -527,7 +529,9 @@ public class NuxeoImageUtils { pictureBlob = pictureBlobHolder.getBlob(); } - result = pictureBlob.getStream(); + InputStream remoteStream = pictureBlob.getStream(); + File tmpFile = FileUtils.createTmpFile(remoteStream); + result = new FileInputStream(tmpFile); } catch (Exception e) { logger.error(e.getMessage(), e); }