Index: src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java (revision 1029616) +++ src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java (working copy) @@ -841,8 +841,7 @@ if (!bRs.next()) { throw new SQLException("bundle cannot be retrieved?"); } - Blob blob = bRs.getBlob(1); - data = getBytes(blob); + data = getBytes(bRs); } finally { closeResultSet(bRs); } @@ -1100,7 +1099,7 @@ if (!rs.next()) { return null; } - byte[] bytes = getBytes(rs.getBlob(1)); + byte[] bytes = getBytes(rs); try { NodePropBundle bundle = @@ -1124,12 +1123,13 @@ /** * Reads the blob's bytes and returns it. this is a helper method to * circumvent issue JCR-1039 and JCR-1474 - * @param blob blob to read + * @param bRs result set with blob as first item to read * @return bytes of the blob * @throws SQLException if an SQL error occurs * @throws IOException if an I/O error occurs */ - private byte[] getBytes(Blob blob) throws SQLException, IOException { + protected byte[] getBytes(ResultSet bRs) throws SQLException, IOException { + Blob blob = bRs.getBlob(1); InputStream in = null; try { long length = blob.length(); Index: src/main/java/org/apache/jackrabbit/core/persistence/bundle/PostgreSQLPersistenceManager.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/persistence/bundle/PostgreSQLPersistenceManager.java (revision 1029616) +++ src/main/java/org/apache/jackrabbit/core/persistence/bundle/PostgreSQLPersistenceManager.java (working copy) @@ -16,6 +16,7 @@ */ package org.apache.jackrabbit.core.persistence.bundle; +import org.apache.commons.io.IOUtils; import org.apache.jackrabbit.core.id.NodeId; import org.apache.jackrabbit.core.persistence.PMContext; import org.apache.jackrabbit.core.persistence.util.NodePropBundle; @@ -24,7 +25,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InputStream; +import java.sql.Blob; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -115,4 +119,29 @@ } } + /** + * Reads the blob's bytes and returns it. + * + * @param bRs result set with blob as first item to read + * @return bytes of the blob + * @throws SQLException if an SQL error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected byte[] getBytes(ResultSet bRs) throws SQLException, IOException { + InputStream in = bRs.getBinaryStream(1); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + byte[] buff = new byte[1024]; + int read; + try { + while ((read = in.read(buff)) >= 0) + out.write(buff, 0, read); + out.flush(); + return out.toByteArray(); + } finally { + IOUtils.closeQuietly(in); + IOUtils.closeQuietly(out); + } + } + }