Changeset 30221

Show
Ignore:
Timestamp:
02/18/08 14:43:02 (9 months ago)
Author:
bstefanescu
Message:

fix for NXP-2072
Do not use jackrabbit input stream directly but wrap it into a custom stream to be able to reset the stream
to read it more than once.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.nuxeo.ecm.core/branches/1.4/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestLocalAPI.java

    r30097 r30221  
    2020package org.nuxeo.ecm.core.api; 
    2121 
     22import java.io.File; 
     23import java.lang.reflect.Array; 
    2224import java.net.URL; 
     25import java.util.Arrays; 
    2326import java.util.Calendar; 
    2427import java.util.List; 
     
    2730import org.nuxeo.ecm.core.api.impl.DocumentModelImpl; 
    2831import org.nuxeo.ecm.core.api.impl.VersionModelImpl; 
     32import org.nuxeo.ecm.core.api.impl.blob.ByteArrayBlob; 
     33import org.nuxeo.ecm.core.api.impl.blob.FileBlob; 
    2934import org.nuxeo.ecm.core.api.model.DocumentPart; 
    3035import org.nuxeo.ecm.core.api.model.Property; 
     
    328333    } 
    329334 
     335    public static byte[] createBytes(int size, byte val) { 
     336        byte[] bytes = new byte[size]; 
     337        Arrays.fill(bytes, val); 
     338        return bytes; 
     339    } 
     340 
     341    @SuppressWarnings("unchecked") 
     342    public void testLazyBlob() throws Exception { 
     343        DocumentModel root = getRootDocument(); 
     344        DocumentModel doc = new DocumentModelImpl(root.getPathAsString(), 
     345                "mydoc", "File"); 
     346 
     347        doc = remote.createDocument(doc); 
     348        byte[] bytes = createBytes(1024*1024, (byte)24); 
     349 
     350        Blob blob = new ByteArrayBlob(bytes); 
     351        doc.getPart("file").get("content").setValue(blob); 
     352        doc = remote.saveDocument(doc); 
     353 
     354        blob = (Blob)doc.getPart("file").get("content").getValue(); 
     355        assertTrue(Arrays.equals(bytes, blob.getByteArray())); 
     356 
     357        // test that reset works 
     358        blob.getStream().reset(); 
     359 
     360        blob = (Blob)doc.getPart("file").get("content").getValue(); 
     361        assertTrue(Arrays.equals(bytes, blob.getByteArray())); 
     362 
     363    } 
     364 
     365 
    330366    // TODO: fix and reenable SF 2007/05/23 
    331367    public void XXXtestProxy() throws Exception { 
  • org.nuxeo.ecm.core/branches/1.4/nuxeo-core-jcr-connector/src/main/java/org/nuxeo/ecm/core/repository/jcr/JCRBlob.java

    r28924 r30221  
    194194    } 
    195195 
    196     public InputStream getStream() throws IOException { 
     196    /** 
     197     * Get the underlying stream. Use getStream() instead 
     198     * @return 
     199     * @throws IOException 
     200     */ 
     201    public InputStream _getStream() throws IOException { 
    197202        try { 
    198203            return node.getProperty(DATA).getStream(); 
     
    202207            throw (IOException) (new IOException("could fetch stream").initCause(e)); 
    203208        } 
     209    } 
     210 
     211    /** 
     212     * Do not return the jackrabbit stream directly. Wrap it inside a JCRBlobInputStream to be able to 
     213     * reset the stream and read it more than once. 
     214     * <p> 
     215     * Fix for NXP-2072 
     216     * @see JCRBlobInputStream 
     217     * @see NXP-2072 
     218     */ 
     219    public InputStream getStream() throws IOException { 
     220        return new JCRBlobInputStream(this); 
    204221    } 
    205222