jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1304484 - in /jackrabbit/oak/trunk/oak-mk/src: main/java/org/apache/jackrabbit/mk/blobs/ main/java/org/apache/jackrabbit/mk/fs/ main/java/org/apache/jackrabbit/mk/persistence/ test/java/org/apache/jackrabbit/mk/blobs/ test/java/org/apache/...
Date Fri, 23 Mar 2012 17:00:54 GMT
Author: stefan
Date: Fri Mar 23 17:00:53 2012
New Revision: 1304484

URL: http://svn.apache.org/viewvc?rev=1304484&view=rev
Log:
cleanup

Removed:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/fs/
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/fs/
Modified:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
    jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java?rev=1304484&r1=1304483&r2=1304484&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java
Fri Mar 23 17:00:53 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.mk.blobs;
 
-import org.apache.jackrabbit.mk.fs.FilePath;
 import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.Cache;
@@ -25,6 +24,8 @@ import org.apache.jackrabbit.mk.util.Str
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
@@ -106,11 +107,15 @@ public abstract class AbstractBlobStore 
 
     public String addBlob(String tempFilePath) {
         try {
-            FilePath file = FilePath.get(tempFilePath);
+            File file = new File(tempFilePath);
+            InputStream in = null;
             try {
-                InputStream in = file.newInputStream();
+                in = new FileInputStream(file);
                 return writeBlob(in);
             } finally {
+                if (in != null) {
+                    in.close();
+                }
                 file.delete();
             }
         } catch (Exception e) {

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java?rev=1304484&r1=1304483&r2=1304484&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/FileBlobStore.java
Fri Mar 23 17:00:53 2012
@@ -17,13 +17,14 @@
 package org.apache.jackrabbit.mk.blobs;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.security.DigestInputStream;
 import java.security.MessageDigest;
-import org.apache.jackrabbit.mk.fs.FilePath;
-import org.apache.jackrabbit.mk.fs.FileUtils;
 import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.StringUtils;
@@ -35,23 +36,23 @@ public class FileBlobStore extends Abstr
 
     private static final String OLD_SUFFIX = "_old";
 
-    private final FilePath baseDir;
+    private final File baseDir;
     private final byte[] buffer = new byte[16 * 1024];
     private boolean mark;
 
     public FileBlobStore(String dir) throws IOException {
-        baseDir = FilePath.get(dir);
-        FileUtils.createDirectories(dir);
+        baseDir = new File(dir);
+        baseDir.mkdirs();
     }
 
     @Override
     public String addBlob(String tempFilePath) {
         try {
-            FilePath file = FilePath.get(tempFilePath);
-            InputStream in = file.newInputStream();
+            File file = new File(tempFilePath);
+            InputStream in = new FileInputStream(file);
             MessageDigest messageDigest = MessageDigest.getInstance(HASH_ALGORITHM);
             DigestInputStream din = new DigestInputStream(in, messageDigest);
-            long length = file.size();
+            long length = file.length();
             try {
                 while (true) {
                     int len = din.read(buffer, 0, buffer.length);
@@ -67,15 +68,15 @@ public class FileBlobStore extends Abstr
             IOUtils.writeVarInt(idStream, 0);
             IOUtils.writeVarLong(idStream, length);
             byte[] digest = messageDigest.digest();
-            FilePath f = getFile(digest, false);
+            File f = getFile(digest, false);
             if (f.exists()) {
                 file.delete();
             } else {
-                FilePath parent = f.getParent();
+                File parent = f.getParentFile();
                 if (!parent.exists()) {
-                    FileUtils.createDirectories(parent.toString());
+                    parent.mkdirs();
                 }
-                file.moveTo(f);
+                file.renameTo(f);
             }
             IOUtils.writeVarInt(idStream, digest.length);
             idStream.write(digest);
@@ -90,42 +91,42 @@ public class FileBlobStore extends Abstr
 
     @Override
     protected synchronized void storeBlock(byte[] digest, int level, byte[] data) throws
IOException {
-        FilePath f = getFile(digest, false);
+        File f = getFile(digest, false);
         if (f.exists()) {
             return;
         }
-        FilePath parent = f.getParent();
+        File parent = f.getParentFile();
         if (!parent.exists()) {
-            FileUtils.createDirectories(parent.toString());
+            parent.mkdirs();
         }
-        FilePath temp = parent.resolve(f.getName() + ".temp");
-        OutputStream out = temp.newOutputStream(false);
+        File temp = new File(parent, f.getName() + ".temp");
+        OutputStream out = new FileOutputStream(temp, false);
         out.write(data);
         out.close();
-        temp.moveTo(f);
+        temp.renameTo(f);
     }
 
-    private FilePath getFile(byte[] digest, boolean old) {
+    private File getFile(byte[] digest, boolean old) {
         String id = StringUtils.convertBytesToHex(digest);
         String sub = id.substring(id.length() - 2);
         if (old) {
             sub += OLD_SUFFIX;
         }
-        return baseDir.resolve(sub).resolve(id + ".dat");
+        return new File(new File(baseDir, sub), id + ".dat");
     }
 
     @Override
     protected byte[] readBlockFromBackend(BlockId id) throws IOException {
-        FilePath f = getFile(id.digest, false);
+        File f = getFile(id.digest, false);
         if (!f.exists()) {
-            FilePath old = getFile(id.digest, true);
-            f.getParent().createDirectory();
-            old.moveTo(f);
+            File old = getFile(id.digest, true);
+            f.getParentFile().mkdir();
+            old.renameTo(f);
             f = getFile(id.digest, false);
         }
-        int length = (int) Math.min(f.size(), getBlockSize());
+        int length = (int) Math.min(f.length(), getBlockSize());
         byte[] data = new byte[length];
-        InputStream in = f.newInputStream();
+        InputStream in = new FileInputStream(f);
         try {
             IOUtils.skipFully(in, id.pos);
             IOUtils.readFully(in, data, 0, length);
@@ -140,17 +141,17 @@ public class FileBlobStore extends Abstr
         mark = true;
         for (int i = 0; i < 256; i++) {
             String sub = StringUtils.convertBytesToHex(new byte[] { (byte) i });
-            FilePath d = baseDir.resolve(sub);
-            FilePath old = baseDir.resolve(sub + OLD_SUFFIX);
+            File d = new File(baseDir, sub);
+            File old = new File(baseDir, sub + OLD_SUFFIX);
             if (d.exists()) {
                 if (old.exists()) {
-                    for (FilePath p : d.newDirectoryStream()) {
+                    for (File p : d.listFiles()) {
                         String name = p.getName();
-                        FilePath newName = old.resolve(name);
-                        p.moveTo(newName);
+                        File newName = new File(old, name);
+                        p.renameTo(newName);
                     }
                 } else {
-                    d.moveTo(old);
+                    d.renameTo(old);
                 }
             }
         }
@@ -164,11 +165,11 @@ public class FileBlobStore extends Abstr
 
     @Override
     protected void mark(BlockId id) throws IOException {
-        FilePath f = getFile(id.digest, false);
+        File f = getFile(id.digest, false);
         if (!f.exists()) {
-            FilePath old = getFile(id.digest, true);
-            f.getParent().createDirectory();
-            old.moveTo(f);
+            File old = getFile(id.digest, true);
+            f.getParentFile().mkdir();
+            old.renameTo(f);
             f = getFile(id.digest, false);
         }
     }
@@ -178,11 +179,11 @@ public class FileBlobStore extends Abstr
         int count = 0;
         for (int i = 0; i < 256; i++) {
             String sub = StringUtils.convertBytesToHex(new byte[] { (byte) i });
-            FilePath old = baseDir.resolve(sub + OLD_SUFFIX);
+            File old = new File(baseDir, sub + OLD_SUFFIX);
             if (old.exists()) {
-                for (FilePath p : old.newDirectoryStream()) {
+                for (File p : old.listFiles()) {
                     String name = p.getName();
-                    FilePath file = old.resolve(name);
+                    File file = new File(old, name);
                     file.delete();
                     count++;
                 }

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java?rev=1304484&r1=1304483&r2=1304484&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/MongoPersistence.java
Fri Mar 23 17:00:53 2012
@@ -19,11 +19,12 @@ package org.apache.jackrabbit.mk.persist
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.InputStream;
 import java.util.Iterator;
 
 import org.apache.jackrabbit.mk.blobs.BlobStore;
-import org.apache.jackrabbit.mk.fs.FilePath;
 import org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;
 import org.apache.jackrabbit.mk.model.Commit;
 import org.apache.jackrabbit.mk.model.Id;
@@ -250,11 +251,15 @@ public class MongoPersistence implements
 
     public String addBlob(String tempFilePath) throws Exception {
         try {
-            FilePath file = FilePath.get(tempFilePath);
+            File file = new File(tempFilePath);
+            InputStream in = null;
             try {
-                InputStream in = file.newInputStream();
+                in = new FileInputStream(file);
                 return writeBlob(in);
             } finally {
+                if (in != null) {
+                    in.close();
+                }
                 file.delete();
             }
         } catch (Exception e) {

Modified: jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java?rev=1304484&r1=1304483&r2=1304484&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/blobs/DbBlobStoreTest.java
Fri Mar 23 17:00:53 2012
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.mk.blobs;
 
 import junit.framework.TestCase;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
-import org.apache.jackrabbit.mk.fs.FileUtils;
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.util.IOUtilsTest;
@@ -70,7 +69,9 @@ public class DbBlobStoreTest extends Tes
         Random r = new Random(0);
         r.nextBytes(data);
         String tempFileName = "target/temp/test";
-        OutputStream out = FileUtils.newOutputStream(tempFileName, false);
+        File tempFile = new File(tempFileName);
+        tempFile.getParentFile().mkdirs();
+        OutputStream out = new FileOutputStream(tempFile, false);
         out.write(data);
         out.close();
         String s = store.addBlob(tempFileName);

Modified: jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java?rev=1304484&r1=1304483&r2=1304484&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/test/java/org/apache/jackrabbit/mk/store/CopyingGCTest.java
Fri Mar 23 17:00:53 2012
@@ -24,7 +24,6 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.blobs.MemoryBlobStore;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.mk.core.Repository;
-import org.apache.jackrabbit.mk.fs.FileUtils;
 import org.apache.jackrabbit.mk.json.fast.Jsop;
 import org.apache.jackrabbit.mk.json.fast.JsopArray;
 import org.apache.jackrabbit.mk.persistence.InMemPersistence;
@@ -34,6 +33,9 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
+import java.io.File;
+import java.io.IOException;
+
 /**
  * Use-case: start off a new revision store that contains just the head revision
  * and its nodes.
@@ -47,8 +49,8 @@ public class CopyingGCTest {
     
     @Before
     public void setup() throws Exception {
-        FileUtils.deleteRecursive("target/mk1", false);
-        FileUtils.deleteRecursive("target/mk2", false);
+        delete(new File("target/mk1"));
+        delete(new File("target/mk2"));
     }
 
     @After
@@ -134,4 +136,16 @@ public class CopyingGCTest {
         // Assert MK contains 3 revisions only
         assertEquals(3, ((JsopArray) Jsop.parse(mk.getRevisions(0, Integer.MAX_VALUE))).size());
     }
+    
+    private static void delete(File f) throws IOException {
+        if (f.exists()) {
+            if (f.isDirectory()) {
+                // recursively delete children first
+                for (File child : f.listFiles()) {
+                    delete(child);
+                }
+            }
+            f.delete();
+        }
+    }
 }



Mime
View raw message