jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1164542 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/api/ main/java/org/apache/jackrabbit/mk/blobs/ test/java/org/apache/jackrabbit/mk/blobs/
Date Fri, 02 Sep 2011 14:18:08 GMT
Author: thomasm
Date: Fri Sep  2 14:18:00 2011
New Revision: 1164542

URL: http://svn.apache.org/viewvc?rev=1164542&view=rev
Log:
Blob store: document and test that the stream is closed.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1164542&r1=1164541&r2=1164542&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Fri Sep  2 14:18:00 2011
@@ -298,9 +298,11 @@ public interface MicroKernel {
     /**
      * Stores the content of the given stream and returns an associated
      * identifier for later retrieval.
-     * <p/>
+     * <p>
      * If identical stream content has been stored previously, then the existing
      * identifier will be returned instead of storing a redundant copy.
+     * <p>
+     * The stream is closed by this method.
      *
      * @param in InputStream providing the blob content
      * @return blob identifier associated with the given content

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java?rev=1164542&r1=1164541&r2=1164542&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
Fri Sep  2 14:18:00 2011
@@ -138,6 +138,7 @@ public abstract class AbstractBlobStore 
             idStream.reset();
             convertBlobToId(new ByteArrayInputStream(idBlock), idStream, level + 1, totalLength);
         }
+        in.close();
     }
 
     protected abstract void storeBlock(byte[] blockId, int level, byte[] data) throws Exception;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java?rev=1164542&r1=1164541&r2=1164542&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
Fri Sep  2 14:18:00 2011
@@ -54,10 +54,9 @@ public class FileBlobStore extends Abstr
     }
 
     private File getFile(byte[] blockId) {
-        String id = StringUtils.convertBytesToHex(blockId) + ".dat";
-        File dir = new File(baseDir, id.substring(0, 2));
-        File f = new File(dir, id);
-        return f;
+        String id = StringUtils.convertBytesToHex(blockId);
+        String sub = id.substring(id.length() - 2);
+        return new File(new File(baseDir, sub), id + ".dat");
     }
 
     @Override

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java?rev=1164542&r1=1164541&r2=1164542&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
Fri Sep  2 14:18:00 2011
@@ -27,9 +27,11 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.sql.Connection;
 import java.util.ArrayList;
 import java.util.Random;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 /**
  * Tests the DbBlobStore implementation.
@@ -70,6 +72,20 @@ public class DbBlobStoreTest extends Tes
         assertEquals(0, store.getBlobLength(""));
     }
 
+    public void testCloseStream() throws Exception {
+        final AtomicBoolean closed = new AtomicBoolean();
+        InputStream in = new InputStream() {
+            public void close() {
+                closed.set(true);
+            }
+            public int read() throws IOException {
+                return -1;
+            }
+        };
+        store.writeBlob(in);
+        assertTrue(closed.get());
+    }
+
     public void testIllegalIdentifier() throws Exception {
         byte[] data = new byte[1];
         try {



Mime
View raw message