Author: cmailleux
Date: Mon Aug 27 17:50:51 2007
New Revision: 18273
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D18273&repname=
=3Djahia
Log:
Use Deffered from commons io for big files in jahia and make it usable thro=
ugh esi
Removed:
branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/apache/commons/io/
Modified:
branches/JAHIA-5-0-SP-BRANCH/core/project.xml
branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/manager/=
JahiaSlideUriManager.java
Modified: branches/JAHIA-5-0-SP-BRANCH/core/project.xml
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/project.xml&rev=3D18273&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/project.xml (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/project.xml Mon Aug 27 17:50:51 2007
@@ -1,4 +1,4 @@
-=C3=AF=C2=BB=C2=BF<?xml version=3D"1.0" encoding=3D"UTF-8"?>
+<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<!DOCTYPE project [
<!ENTITY % locator-entities SYSTEM "file:locator.ent"> %locator-entiti=
es;
]>
@@ -189,7 +189,7 @@
</dependency>
<dependency>
<id>commons-io</id>
- <version>1.0</version>
+ <version>1.3.1</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/ma=
nager/JahiaSlideUriManager.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/hibernate/manager/JahiaSlideUriManager.java=
&rev=3D18273&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/manager/=
JahiaSlideUriManager.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/hibernate/manager/=
JahiaSlideUriManager.java Mon Aug 27 17:50:51 2007
@@ -19,6 +19,9 @@
import org.apache.commons.collections.FastArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.io.output.DeferredFileOutputStream;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.FileCleaner;
import org.apache.slide.content.*;
import org.apache.slide.lock.NodeLock;
import org.apache.slide.security.NodePermission;
@@ -32,9 +35,7 @@
import org.jahia.services.cache.CacheService;
import org.springframework.orm.ObjectRetrievalFailureException;
=
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
@@ -438,20 +439,20 @@
}
try {
InputStream is =3D versionContent.getContent().getBinaryStream=
();
- ByteArrayOutputStream outputStream =3D new ByteArrayOutputStre=
am(128000);
- byte[] buffer =3D new byte[128000];
- while (true) {
- int amountRead =3D is.read(buffer);
- if (amountRead =3D=3D -1) {
- break;
- }
- outputStream.write(buffer, 0, amountRead);
- }
-
+ DeferredFileOutputStream dfos =3D
+ new DeferredFileOutputStream(1024 * 1024 * 10, File.cr=
eateTempFile("temp", "download"));
+ InputStream inputStream =3D new BufferedInputStream(new FileIn=
putStream(dfos.getFile()));
+ FileCleaner.track(dfos.getFile(), inputStream);
+ IOUtils.copy(is, dfos);
is.close();
- outputStream.close();
-
- revisionContent.setContent(outputStream.toByteArray());
+ dfos.close();
+ if (!dfos.isInMemory()) {
+ revisionContent.setContent(inputStream);
+ }
+ else {
+ revisionContent.setContent(dfos.getData());
+ inputStream.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
throw new RevisionNotFoundException(uri, revisionDescriptor.ge=
tRevisionNumber());
@@ -517,10 +518,24 @@
versionContent.setVersion(versionHistory);
versionContent.setVersionId(versionHistory.getVersionId());
try {
- versionContent.setContent(Hibernate.createBlob(revisionContent=
.streamContent()));
+ InputStream is =3D revisionContent.streamContent();
+ DeferredFileOutputStream dfos =3D
+ new DeferredFileOutputStream(1024 * 1024 * 10, File.cr=
eateTempFile("temp", "upload"));
+ InputStream inputStream =3D new BufferedInputStream(new FileIn=
putStream(dfos.getFile()));
+ FileCleaner.track(dfos.getFile(), inputStream);
+ IOUtils.copy(is, dfos);
+ is.close();
+ dfos.close();
+ if (!dfos.isInMemory()) {
+ versionContent.setContent(Hibernate.createBlob(inputStream=
));
+ }
+ else {
+ versionContent.setContent(Hibernate.createBlob(dfos.getDat=
a()));
+ inputStream.close();
+ }
+
} catch (IOException e) {
log.warn("Cannot stream content",e);
- versionContent.setContent(Hibernate.createBlob(revisionContent=
.getContentBytes()));
}
dao.update(versionContent);
}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list