@@ -201,22 +201,38 @@ else if (value instanceof java.util.Calendar){
201
201
//**************************************************************************
202
202
//** toByteArray
203
203
//**************************************************************************
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.
205
210
*/
206
211
public byte [] toByteArray (){
207
212
if (value ==null ) return null ;
208
213
if (value instanceof byte []) return (byte []) value ;
209
214
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
+
210
228
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 )){
213
230
out .writeObject (value );
214
231
out .flush ();
215
- out .close ();
216
232
bos .close ();
217
233
return bos .toByteArray ();
218
234
}
219
- catch (java . io . IOException ex ) {
235
+ catch (Exception ex ) {
220
236
return null ;
221
237
}
222
238
}
@@ -225,37 +241,40 @@ public byte[] toByteArray(){
225
241
//**************************************************************************
226
242
//** toBoolean
227
243
//**************************************************************************
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
+ */
230
247
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 ;
233
250
234
- if (value .equals ("true" )) return true ;
235
- if (value .equals ("false" )) return false ;
236
251
237
- if (value .equals ("yes" )) return true ;
238
- if (value .equals ("no" )) return false ;
252
+ String value = this .value .toString ().toLowerCase ().trim ();
239
253
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 ;
242
256
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 ;
245
259
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 ;
248
268
249
- }
250
269
return null ;
251
270
}
252
271
253
272
254
273
//**************************************************************************
255
274
//** isNumeric
256
275
//**************************************************************************
257
- /** Used to determine if the value is numeric. */
258
-
276
+ /** Returns true if the value is numeric.
277
+ */
259
278
public boolean isNumeric (){
260
279
return (toDouble ()!=null );
261
280
}
@@ -264,8 +283,8 @@ public boolean isNumeric(){
264
283
//**************************************************************************
265
284
//** isArray
266
285
//**************************************************************************
267
- /** Used to determine whether the value is an array. */
268
-
286
+ /** Returns true is the value is an array.
287
+ */
269
288
public boolean isArray (){
270
289
return value !=null && value .getClass ().isArray ();
271
290
}
@@ -274,8 +293,8 @@ public boolean isArray(){
274
293
//**************************************************************************
275
294
//** isNull
276
295
//**************************************************************************
277
- /** Used to determine whether the value is null. */
278
-
296
+ /** Returns true if the value is null.
297
+ */
279
298
public boolean isNull (){
280
299
return value ==null ;
281
300
}
@@ -296,8 +315,8 @@ public String toString(){
296
315
//**************************************************************************
297
316
//** equals
298
317
//**************************************************************************
299
- /** Used to compare values. Accepts any object. */
300
-
318
+ /** Used to compare values. Accepts any object.
319
+ */
301
320
public boolean equals (Object obj ){
302
321
if (obj instanceof Value ) obj = ((Value ) obj ).toObject ();
303
322
if (obj ==null ) {
0 commit comments