jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1344884 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/mk/util/ oak-mk/src/main/java/org/apache/jackrabbit/mk/blobs/ oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/ oak-mk/src/main/java/org/apache/jackr...
Date Thu, 31 May 2012 19:58:19 GMT
Author: stefan
Date: Thu May 31 19:58:19 2012
New Revision: 1344884

URL: http://svn.apache.org/viewvc?rev=1344884&view=rev
Log:
OAK-77: Consolidate Utilities

move StringCache and ExceptionFactory utility classes to the oak-core component where they
are referenced

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java
  (contents, props changed)
      - copied, changed from r1344879, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java
  (contents, props changed)
      - copied, changed from r1344288, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java
Removed:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java
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

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java
(from r1344879, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java&r1=1344879&r2=1344884&rev=1344884&view=diff
==============================================================================
    (empty)

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java
(from r1344288, jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java&p1=jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java&r1=1344288&r2=1344884&rev=1344884&view=diff
==============================================================================
    (empty)

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/util/StringCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1344884&r1=1344883&r2=1344884&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
Thu May 31 19:58:19 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.mk.blobs;
 
-import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.Cache;
 import org.apache.jackrabbit.mk.util.StringUtils;
@@ -105,25 +104,21 @@ public abstract class AbstractBlobStore 
         return blockSize;
     }
 
-    public String addBlob(String tempFilePath) {
+    public String addBlob(String tempFilePath) throws Exception {
+        File file = new File(tempFilePath);
+        InputStream in = null;
         try {
-            File file = new File(tempFilePath);
-            InputStream in = null;
-            try {
-                in = new FileInputStream(file);
-                return writeBlob(in);
-            } finally {
-                if (in != null) {
-                    in.close();
-                }
-                file.delete();
+            in = new FileInputStream(file);
+            return writeBlob(in);
+        } finally {
+            if (in != null) {
+                in.close();
             }
-        } catch (Exception e) {
-            throw ExceptionFactory.convert(e);
+            file.delete();
         }
     }
 
-    public String writeBlob(InputStream in) {
+    public String writeBlob(InputStream in) throws Exception {
         try {
             ByteArrayOutputStream idStream = new ByteArrayOutputStream();
             convertBlobToId(in, idStream, 0, 0);
@@ -132,13 +127,12 @@ public abstract class AbstractBlobStore 
             String blobId = StringUtils.convertBytesToHex(id);
             usesBlobId(blobId);
             return blobId;
-        } catch (Exception e) {
+        } finally {
             try {
                 in.close();
-            } catch (IOException e1) {
+            } catch (IOException e) {
                 // ignore
             }
-            throw ExceptionFactory.convert(e);
         }
     }
 
@@ -221,59 +215,55 @@ public abstract class AbstractBlobStore 
         }
     }
 
-    public int readBlob(String blobId, long pos, byte[] buff, int off, int length) {
-        try {
-            if (isMarkEnabled()) {
-                mark(blobId);
-            }
-            byte[] id = StringUtils.convertHexToBytes(blobId);
-            ByteArrayInputStream idStream = new ByteArrayInputStream(id);
-            while (true) {
-                int type = idStream.read();
-                if (type == -1) {
-                    return -1;
-                } else if (type == TYPE_DATA) {
-                    int len = IOUtils.readVarInt(idStream);
-                    if (pos < len) {
-                        IOUtils.skipFully(idStream, (int) pos);
-                        len -= pos;
-                        if (length < len) {
-                            len = length;
-                        }
-                        IOUtils.readFully(idStream, buff, off, len);
-                        return len;
+    public int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws
Exception {
+        if (isMarkEnabled()) {
+            mark(blobId);
+        }
+        byte[] id = StringUtils.convertHexToBytes(blobId);
+        ByteArrayInputStream idStream = new ByteArrayInputStream(id);
+        while (true) {
+            int type = idStream.read();
+            if (type == -1) {
+                return -1;
+            } else if (type == TYPE_DATA) {
+                int len = IOUtils.readVarInt(idStream);
+                if (pos < len) {
+                    IOUtils.skipFully(idStream, (int) pos);
+                    len -= pos;
+                    if (length < len) {
+                        len = length;
                     }
-                    IOUtils.skipFully(idStream, len);
-                    pos -= len;
-                } else if (type == TYPE_HASH) {
-                    int level = IOUtils.readVarInt(idStream);
-                    long totalLength = IOUtils.readVarLong(idStream);
+                    IOUtils.readFully(idStream, buff, off, len);
+                    return len;
+                }
+                IOUtils.skipFully(idStream, len);
+                pos -= len;
+            } else if (type == TYPE_HASH) {
+                int level = IOUtils.readVarInt(idStream);
+                long totalLength = IOUtils.readVarLong(idStream);
+                if (level > 0) {
+                    // block length (ignored)
+                    IOUtils.readVarLong(idStream);
+                }
+                byte[] digest = new byte[IOUtils.readVarInt(idStream)];
+                IOUtils.readFully(idStream, digest, 0, digest.length);
+                if (pos >= totalLength) {
+                    pos -= totalLength;
+                } else {
                     if (level > 0) {
-                        // block length (ignored)
-                        IOUtils.readVarLong(idStream);
-                    }
-                    byte[] digest = new byte[IOUtils.readVarInt(idStream)];
-                    IOUtils.readFully(idStream, digest, 0, digest.length);
-                    if (pos >= totalLength) {
-                        pos -= totalLength;
+                        byte[] block = readBlock(digest, 0);
+                        idStream = new ByteArrayInputStream(block);
                     } else {
-                        if (level > 0) {
-                            byte[] block = readBlock(digest, 0);
-                            idStream = new ByteArrayInputStream(block);
-                        } else {
-                            long readPos = pos - pos % blockSize;
-                            byte[] block = readBlock(digest, readPos);
-                            ByteArrayInputStream in = new ByteArrayInputStream(block);
-                            IOUtils.skipFully(in, pos - readPos);
-                            return IOUtils.readFully(in, buff, off, length);
-                        }
+                        long readPos = pos - pos % blockSize;
+                        byte[] block = readBlock(digest, readPos);
+                        ByteArrayInputStream in = new ByteArrayInputStream(block);
+                        IOUtils.skipFully(in, pos - readPos);
+                        return IOUtils.readFully(in, buff, off, length);
                     }
-                } else {
-                    throw new IOException("Unknown blobs id type " + type + " for blob "
+ blobId);
                 }
+            } else {
+                throw new IOException("Unknown blobs id type " + type + " for blob " + blobId);
             }
-        } catch (Exception e) {
-            throw ExceptionFactory.convert(e);
         }
     }
 
@@ -286,46 +276,42 @@ public abstract class AbstractBlobStore 
         try {
             return new Data(readBlockFromBackend(id));
         } catch (Exception e) {
-            throw ExceptionFactory.convert(e);
+            throw new RuntimeException("failed to read block from backend", e);
         }
     }
 
     protected abstract byte[] readBlockFromBackend(BlockId id) throws Exception;
 
-    public long getBlobLength(String blobId) {
-        try {
-            if (isMarkEnabled()) {
-                mark(blobId);
+    public long getBlobLength(String blobId) throws Exception {
+        if (isMarkEnabled()) {
+            mark(blobId);
+        }
+        byte[] id = StringUtils.convertHexToBytes(blobId);
+        ByteArrayInputStream idStream = new ByteArrayInputStream(id);
+        long totalLength = 0;
+        while (true) {
+            int type = idStream.read();
+            if (type == -1) {
+                break;
             }
-            byte[] id = StringUtils.convertHexToBytes(blobId);
-            ByteArrayInputStream idStream = new ByteArrayInputStream(id);
-            long totalLength = 0;
-            while (true) {
-                int type = idStream.read();
-                if (type == -1) {
-                    break;
-                }
-                if (type == TYPE_DATA) {
-                    int len = IOUtils.readVarInt(idStream);
-                    IOUtils.skipFully(idStream, len);
-                    totalLength += len;
-                } else if (type == TYPE_HASH) {
-                    int level = IOUtils.readVarInt(idStream);
-                    totalLength += IOUtils.readVarLong(idStream);
-                    if (level > 0) {
-                        // block length (ignored)
-                        IOUtils.readVarLong(idStream);
-                    }
-                    int digestLength = IOUtils.readVarInt(idStream);
-                    IOUtils.skipFully(idStream, digestLength);
-                } else {
-                    throw new IOException("Datastore id type " + type + " for blob " + blobId);
+            if (type == TYPE_DATA) {
+                int len = IOUtils.readVarInt(idStream);
+                IOUtils.skipFully(idStream, len);
+                totalLength += len;
+            } else if (type == TYPE_HASH) {
+                int level = IOUtils.readVarInt(idStream);
+                totalLength += IOUtils.readVarLong(idStream);
+                if (level > 0) {
+                    // block length (ignored)
+                    IOUtils.readVarLong(idStream);
                 }
+                int digestLength = IOUtils.readVarInt(idStream);
+                IOUtils.skipFully(idStream, digestLength);
+            } else {
+                throw new IOException("Datastore id type " + type + " for blob " + blobId);
             }
-            return totalLength;
-        } catch (IOException e) {
-            throw ExceptionFactory.convert(e);
         }
+        return totalLength;
     }
 
     protected void mark(String blobId) throws IOException {

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=1344884&r1=1344883&r2=1344884&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
Thu May 31 19:58:19 2012
@@ -25,7 +25,6 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.security.DigestInputStream;
 import java.security.MessageDigest;
-import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.StringUtils;
 
@@ -48,47 +47,43 @@ public class FileBlobStore extends Abstr
     }
 
     @Override
-    public String addBlob(String tempFilePath) {
+    public String addBlob(String tempFilePath) throws Exception {
+        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.length();
         try {
-            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.length();
-            try {
-                while (true) {
-                    int len = din.read(buffer, 0, buffer.length);
-                    if (len < 0) {
-                        break;
-                    }
+            while (true) {
+                int len = din.read(buffer, 0, buffer.length);
+                if (len < 0) {
+                    break;
                 }
-            } finally {
-                din.close();
             }
-            ByteArrayOutputStream idStream = new ByteArrayOutputStream();
-            idStream.write(TYPE_HASH);
-            IOUtils.writeVarInt(idStream, 0);
-            IOUtils.writeVarLong(idStream, length);
-            byte[] digest = messageDigest.digest();
-            File f = getFile(digest, false);
-            if (f.exists()) {
-                file.delete();
-            } else {
-                File parent = f.getParentFile();
-                if (!parent.exists()) {
-                    parent.mkdirs();
-                }
-                file.renameTo(f);
+        } finally {
+            din.close();
+        }
+        ByteArrayOutputStream idStream = new ByteArrayOutputStream();
+        idStream.write(TYPE_HASH);
+        IOUtils.writeVarInt(idStream, 0);
+        IOUtils.writeVarLong(idStream, length);
+        byte[] digest = messageDigest.digest();
+        File f = getFile(digest, false);
+        if (f.exists()) {
+            file.delete();
+        } else {
+            File parent = f.getParentFile();
+            if (!parent.exists()) {
+                parent.mkdirs();
             }
-            IOUtils.writeVarInt(idStream, digest.length);
-            idStream.write(digest);
-            byte[] id = idStream.toByteArray();
-            String blobId = StringUtils.convertBytesToHex(id);
-            usesBlobId(blobId);
-            return blobId;
-        } catch (Exception e) {
-            throw ExceptionFactory.convert(e);
+            file.renameTo(f);
         }
+        IOUtils.writeVarInt(idStream, digest.length);
+        idStream.write(digest);
+        byte[] id = idStream.toByteArray();
+        String blobId = StringUtils.convertBytesToHex(id);
+        usesBlobId(blobId);
+        return blobId;
     }
 
     @Override

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=1344884&r1=1344883&r2=1344884&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
Thu May 31 19:58:19 2012
@@ -35,7 +35,6 @@ import org.apache.jackrabbit.mk.store.Bi
 import org.apache.jackrabbit.mk.store.Binding;
 import org.apache.jackrabbit.mk.store.IdFactory;
 import org.apache.jackrabbit.mk.store.NotFoundException;
-import org.apache.jackrabbit.mk.util.ExceptionFactory;
 import org.apache.jackrabbit.mk.util.IOUtils;
 import org.apache.jackrabbit.mk.util.StringUtils;
 import org.bson.types.ObjectId;
@@ -254,17 +253,13 @@ public class MongoPersistence implements
     //------------------------------------------------------------< BlobStore >
 
     public String addBlob(String tempFilePath) throws Exception {
+        File file = new File(tempFilePath);
+        InputStream in = null;
         try {
-            File file = new File(tempFilePath);
-            InputStream in = null;
-            try {
-                in = new BufferedInputStream(new FileInputStream(file));
-                return writeBlob(in);
-            } finally {
-                file.delete();
-            }
-        } catch (Exception e) {
-            throw ExceptionFactory.convert(e);
+            in = new BufferedInputStream(new FileInputStream(file));
+            return writeBlob(in);
+        } finally {
+            file.delete();
         }
     }
 



Mime
View raw message