03ee82a39281b1bb82e9226134c103f5a9ac3842.svn-base 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package xin.glue.ui.T.T04;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import com.posdata.glue.PosException;
  7. import com.posdata.glue.biz.activity.PosActivity;
  8. import com.posdata.glue.biz.constants.PosBizControlConstants;
  9. import com.posdata.glue.context.PosContext;
  10. import com.posdata.glue.dao.vo.PosRow;
  11. import com.posdata.glue.dao.vo.PosRowSet;
  12. public class ConvertBlob extends PosActivity {
  13. protected static final String alertMessage = "Do not exist blob value";
  14. public String runActivity(PosContext ctx) {
  15. String resultKey = getProperty("resultKey");
  16. PosRowSet rows = (PosRowSet) ctx.get("BlobFileResult");
  17. if (rows.hasNext()) {
  18. PosRow row = rows.next();
  19. InputStream is = (InputStream) row.getAttribute("pic"); // Blob 항목은 InputStream 으로 얻는다.
  20. if (is == null) {
  21. logger.logWarn(alertMessage);
  22. ctx.put(resultKey, alertMessage);
  23. } else {
  24. String convertedString = convertStreamToString(is);
  25. ctx.put(resultKey, convertedString);
  26. }
  27. }
  28. return PosBizControlConstants.SUCCESS;
  29. }
  30. public String convertStreamToString(InputStream is)
  31. {
  32. BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  33. StringBuffer sb = new StringBuffer();
  34. String line = null;
  35. try
  36. {
  37. while ((line = reader.readLine()) != null)
  38. {
  39. sb.append(line + "\n");
  40. }
  41. }
  42. catch (IOException e)
  43. {
  44. throw new PosException(
  45. "Cannot convert stream to string: " + e.getMessage());
  46. }
  47. finally
  48. {
  49. try
  50. {
  51. is.close();
  52. }
  53. catch (IOException e){}
  54. }
  55. return sb.toString();
  56. }
  57. }