jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1366639 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-it/osgi/ oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/ oak-jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/
Date Sat, 28 Jul 2012 11:23:56 GMT
Author: jukka
Date: Sat Jul 28 11:23:55 2012
New Revision: 1366639

URL: http://svn.apache.org/viewvc?rev=1366639&view=rev
Log:
OAK-200: Replace Commons Collections with Guava

Use Guava to replace also Commons IO.
Better documentation of the contract to close streams.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CoreValueFactory.java
    jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java
    jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CoreValueFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CoreValueFactory.java?rev=1366639&r1=1366638&r2=1366639&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CoreValueFactory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/CoreValueFactory.java
Sat Jul 28 11:23:55 2012
@@ -76,12 +76,14 @@ public interface CoreValueFactory {
     CoreValue createValue(BigDecimal value);
 
     /**
-     * Creates a new value of type {@link javax.jcr.PropertyType#BINARY}.
+     * Creates a new value of type {@link javax.jcr.PropertyType#BINARY}
+     * from the given byte stream. The stream is consumed <em>and</em> closed
+     * by this method.
      *
      * @param value A non-null {@code InputStream} that defines the new value.
      * @return a new value instance.
      * @throws IllegalArgumentException if the specified {@code InputStream} is {@code null}.
-     * @throws IOException If an error occurs while processing the stream.
+     * @throws IOException If the stream could not be consumed (or closed).
      * @throws //TODO define exceptions (currently impl. throws MicrokernelException)
      */
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java?rev=1366639&r1=1366638&r2=1366639&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java
(original)
+++ jackrabbit/oak/trunk/oak-it/osgi/src/test/java/org/apache/jackrabbit/oak/osgi/OSGiIT.java
Sat Jul 28 11:23:55 2012
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
 import static org.ops4j.pax.exam.CoreOptions.bundle;
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
@@ -23,6 +25,7 @@ import static org.ops4j.pax.exam.CoreOpt
 import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.util.regex.Pattern;
 
 import javax.inject.Inject;
 import javax.jcr.Repository;
@@ -48,7 +51,6 @@ public class OSGiIT {
                 junitBundles(),
                 mavenBundle("org.apache.felix", "org.apache.felix.scr", "1.6.0"),
                 bundle(new File(base, "jcr.jar").toURI().toURL().toString()),
-                bundle(new File(base, "commons-io.jar").toURI().toURL().toString()),
                 bundle(new File(base, "guava.jar").toURI().toURL().toString()),
                 bundle(new File(base, "jackrabbit-api.jar").toURI().toURL().toString()),
                 bundle(new File(base, "jackrabbit-jcr-commons.jar").toURI().toURL().toString()),
@@ -65,8 +67,8 @@ public class OSGiIT {
 
     @Test
     public void testMicroKernel() {
-        System.out.println(kernel);
-        System.out.println(kernel.getHeadRevision());
+        assertNotNull(kernel);
+        assertTrue(Pattern.matches("[0-9a-f]+", kernel.getHeadRevision()));
     }
 
     @Inject
@@ -74,7 +76,8 @@ public class OSGiIT {
 
     @Test
     public void testOakRepository() {
-        System.out.println(oakRepository);
+        assertNotNull(oakRepository);
+        // TODO: try something with oakRepository
     }
 
     @Inject
@@ -82,7 +85,8 @@ public class OSGiIT {
 
     @Test
     public void testJcrRepository() {
-        System.out.println(jcrRepository);
+        assertNotNull(jcrRepository);
+        // TODO: try something with jcrRepository
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml?rev=1366639&r1=1366638&r2=1366639&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml (original)
+++ jackrabbit/oak/trunk/oak-it/osgi/test-bundles.xml Sat Jul 28 11:23:55 2012
@@ -29,7 +29,6 @@
       <scope>test</scope>
       <includes>
         <include>javax.jcr:jcr</include>
-        <include>commons-io:commons-io</include>
         <include>com.google.guava:guava</include>
         <include>org.apache.jackrabbit:jackrabbit-api</include>
         <include>org.apache.jackrabbit:jackrabbit-jcr-commons</include>

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1366639&r1=1366638&r2=1366639&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Sat Jul 28 11:23:55 2012
@@ -192,11 +192,6 @@ org.apache.jackrabbit.test.api.observati
         <version>${guava.version}</version>
     </dependency>
     <dependency>
-      <groupId>commons-io</groupId>
-      <artifactId>commons-io</artifactId>
-      <version>1.4</version>
-    </dependency>
-    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.6.4</version>

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java?rev=1366639&r1=1366638&r2=1366639&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueFactoryImpl.java
Sat Jul 28 11:23:55 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.oak.jcr.value;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -136,9 +135,6 @@ public class ValueFactoryImpl implements
             return new ValueImpl(cv, namePathMapper);
         } catch (IOException ex) {
             throw new RuntimeException(ex);
-        } finally {
-            // JCR-2903
-            IOUtils.closeQuietly(value);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java?rev=1366639&r1=1366638&r2=1366639&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
Sat Jul 28 11:23:55 2012
@@ -16,13 +16,16 @@
  */
 package org.apache.jackrabbit.oak.jcr.value;
 
-import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.util.ISO8601;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Charsets;
+import com.google.common.io.CharStreams;
+import com.google.common.io.InputSupplier;
+
 import javax.jcr.Binary;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -31,7 +34,6 @@ import javax.jcr.ValueFormatException;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
 import java.math.BigDecimal;
 import java.util.Calendar;
 import java.util.TimeZone;
@@ -184,13 +186,17 @@ class ValueImpl implements Value {
                     throw new IllegalStateException("getStream has previously been called
on this Value instance. " +
                             "In this case a new Value instance must be acquired in order
to successfully call this method.");
                 }
-                InputStream in = getNewStream();
                 try {
-                    return IOUtils.toString(in, "UTF-8");
+                    stream = getNewStream();
+                    return CharStreams.toString(CharStreams.newReaderSupplier(
+                            new InputSupplier<InputStream>() {
+                                @Override
+                                public InputStream getInput() {
+                                    return stream;
+                                }
+                            }, Charsets.UTF_8));
                 } catch (IOException e) {
                     throw new RepositoryException("conversion from stream to string failed",
e);
-                } finally {
-                    IOUtils.closeQuietly(stream);
                 }
             default:
                 return value.toString();
@@ -212,11 +218,8 @@ class ValueImpl implements Value {
         switch (getType()) {
         case PropertyType.NAME:
         case PropertyType.PATH:
-            try {
-                return new ByteArrayInputStream(getString().getBytes("UTF-8"));
-            } catch (UnsupportedEncodingException ex) {
-                throw new RepositoryException("UTF-8 is not supported", ex);
-            }
+            return new ByteArrayInputStream(
+                    getString().getBytes(Charsets.UTF_8));
         }
         return value.getNewStream();
     }
@@ -230,6 +233,7 @@ class ValueImpl implements Value {
     }
 
     //-------------------------------------------------------------< Object >---
+
     /**
      * @see Object#equals(Object)
      */



Mime
View raw message