I have to set private InputStream responseMsg
in my struts 2 application action class methods using following code
responseMsg = new ByteArrayInputStream(message.getBytes("UTF-8"));
in this case i have to handle UnsupportedEncodingException
checked exception. I want to assign InputStream
in so many action methods if i added throws UnsupportedEncodingException
in all methods means code looks messy. so i decided to create utility method in a Utility class
public class Utilities {
public InputStream responseMessage(String message) throws UnsupportedEncodingException {
return new ByteArrayInputStream(message.getBytes("UTF-8"));
}
}
invoked from my action class
responseMsg = new Utilities().responseMessage(message);
in this case also compile time error coming to handle UnsupportedEncodingException
in action methods, help me to create Utility methods for all of my action class methods.