1 3 package jodd.typeconverter; 4 5 import java.sql.Clob ; 6 import java.sql.SQLException ; 7 8 11 public class StringConverter implements TypeConverter { 12 13 public static String valueOf(Object value) { 14 if (value == null) { 15 return null; 16 } 17 Class type = value.getClass(); 18 if (type == byte[].class) { 19 byte[] valueArray = (byte[]) value; 20 return new String (valueArray, 0, valueArray.length); 21 } 22 if (value instanceof Clob ) { 23 Clob clob = (Clob ) value; 24 try { 25 long lenght = clob.length(); 26 if (lenght > Integer.MAX_VALUE) { 27 throw new TypeConversionException("Clob is too big."); 28 } 29 return clob.getSubString(1, (int) lenght); 30 } catch (SQLException sex) { 31 throw new TypeConversionException(sex); 32 } 33 } 34 return value.toString(); 35 } 36 37 public Object convert(Object value) { 38 return valueOf(value); 39 } 40 41 } 42 | Popular Tags |