Return-Path: X-Original-To: apmail-jackrabbit-commits-archive@www.apache.org Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5E44787CD for ; Wed, 7 Sep 2011 08:52:26 +0000 (UTC) Received: (qmail 57295 invoked by uid 500); 7 Sep 2011 08:52:23 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 57070 invoked by uid 500); 7 Sep 2011 08:52:01 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 56928 invoked by uid 99); 7 Sep 2011 08:51:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Sep 2011 08:51:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Sep 2011 08:51:54 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 767DC2388A02; Wed, 7 Sep 2011 08:51:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1166064 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/blobs/ main/java/org/apache/jackrabbit/mk/util/ test/java/org/apache/jackrabbit/mk/blobs/ Date: Wed, 07 Sep 2011 08:51:34 -0000 To: commits@jackrabbit.apache.org From: thomasm@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110907085134.767DC2388A02@eris.apache.org> Author: thomasm Date: Wed Sep 7 08:51:33 2011 New Revision: 1166064 URL: http://svn.apache.org/viewvc?rev=1166064&view=rev Log: Use MicroKernelException where possible. Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.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/blobs/AbstractBlobStore.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/blobs/AbstractBlobStore.java?rev=1166064&r1=1166063&r2=1166064&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 Wed Sep 7 08:51:33 2011 @@ -16,6 +16,7 @@ */ 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.StringUtils; import org.h2.util.SmallLRUCache; @@ -82,12 +83,16 @@ public abstract class AbstractBlobStore this.blockSize = x; } - public String writeBlob(InputStream in) throws Exception { - ByteArrayOutputStream idStream = new ByteArrayOutputStream(); - convertBlobToId(in, idStream, 0, 0); - byte[] id = idStream.toByteArray(); - // System.out.println(" write blob " + StringUtils.convertBytesToHex(id)); - return StringUtils.convertBytesToHex(id); + public String writeBlob(InputStream in) { + try { + ByteArrayOutputStream idStream = new ByteArrayOutputStream(); + convertBlobToId(in, idStream, 0, 0); + byte[] id = idStream.toByteArray(); + // System.out.println(" write blob " + StringUtils.convertBytesToHex(id)); + return StringUtils.convertBytesToHex(id); + } catch (Exception e) { + throw ExceptionFactory.convert(e); + } } private void convertBlobToId(InputStream in, ByteArrayOutputStream idStream, int level, long totalLength) throws Exception { @@ -143,50 +148,54 @@ public abstract class AbstractBlobStore protected abstract void storeBlock(byte[] blockId, int level, byte[] data) throws Exception; - public int readBlob(String blobId, long pos, byte[] buff, int off, int length) throws Exception { - 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; + public int readBlob(String blobId, long pos, byte[] buff, int off, int length) { + try { + 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; } - 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 { - byte[] block = readBlock(digest); + IOUtils.skipFully(idStream, len); + pos -= len; + } else if (type == TYPE_HASH) { + int level = IOUtils.readVarInt(idStream); + long totalLength = IOUtils.readVarLong(idStream); if (level > 0) { - idStream = new ByteArrayInputStream(block); + // 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 { - ByteArrayInputStream in = new ByteArrayInputStream(block); - IOUtils.skipFully(in, (int) pos); - return IOUtils.readFully(in, buff, off, length); + byte[] block = readBlock(digest); + if (level > 0) { + idStream = new ByteArrayInputStream(block); + } else { + ByteArrayInputStream in = new ByteArrayInputStream(block); + IOUtils.skipFully(in, (int) pos); + 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); } } @@ -202,33 +211,37 @@ public abstract class AbstractBlobStore protected abstract byte[] readBlockFromBackend(byte[] blockId) throws Exception; - public long getBlobLength(String blobId) throws IOException { - 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); + public long getBlobLength(String blobId) { + try { + 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); } - 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; } public abstract void clear(); Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java?rev=1166064&r1=1166063&r2=1166064&view=diff ============================================================================== --- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java (original) +++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/ExceptionFactory.java Wed Sep 7 08:51:33 2011 @@ -17,6 +17,7 @@ package org.apache.jackrabbit.mk.util; import org.apache.jackrabbit.mk.Constants; +import org.apache.jackrabbit.mk.api.MicroKernelException; import java.text.MessageFormat; import java.util.ConcurrentModificationException; @@ -34,6 +35,16 @@ public class ExceptionFactory { static final HashMap MESSAGE_MAP = new HashMap(); + public static MicroKernelException convert(Exception e) { + if (e instanceof MicroKernelException) { + return (MicroKernelException) e; + } + return new MicroKernelException(e.getMessage(), e); + } + + public static MicroKernelException get(String s) { + return new MicroKernelException(s); + } static { MESSAGE_MAP.put(CLOSED_0, "The repository is closed"); Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java?rev=1166064&r1=1166063&r2=1166064&view=diff ============================================================================== --- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java (original) +++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/blobs/DataStoreTest.java Wed Sep 7 08:51:33 2011 @@ -33,7 +33,7 @@ import java.util.Random; public class DataStoreTest extends TestCase { // private static final String URL = "fs:{homeDir}/target;clean"; - private static final String URL = "mem:fs:target/temp"; + private static final String URL = "mem:fs:target/temp;clean"; // private static final String URL = "mem:"; private MicroKernel mk; 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=1166064&r1=1166063&r2=1166064&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 Wed Sep 7 08:51:33 2011 @@ -17,6 +17,7 @@ package org.apache.jackrabbit.mk.blobs; import junit.framework.TestCase; +import org.apache.jackrabbit.mk.api.MicroKernelException; import org.apache.jackrabbit.mk.json.JsopBuilder; import org.apache.jackrabbit.mk.json.JsopTokenizer; import org.apache.jackrabbit.mk.util.IOUtilsTest; @@ -91,13 +92,13 @@ public class DbBlobStoreTest extends Tes try { store.readBlob("ff", 0, data, 0, 1); fail(); - } catch (IOException e) { + } catch (MicroKernelException e) { // expected } try { store.getBlobLength("ff"); fail(); - } catch (IOException e) { + } catch (MicroKernelException e) { // expected } }