package xin.glue.ui.T.T04; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import com.posdata.glue.PosException; import com.posdata.glue.biz.activity.PosActivity; import com.posdata.glue.biz.constants.PosBizControlConstants; import com.posdata.glue.context.PosContext; import com.posdata.glue.dao.vo.PosRow; import com.posdata.glue.dao.vo.PosRowSet; public class ConvertBlob extends PosActivity { protected static final String alertMessage = "Do not exist blob value"; public String runActivity(PosContext ctx) { String resultKey = getProperty("resultKey"); PosRowSet rows = (PosRowSet) ctx.get("BlobFileResult"); if (rows.hasNext()) { PosRow row = rows.next(); InputStream is = (InputStream) row.getAttribute("pic"); // Blob 항목은 InputStream 으로 얻는다. if (is == null) { logger.logWarn(alertMessage); ctx.put(resultKey, alertMessage); } else { String convertedString = convertStreamToString(is); ctx.put(resultKey, convertedString); } } return PosBizControlConstants.SUCCESS; } public String convertStreamToString(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { throw new PosException( "Cannot convert stream to string: " + e.getMessage()); } finally { try { is.close(); } catch (IOException e){} } return sb.toString(); } }