Index: extensions/modeshape-connector-store-jpa/src/main/java/org/modeshape/connector/store/jpa/model/simple/SimpleJpaRepository.java =================================================================== --- extensions/modeshape-connector-store-jpa/src/main/java/org/modeshape/connector/store/jpa/model/simple/SimpleJpaRepository.java (revision 2428) +++ extensions/modeshape-connector-store-jpa/src/main/java/org/modeshape/connector/store/jpa/model/simple/SimpleJpaRepository.java (working copy) @@ -882,8 +882,18 @@ public class SimpleJpaRepository extends MapRepository { try { binary.acquire(); stream = binary.getStream(); - if (compressData) stream = new GZIPInputStream(stream); - bytes = IoUtil.readBytes(stream); + if (compressData) { + ByteArrayOutputStream bs = new ByteArrayOutputStream(); + OutputStream compressedStream = new GZIPOutputStream(bs); + try { + IoUtil.write(stream, compressedStream); + } finally { + compressedStream.close(); + } + bytes = bs.toByteArray(); + } else { + bytes = IoUtil.readBytes(stream); + } } finally { try { if (stream != null) stream.close(); Index: extensions/modeshape-connector-store-jpa/src/test/java/org/modeshape/connector/store/jpa/model/simple/SimpleJpaConnectorWritableTest.java =================================================================== --- extensions/modeshape-connector-store-jpa/src/test/java/org/modeshape/connector/store/jpa/model/simple/SimpleJpaConnectorWritableTest.java (revision 2428) +++ extensions/modeshape-connector-store-jpa/src/test/java/org/modeshape/connector/store/jpa/model/simple/SimpleJpaConnectorWritableTest.java (working copy) @@ -23,11 +23,19 @@ */ package org.modeshape.connector.store.jpa.model.simple; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import java.io.File; +import org.junit.Test; +import org.modeshape.common.FixFor; import org.modeshape.connector.store.jpa.JpaSource; import org.modeshape.connector.store.jpa.TestEnvironment; import org.modeshape.graph.Graph; import org.modeshape.graph.connector.RepositorySource; import org.modeshape.graph.connector.test.WritableConnectorTest; +import org.modeshape.graph.property.Binary; +import org.modeshape.graph.property.BinaryFactory; +import org.modeshape.graph.property.Property; public class SimpleJpaConnectorWritableTest extends WritableConnectorTest { @@ -57,4 +65,30 @@ public class SimpleJpaConnectorWritableTest extends WritableConnectorTest { protected void initializeContent( Graph graph ) { } + @FixFor( "MODE-966" ) + @Test + public void shouldStoreLargeBinaryValue() throws Exception { + File file = new File("src/test/resources/testdata/test1.xmi"); + assertThat(file.exists(), is(true)); + BinaryFactory binaryFactory = context.getValueFactories().getBinaryFactory(); + Binary binaryValue = binaryFactory.create(file); + graph.batch() + .create("/someFile.xmi") + .with("jcr:primaryType", "nt:file") + .and() + .create("/someFile.xmi/jcr:content") + .with("jcr:priamryType", "nt:resource") + .and("jcr:data", binaryValue) + .and() + .execute(); + + // Now read the content back out ... + Property data = graph.getProperty("jcr:data").on("/someFile.xmi/jcr:content"); + Binary readValue = binaryFactory.create(data.getFirstValue()); + + // and verify the content matches ... + assertThat(binaryValue.getHash(), is(readValue.getHash())); + assertThat(binaryValue.getBytes(), is(readValue.getBytes())); + } + } Index: extensions/modeshape-connector-store-jpa/src/test/resources/testdata/test1.xmi new file mode 100644 =================================================================== --- /dev/null (revision 2428) +++ extensions/modeshape-connector-store-jpa/src/test/resources/testdata/test1.xmi (working copy) @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +