Return string in DataHandler

I created a web service in Javathat returns DataHandler. This should be able to return File, which works great. But he must also be able to return a String. Any idea how I can convey Stringusing DataHandler?

+5
source share
1 answer

JavaMail has ByteArrayDataSourcewhich you can use for this purpose:

DataSource ds = new ByteArrayDataSource(theString, "text/plain; charset=UTF-8");
DataHandler handler = new DataHandler(ds);

charset in the mime type, it determines what encoding it will use to convert the string to bytes.

+8
source

All Articles