@@ -201,22 +201,38 @@ else if (value instanceof java.util.Calendar){
201201 //**************************************************************************
202202 //** toByteArray
203203 //**************************************************************************
204- /** Returns the value as a byte array.
204+ /** Returns the value as a byte array. Returns a null if the value is null
205+ * or if there was a problem converting the value to a byte array. Note
206+ * that if the underlying object is a String, and if the String appears to
207+ * represent a Base64 encoded byte array, then an attempt is made to decode
208+ * the Base64 String. Otherwise, this method will simply write the value to
209+ * a ByteArrayOutputStream and return the raw bytes.
205210 */
206211 public byte [] toByteArray (){
207212 if (value ==null ) return null ;
208213 if (value instanceof byte []) return (byte []) value ;
209214
215+
216+ //Check if string is Base64 encoded
217+ if (value instanceof String ){
218+ String data = (String ) value ;
219+ if (data .startsWith ("data:" ) && data .contains (";base64," )){
220+ String type = data .substring (data .indexOf (":" )+1 , data .indexOf (";" ));
221+ data = data .substring (("data:" + type + ";base64," ).length ());
222+ byte [] b = Base64 .decode (data );
223+ if (b !=null ) return b ;
224+ }
225+ }
226+
227+
210228 java .io .ByteArrayOutputStream bos = new java .io .ByteArrayOutputStream ();
211- try {
212- java .io .ObjectOutputStream out = new java .io .ObjectOutputStream (bos );
229+ try (java .io .ObjectOutputStream out = new java .io .ObjectOutputStream (bos )){
213230 out .writeObject (value );
214231 out .flush ();
215- out .close ();
216232 bos .close ();
217233 return bos .toByteArray ();
218234 }
219- catch (java . io . IOException ex ) {
235+ catch (Exception ex ) {
220236 return null ;
221237 }
222238 }
@@ -225,37 +241,40 @@ public byte[] toByteArray(){
225241 //**************************************************************************
226242 //** toBoolean
227243 //**************************************************************************
228- /** Returns a boolean value for the field. */
229-
244+ /** Returns the value as a Boolean. Returns null if the value is null or
245+ * cannot be converted to a Boolean.
246+ */
230247 public Boolean toBoolean (){
231- if (value != null ){
232- String value = this . value . toString (). toLowerCase (). trim () ;
248+ if (value == null ) return null ;
249+ if ( value instanceof Boolean ) return ( Boolean ) value ;
233250
234- if (value .equals ("true" )) return true ;
235- if (value .equals ("false" )) return false ;
236251
237- if (value .equals ("yes" )) return true ;
238- if (value .equals ("no" )) return false ;
252+ String value = this .value .toString ().toLowerCase ().trim ();
239253
240- if (value .equals ("y " )) return true ;
241- if (value .equals ("n " )) return false ;
254+ if (value .equals ("true " )) return true ;
255+ if (value .equals ("false " )) return false ;
242256
243- if (value .equals ("t " )) return true ;
244- if (value .equals ("f " )) return false ;
257+ if (value .equals ("yes " )) return true ;
258+ if (value .equals ("no " )) return false ;
245259
246- if (value .equals ("1" )) return true ;
247- if (value .equals ("0" )) return false ;
260+ if (value .equals ("y" )) return true ;
261+ if (value .equals ("n" )) return false ;
262+
263+ if (value .equals ("t" )) return true ;
264+ if (value .equals ("f" )) return false ;
265+
266+ if (value .equals ("1" )) return true ;
267+ if (value .equals ("0" )) return false ;
248268
249- }
250269 return null ;
251270 }
252271
253272
254273 //**************************************************************************
255274 //** isNumeric
256275 //**************************************************************************
257- /** Used to determine if the value is numeric. */
258-
276+ /** Returns true if the value is numeric.
277+ */
259278 public boolean isNumeric (){
260279 return (toDouble ()!=null );
261280 }
@@ -264,8 +283,8 @@ public boolean isNumeric(){
264283 //**************************************************************************
265284 //** isArray
266285 //**************************************************************************
267- /** Used to determine whether the value is an array. */
268-
286+ /** Returns true is the value is an array.
287+ */
269288 public boolean isArray (){
270289 return value !=null && value .getClass ().isArray ();
271290 }
@@ -274,8 +293,8 @@ public boolean isArray(){
274293 //**************************************************************************
275294 //** isNull
276295 //**************************************************************************
277- /** Used to determine whether the value is null. */
278-
296+ /** Returns true if the value is null.
297+ */
279298 public boolean isNull (){
280299 return value ==null ;
281300 }
@@ -296,8 +315,8 @@ public String toString(){
296315 //**************************************************************************
297316 //** equals
298317 //**************************************************************************
299- /** Used to compare values. Accepts any object. */
300-
318+ /** Used to compare values. Accepts any object.
319+ */
301320 public boolean equals (Object obj ){
302321 if (obj instanceof Value ) obj = ((Value ) obj ).toObject ();
303322 if (obj ==null ) {
0 commit comments