jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clomb...@apache.org
Subject svn commit: r575089 - /jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java
Date Wed, 12 Sep 2007 21:46:02 GMT
Author: clombart
Date: Wed Sep 12 14:46:01 2007
New Revision: 575089

URL: http://svn.apache.org/viewvc?rev=575089&view=rev
Log:
review the implementation. Use inputstream instead of String

Modified:
    jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java

Modified: jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java?rev=575089&r1=575088&r2=575089&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java
(original)
+++ jackrabbit/trunk/contrib/jackrabbit-jcr-mapping/jcr-mapping/src/main/java/org/apache/jackrabbit/ocm/manager/atomictypeconverter/impl/ByteArrayTypeConverterImpl.java
Wed Sep 12 14:46:01 2007
@@ -17,6 +17,11 @@
 
 package org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
@@ -43,8 +48,8 @@
 		{
 			return null;
 		}
-		String value = new String((byte[]) propValue);
-		return valueFactory.createValue(value);
+		  InputStream ins = new ByteArrayInputStream((byte[]) propValue);
+		  return valueFactory.createValue(ins);
 	}
 
 
@@ -56,11 +61,11 @@
     {
 		try
 		{
-			return value.getString().getBytes();
+			return inputStreamToBytes(value.getStream());
 		}
-		catch (RepositoryException e)
+		catch (Exception e)
 		{
-			throw new IncorrectAtomicTypeException("Impossible to convert the value : " + value.toString()
, e);
+			throw new IncorrectAtomicTypeException("Impossible to convert a binary value." , e);
 		}
 	}
 
@@ -70,6 +75,20 @@
 	 */
 	public String getXPathQueryValue(ValueFactory valueFactory, Object object)
 	{
-		return  "'" + object.toString() + "'";
+		throw new IncorrectAtomicTypeException("Binary cannot be used in queries");
 	}
+	
+	private byte[] inputStreamToBytes(InputStream in) throws IOException {
+
+		ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+		byte[] buffer = new byte[1024];
+		int len;
+
+		while((len = in.read(buffer)) >= 0)
+		out.write(buffer, 0, len);
+
+		in.close();
+		out.close();
+		return out.toByteArray();
+		}
 }



Mime
View raw message