jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1341504 - /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java
Date Tue, 22 May 2012 14:56:38 GMT
Author: thomasm
Date: Tue May 22 14:56:37 2012
New Revision: 1341504

URL: http://svn.apache.org/viewvc?rev=1341504&view=rev
Log:
OAK-16 Proper ValueFactory implementation and Value handling - don't use the (old) stream
for getString()

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/value/ValueImpl.java

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=1341504&r1=1341503&r2=1341504&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
Tue May 22 14:56:37 2012
@@ -180,9 +180,13 @@ class ValueImpl implements Value {
                     return namePathMapper.getJcrPath(value.toString());
                 }
             case PropertyType.BINARY:
-                InputStream stream = getStream();
+                if (stream != null) {
+                    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(stream, "UTF-8");
+                    return IOUtils.toString(in, "UTF-8");
                 } catch (IOException e) {
                     throw new RepositoryException("conversion from stream to string failed",
e);
                 } finally {
@@ -199,23 +203,24 @@ class ValueImpl implements Value {
     @Override
     public InputStream getStream() throws IllegalStateException, RepositoryException {
         if (stream == null) {
-            switch (getType()) {
-                case PropertyType.NAME:
-                case PropertyType.PATH:
-                    try {
-                        stream = new ByteArrayInputStream(getString().getBytes("UTF-8"));
-                    } catch (UnsupportedEncodingException ex) {
-                        throw new RepositoryException("UTF-8 is not supported", ex);
-                    }
-                    break;
-                default:
-                    stream = value.getNewStream();
-            }
+            stream = getNewStream();
         }
-
         return stream;
     }
 
+    private InputStream getNewStream() throws RepositoryException {
+        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 value.getNewStream();
+    }
+
     /**
      * @see javax.jcr.Value#getBinary()
      */



Mime
View raw message