chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1583765 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory: storedobj/impl/ types/
Date Tue, 01 Apr 2014 19:43:39 GMT
Author: jens
Date: Tue Apr  1 19:43:38 2014
New Revision: 1583765

URL: http://svn.apache.org/r1583765
Log:
InMemory: implement a document type to test big content streams acting as a fake (content
is discarded and generated randomly on read) [CMIS-777]

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DefaultTypeSystemCreator.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java?rev=1583765&r1=1583764&r2=1583765&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ContentStreamDataImpl.java
Tue Apr  1 19:43:38 2014
@@ -47,7 +47,7 @@ public class ContentStreamDataImpl imple
     private static long totalLength = 0L;
     private static long totalCalls = 0L;
 
-    private int fLength;
+    private long fLength;
 
     private String fMimeType;
 
@@ -62,16 +62,18 @@ public class ContentStreamDataImpl imple
     private long fStreamLimitLength;
 
     private final long sizeLimitKB;
+    
+    private final boolean doNotStoreContent;
 
     private static synchronized long getTotalLength() {
         return totalLength;
     }
 
-    private static synchronized void increaseTotalLength(int length) {
+    private static synchronized void increaseTotalLength(long length) {
         totalLength += length;
     }
 
-    private static synchronized void decreaseTotalLength(int length) {
+    private static synchronized void decreaseTotalLength(long length) {
         totalLength -= length;
     }
 
@@ -86,6 +88,13 @@ public class ContentStreamDataImpl imple
     public ContentStreamDataImpl(long maxAllowedContentSizeKB) {
         sizeLimitKB = maxAllowedContentSizeKB;
         fLength = 0;
+        doNotStoreContent = false;
+    }
+
+    public ContentStreamDataImpl(long maxAllowedContentSizeKB, boolean doNotStore) {
+        sizeLimitKB = maxAllowedContentSizeKB;
+        fLength = 0;
+        doNotStoreContent = doNotStore;
     }
 
     public void setContent(InputStream in) throws IOException {
@@ -99,7 +108,9 @@ public class ContentStreamDataImpl imple
             ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
             int len = in.read(buffer);
             while (len != -1) {
-                contentStream.write(buffer, 0, len);
+                if (!doNotStoreContent) {
+                    contentStream.write(buffer, 0, len);
+                }
                 fLength += len;
                 if (sizeLimitKB > 0 && fLength > sizeLimitKB * SIZE_KB) {
                     throw new CmisInvalidArgumentException("Content size exceeds max. allowed
size of " + sizeLimitKB
@@ -107,8 +118,10 @@ public class ContentStreamDataImpl imple
                 }
                 len = in.read(buffer);
             }
-            fContent = contentStream.toByteArray();
-            fLength = contentStream.size();
+            if (!doNotStoreContent) {
+                fContent = contentStream.toByteArray();
+                fLength = contentStream.size();
+            }
             contentStream.close();
             in.close();
         }
@@ -127,7 +140,9 @@ public class ContentStreamDataImpl imple
             ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
 
             // first read existing stream
-            contentStream.write(fContent);
+            if (!doNotStoreContent) {
+                contentStream.write(fContent);
+            }
             decreaseTotalLength(fLength);
 
             // then append new content
@@ -141,7 +156,9 @@ public class ContentStreamDataImpl imple
                 }
                 len = is.read(buffer);
             }
-            fContent = contentStream.toByteArray();
+            if (!doNotStoreContent) {
+                fContent = contentStream.toByteArray();
+            }
             fLength = contentStream.size();
             contentStream.close();
             is.close();
@@ -186,11 +203,15 @@ public class ContentStreamDataImpl imple
 
     @Override
     public InputStream getStream() {
+        if (doNotStoreContent) {
+            return new RandomInputStream(fLength);
+        }
+        
         if (null == fContent) {
             return null;
         } else if (fStreamLimitOffset <= 0 && fStreamLimitLength < 0) {
-            return new ByteArrayInputStream(fContent);
-        } else {
+                return new ByteArrayInputStream(fContent);
+        } else {            
             return new ByteArrayInputStream(fContent, (int) (fStreamLimitOffset < 0 ?
0 : fStreamLimitOffset),
                     (int) (fStreamLimitLength < 0 ? fLength : fStreamLimitLength));
         }
@@ -206,7 +227,7 @@ public class ContentStreamDataImpl imple
     }
 
     public ContentStream getCloneWithLimits(long offset, long length) {
-        ContentStreamDataImpl clone = new ContentStreamDataImpl(0);
+        ContentStreamDataImpl clone = new ContentStreamDataImpl(0, doNotStoreContent);
         clone.fFileName = fFileName;
         clone.fLength = fLength;
         clone.fContent = fContent;

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java?rev=1583765&r1=1583764&r2=1583765&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/storedobj/impl/ObjectStoreImpl.java
Tue Apr  1 19:43:38 2014
@@ -68,6 +68,7 @@ import org.apache.chemistry.opencmis.inm
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.Relationship;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
 import org.apache.chemistry.opencmis.inmemory.storedobj.api.VersionedDocument;
+import org.apache.chemistry.opencmis.inmemory.types.DefaultTypeSystemCreator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -1077,7 +1078,8 @@ public class ObjectStoreImpl implements 
             if (null == contentStream) {
                 newContent = null;
             } else {
-                newContent = new ContentStreamDataImpl(MAX_CONTENT_SIZE_KB == null ? 0 :
MAX_CONTENT_SIZE_KB);
+                boolean useFakeContentStore = so.getTypeId().equals(DefaultTypeSystemCreator.BIG_CONTENT_FAKE_TYPE);
+                newContent = new ContentStreamDataImpl(MAX_CONTENT_SIZE_KB == null ? 0 :
MAX_CONTENT_SIZE_KB, useFakeContentStore);
                 String fileName = contentStream.getFileName();
                 if (null == fileName || fileName.length() <= 0) {
                     fileName = so.getName(); // use name of document as fallback

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DefaultTypeSystemCreator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DefaultTypeSystemCreator.java?rev=1583765&r1=1583764&r2=1583765&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DefaultTypeSystemCreator.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/types/DefaultTypeSystemCreator.java
Tue Apr  1 19:43:38 2014
@@ -56,6 +56,7 @@ public class DefaultTypeSystemCreator im
     public static final String LEVEL1_TYPE = "DocumentLevel1";
     public static final String LEVEL2_TYPE = "DocumentLevel2";
     public static final String SECONDARY_TYPE_ID = "MySecondaryType";
+    public static final String BIG_CONTENT_FAKE_TYPE = "BigContentFakeType";
 
     /*
      * In the public interface of this class we return the singleton containing
@@ -401,6 +402,17 @@ public class DefaultTypeSystemCreator im
             polType.addPropertyDefinition(prop1);
             typesList.add(polType);
 
+            MutableTypeDefinition cmisTypeFake;
+            cmisTypeFake = typeFactory.createDocumentTypeDefinition(CmisVersion.CMIS_1_1,
DocumentTypeCreationHelper
+                    .getCmisDocumentType().getId());
+            cmisTypeFake.setId(BIG_CONTENT_FAKE_TYPE);
+            cmisTypeFake.setDisplayName("BigContentFakeType");
+            cmisTypeFake.setDescription("Builtin InMemory type definition for big content
streams. Content is "
+                    + "ignored and replaced by random bytes");
+            typesList.add(cmisTypeFake);
+
+            
+
             return typesList;
         } catch (Exception e) {
             throw new CmisRuntimeException("Error when creating built-in InMemory types.",
e);



Mime
View raw message