svn commit: r883529 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r883529 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

adrianc
Author: adrianc
Date: Mon Nov 23 22:49:06 2009
New Revision: 883529

URL: http://svn.apache.org/viewvc?rev=883529&view=rev
Log:
Added Blob<->byte[] converters.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java?rev=883529&r1=883528&r2=883529&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/MiscConverters.java Mon Nov 23 22:49:06 2009
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.Reader;
+import java.sql.Blob;
 import java.sql.Clob;
 import java.util.Locale;
 
@@ -30,6 +31,34 @@
 
     public static final int CHAR_BUFFER_SIZE = 4096;
 
+    public static class BlobToByteArray extends AbstractConverter<Blob, byte[]> {
+        public BlobToByteArray() {
+            super(Blob.class, byte[].class);
+        }
+
+        public byte[] convert(Blob obj) throws ConversionException {
+            try {
+                return obj.getBytes(1, Integer.MAX_VALUE);
+            } catch (Exception e) {
+                throw new ConversionException(e);
+            }
+        }
+    }
+
+    public static class ByteArrayToBlob extends AbstractConverter<byte[], Blob> {
+        public ByteArrayToBlob() {
+            super(byte[].class, Blob.class);
+        }
+
+        public Blob convert(byte[] obj) throws ConversionException {
+            try {
+                return new javax.sql.rowset.serial.SerialBlob(obj);
+            } catch (Exception e) {
+                throw new ConversionException(e);
+            }
+        }
+    }
+
     public static class ClobToString extends AbstractConverter<Clob, String> {
         public ClobToString() {
             super(Clob.class, String.class);