Author: sagara Date: Tue Oct 18 07:09:15 2011 New Revision: 1185510 URL: http://svn.apache.org/viewvc?rev=1185510&view=rev Log: Merged r1185504 to the 1.6 branch.
Modified: axis/axis2/java/core/branches/1_6/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java axis/axis2/java/core/branches/1_6/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java Modified: axis/axis2/java/core/branches/1_6/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java?rev=1185510&r1=1185509&r2=1185510&view=diff ============================================================================== --- axis/axis2/java/core/branches/1_6/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java (original) +++ axis/axis2/java/core/branches/1_6/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java Tue Oct 18 07:09:15 2011 @@ -1333,18 +1333,27 @@ public class ConverterUtil { * * @return string */ - public static String getStringFromDatahandler(DataHandler dataHandler) { - try { - InputStream inStream; - if (dataHandler == null) { - return ""; - } - inStream = dataHandler.getDataSource().getInputStream(); - byte[] data = IOUtils.getStreamAsByteArray(inStream); - return Base64.encode(data); - } catch (Exception e) { - throw new RuntimeException(e); - } + public static String getStringFromDatahandler(DataHandler dataHandler) { + InputStream inStream = null; + try { + if (dataHandler == null) { + return ""; + } + inStream = dataHandler.getDataSource().getInputStream(); + byte[] data = IOUtils.getStreamAsByteArray(inStream); + return Base64.encode(data); + } catch (Exception e) { + throw new RuntimeException(e); + + } finally { + try { + if (inStream != null) + inStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } } /** Modified: axis/axis2/java/core/branches/1_6/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/branches/1_6/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java?rev=1185510&r1=1185509&r2=1185510&view=diff ============================================================================== --- axis/axis2/java/core/branches/1_6/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java (original) +++ axis/axis2/java/core/branches/1_6/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java Tue Oct 18 07:09:15 2011 @@ -29,6 +29,12 @@ import java.util.Date; import java.util.List; import java.util.TimeZone; +import javax.activation.DataHandler; +import javax.activation.DataSource; + +import org.apache.axiom.attachments.ByteArrayDataSource; +import org.apache.axiom.om.util.Base64; + public class ConverterUtilTest extends TestCase { /** Test conversion of Big Integer */ @@ -168,5 +174,14 @@ public class ConverterUtilTest extends T TestCase.assertTrue(ConverterUtil.convertToString(c).endsWith("+09:00")); } + + public void testConvertToStringFromDataHandler() { + String inStr = "Sample Data"; + DataSource ds = new ByteArrayDataSource(inStr.getBytes()); + DataHandler dh = new DataHandler(ds); + String rawOutStr = ConverterUtil.convertToString(dh); + String outStr = new String(Base64.decode(rawOutStr)); + assertEquals("Not expected content", inStr, outStr); + } }