You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2009/08/10 12:14:11 UTC
svn commit: r802718 - in /jackrabbit/trunk:
jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/
jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/
jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/
Author: mreutegg
Date: Mon Aug 10 10:14:11 2009
New Revision: 802718
URL: http://svn.apache.org/viewvc?rev=802718&view=rev
Log:
JCR-2248: QValueFactoryImpl$BinaryQValue must not return 'this' on getBinary
Added:
jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/BinaryTest.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/DefaultQValue.java
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/QValueFactoryImpl.java
jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
Added: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/BinaryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/BinaryTest.java?rev=802718&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/BinaryTest.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/BinaryTest.java Mon Aug 10 10:14:11 2009
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi;
+
+import java.util.Random;
+import java.io.ByteArrayInputStream;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+import javax.jcr.Property;
+import javax.jcr.Binary;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * <code>BinaryTest</code>...
+ */
+public class BinaryTest extends AbstractJCRTest {
+
+ public void testStreamBinary() throws Exception {
+ byte[] data = new byte[10 * 1024 * 1024];
+ new Random().nextBytes(data);
+ Node test = testRootNode.addNode("test");
+ Property p = test.setProperty("prop", new ByteArrayInputStream(data));
+ // check before save
+ checkBinary(p);
+ superuser.save();
+ // check after save
+ checkBinary(p);
+
+ // check from other session
+ Session s = getHelper().getReadOnlySession();
+ try {
+ p = s.getNode(testRoot).getNode("test").getProperty("prop");
+ checkBinary(p);
+ } finally {
+ s.logout();
+ }
+ }
+
+ protected void checkBinary(Property p) throws Exception {
+ for (int i = 0; i < 3; i++) {
+ Binary bin = p.getBinary();
+ try {
+ //System.out.println(bin.getClass() + "@" + System.identityHashCode(bin));
+ bin.read(new byte[1], 0);
+ } finally {
+ bin.dispose();
+ }
+ }
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/BinaryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java?rev=802718&r1=802717&r2=802718&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/test/java/org/apache/jackrabbit/jcr2spi/TestAll.java Mon Aug 10 10:14:11 2009
@@ -47,6 +47,7 @@
suite.addTestSuite(AddNewPropertyTest.class);
suite.addTestSuite(SingleValuedPropertyTest.class);
suite.addTestSuite(MultiValuedPropertyTest.class);
+ suite.addTestSuite(BinaryTest.class);
// change mixin types
suite.addTestSuite(MixinModificationTest.class);
Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java?rev=802718&r1=802717&r2=802718&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/AbstractQValue.java Mon Aug 10 10:14:11 2009
@@ -25,6 +25,8 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.ValueFormatException;
+import javax.jcr.Binary;
+
import java.util.Calendar;
import java.util.TimeZone;
import java.math.BigDecimal;
@@ -351,6 +353,38 @@
}
/**
+ * This implementation creates a binary instance that uses
+ * {@link #getStream()} and skipping on the given stream as its underlying
+ * mechanism to provide random access defined on {@link Binary}.
+ *
+ * @see QValue#getBinary()
+ */
+ public Binary getBinary() throws RepositoryException {
+ return new Binary() {
+ public InputStream getStream() throws RepositoryException {
+ return AbstractQValue.this.getStream();
+ }
+
+ public int read(byte[] b, long position) throws IOException, RepositoryException {
+ InputStream in = getStream();
+ try {
+ in.skip(position);
+ return in.read(b);
+ } finally {
+ in.close();
+ }
+ }
+
+ public long getSize() throws RepositoryException {
+ return getLength();
+ }
+
+ public void dispose() {
+ }
+ };
+ }
+
+ /**
* @see QValue#discard()
*/
public void discard() {
Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/DefaultQValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/DefaultQValue.java?rev=802718&r1=802717&r2=802718&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/DefaultQValue.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/DefaultQValue.java Mon Aug 10 10:14:11 2009
@@ -17,7 +17,6 @@
package org.apache.jackrabbit.spi.commons.value;
import java.io.Serializable;
-import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
@@ -25,13 +24,11 @@
import java.net.URI;
import java.util.Calendar;
-import javax.jcr.Binary;
import javax.jcr.RepositoryException;
import org.apache.jackrabbit.spi.QValue;
import org.apache.jackrabbit.spi.Name;
import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.value.BinaryImpl;
/**
* <code>QValue</code> implementation for all valid <code>PropertyType</code>s
@@ -83,19 +80,6 @@
//-------------------------------------------------------------< QValue >---
/**
- * @see QValue#getBinary()
- */
- public Binary getBinary() throws RepositoryException {
- try {
- // convert via string
- return new BinaryImpl(getString().getBytes(
- AbstractQValueFactory.DEFAULT_ENCODING));
- } catch (IOException e) {
- throw new RepositoryException(e);
- }
- }
-
- /**
* @see QValue#getStream()
*/
public InputStream getStream() throws RepositoryException {
Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/QValueFactoryImpl.java?rev=802718&r1=802717&r2=802718&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/QValueFactoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/value/QValueFactoryImpl.java Mon Aug 10 10:14:11 2009
@@ -24,7 +24,6 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
-import javax.jcr.Binary;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -36,7 +35,6 @@
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
-import java.io.RandomAccessFile;
import java.util.Arrays;
/**
@@ -91,7 +89,7 @@
* state, i.e. the <code>getStream()</code> method always returns a fresh
* <code>InputStream</code> instance.
*/
- private static class BinaryQValue extends AbstractQValue implements Binary, Serializable {
+ private static class BinaryQValue extends AbstractQValue implements Serializable {
/**
* A dummy value for calling the constructor of AbstractQValue
@@ -300,13 +298,6 @@
}
/**
- * @see QValue#getBinary()
- */
- public Binary getBinary() throws RepositoryException {
- return this;
- }
-
- /**
* Frees temporarily allocated resources such as temporary file, buffer, etc.
* If this <code>BinaryQValue</code> is backed by a persistent resource
* calling this method will have no effect.
@@ -327,10 +318,6 @@
}
}
- public void dispose() {
- discard();
- }
-
//-----------------------------------------------< java.lang.Object >---
/**
* Returns a string representation of this <code>BinaryQValue</code>
@@ -377,35 +364,6 @@
return 0;
}
- //-----------------------------< javx.jcr.Binary >----------------------
- /**
- * {@inheritDoc}
- */
- public int read(byte[] b, long position) throws IOException, RepositoryException {
- if (file != null) {
- // this instance is backed by a temp file
- RandomAccessFile raf = new RandomAccessFile(file, "r");
- raf.seek(position);
- return raf.read(b);
- } else {
- // this instance is backed by an in-memory buffer
- int length = Math.min(b.length, buffer.length - (int) position);
- if (length > 0) {
- System.arraycopy(buffer, (int) position, b, 0, length);
- return length;
- } else {
- return -1;
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public long getSize() throws RepositoryException {
- return getLength();
- }
-
//-----------------------------< Serializable >-------------------------
private void writeObject(ObjectOutputStream out)
Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java?rev=802718&r1=802717&r2=802718&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2davex/QValueFactoryImpl.java Mon Aug 10 10:14:11 2009
@@ -36,7 +36,6 @@
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
-import javax.jcr.Binary;
import javax.jcr.ValueFactory;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
@@ -299,37 +298,6 @@
}
/**
- * @see QValue#getBinary()
- */
- public Binary getBinary() throws RepositoryException {
- // TODO FIXME consolidate Binary implementations
- // TODO optimize
- return new Binary() {
- public InputStream getStream() throws RepositoryException {
- return BinaryQValue.this.getStream();
- }
-
- public int read(byte[] b, long position) throws IOException, RepositoryException {
- InputStream in = getStream();
- try {
- in.skip(position);
- return in.read(b);
- } finally {
- in.close();
- }
- }
-
- public long getSize() throws RepositoryException {
- return getLength();
- }
-
- public void dispose() {
- }
-
- };
- }
-
- /**
* Frees temporarily allocated resources such as temporary file, buffer, etc.
* If this <code>BinaryQValue</code> is backed by a persistent resource
* calling this method will have no effect.