You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by sa...@apache.org on 2011/10/18 08:54:07 UTC
svn commit: r1185504 - in /axis/axis2/java/core/trunk/modules/adb:
src/org/apache/axis2/databinding/utils/ConverterUtil.java
test/org/apache/axis2/databinding/utils/ConverterUtilTest.java
Author: sagara
Date: Tue Oct 18 06:54:07 2011
New Revision: 1185504
URL: http://svn.apache.org/viewvc?rev=1185504&view=rev
Log:
Fixed AXIS2-5167 and added a test case for getStringFromDatahandler() method.
Modified:
axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java
axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java
Modified: axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java?rev=1185504&r1=1185503&r2=1185504&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java (original)
+++ axis/axis2/java/core/trunk/modules/adb/src/org/apache/axis2/databinding/utils/ConverterUtil.java Tue Oct 18 06:54:07 2011
@@ -1360,18 +1360,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/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java?rev=1185504&r1=1185503&r2=1185504&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java (original)
+++ axis/axis2/java/core/trunk/modules/adb/test/org/apache/axis2/databinding/utils/ConverterUtilTest.java Tue Oct 18 06:54:07 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 */
@@ -207,5 +213,13 @@ public class ConverterUtilTest extends T
assertNotNull(date);
}
-
+
+ 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);
+ }
}