jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1173068 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs: AbstractBlobStore.java DbBlobStore.java FileBlobStore.java MemoryBlobStore.java
Date Tue, 20 Sep 2011 10:27:30 GMT
Author: thomasm
Date: Tue Sep 20 10:27:30 2011
New Revision: 1173068

URL: http://svn.apache.org/viewvc?rev=1173068&view=rev
Log:
Simplify the blob store a bit, and use the file system abstraction.

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/DbBlobStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStore.java

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=1173068&r1=1173067&r2=1173068&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
Tue Sep 20 10:27:30 2011
@@ -247,8 +247,6 @@ public abstract class AbstractBlobStore 
         }
     }
 
-    public abstract void clear();
-
     public static class Data implements Cache.Value {
 
         final byte[] data;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/DbBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/DbBlobStore.java?rev=1173068&r1=1173067&r2=1173068&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/DbBlobStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/DbBlobStore.java
Tue Sep 20 10:27:30 2011
@@ -118,9 +118,4 @@ public class DbBlobStore extends Abstrac
         }
     }
 
-    @Override
-    public void clear() {
-        // TODO currently not cleared
-    }
-
 }

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=1173068&r1=1173067&r2=1173068&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
Tue Sep 20 10:27:30 2011
@@ -16,12 +16,13 @@
  */
 package org.apache.jackrabbit.mk.blobs;
 
+import org.apache.jackrabbit.mk.fs.FilePath;
+import org.apache.jackrabbit.mk.fs.FileUtils;
+import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.StringUtils;
-import org.h2.util.IOUtils;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.IOException;
 
 /**
@@ -29,42 +30,42 @@ import java.io.IOException;
  */
 public class FileBlobStore extends AbstractBlobStore {
 
-    private final File baseDir;
+    private final FilePath baseDir;
 
-    public FileBlobStore(String dir) {
-        baseDir = new File(dir);
-        baseDir.mkdirs();
+    public FileBlobStore(String dir) throws IOException {
+        baseDir = FilePath.get(dir);
+        FileUtils.createDirectories(dir);
     }
 
     @Override
     protected synchronized void storeBlock(byte[] blockId, int level, byte[] data) throws
IOException {
-        File f = getFile(blockId);
+        FilePath f = getFile(blockId);
         if (f.exists()) {
             return;
         }
-        File parent = f.getParentFile();
+        FilePath parent = f.getParent();
         if (!parent.exists()) {
-            parent.mkdirs();
+            FileUtils.createDirectories(parent.toString());
         }
-        File temp = new File(parent, f.getName() + ".temp");
-        FileOutputStream out = new FileOutputStream(temp);
+        FilePath temp = parent.resolve(f.getName() + ".temp");
+        OutputStream out = temp.newOutputStream(false);
         out.write(data);
         out.close();
-        temp.renameTo(f);
+        temp.moveTo(f);
     }
 
-    private File getFile(byte[] blockId) {
+    private FilePath getFile(byte[] blockId) {
         String id = StringUtils.convertBytesToHex(blockId);
         String sub = id.substring(id.length() - 2);
-        return new File(new File(baseDir, sub), id + ".dat");
+        return baseDir.resolve(sub).resolve(id + ".dat");
     }
 
     @Override
     protected byte[] readBlockFromBackend(byte[] blockId) throws IOException {
-        File f = getFile(blockId);
-        int length = (int) f.length();
+        FilePath f = getFile(blockId);
+        int length = (int) f.size();
         byte[] data = new byte[length];
-        FileInputStream in = new FileInputStream(f);
+        InputStream in = f.newInputStream();
         try {
             IOUtils.readFully(in, data, 0, length);
         } finally {
@@ -73,9 +74,4 @@ public class FileBlobStore extends Abstr
         return data;
     }
 
-    @Override
-    public void clear() {
-        // TODO currently not cleared
-    }
-
 }
\ No newline at end of file

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStore.java?rev=1173068&r1=1173067&r2=1173068&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/MemoryBlobStore.java
Tue Sep 20 10:27:30 2011
@@ -41,9 +41,4 @@ public class MemoryBlobStore extends Abs
         map.put(getId(blockId), data);
     }
 
-    @Override
-    public synchronized void clear() {
-        map.clear();
-    }
-
 }



Mime
View raw message