@Override public AgentData unmarshalling(byte[] bdata, AgentData adata) { AgentInputStream ais = null; FileData data = (FileData) adata; try { ais = ObjectFactory.getObjectPool(AgentInputStream.class).borrowObject(); ais.setInput(new ByteArrayInputStream(bdata)); // fixed // 앞에 typeCd가 한번 더 붙어서 오기때문에 두번 read한다. data.setTypeCd((char) ais.read()); data.setAgentId(ais.readString(APMConstants.AGENT_ID_LEN).trim()); data.setTypeCd((char) ais.read()); data.setReqId(ais.readString(APMConstants.REQ_ID_LEN).trim()); data.setReqSeq(ais.readShort()); data.setReqChkDtm(ais.readString(APMConstants.DTM_LEN).trim()); data.setInOutCl(ais.readString(APMConstants.INOUT_CL_LEN).trim()); data.setElapsedTime(ais.readInt()); // 파일 타입일 때는 ip/port가 없으므로 VO에 담지 않는다. ais.readString(APMConstants.IP_LEN); ais.readInt(); ais.readInt(); data.setFilePath(ais.readString((byte) APMConstants.COL_DELIMITER)); return data; } catch (Exception e) { e.printStackTrace(); } finally { try { ObjectFactory.getObjectPool(AgentInputStream.class).returnObject(ais); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return data; }
@Override public byte[] marshalling(AgentData agentData) { AgentOutputStream aos = null; FileData data = (FileData) agentData; try { aos = ObjectFactory.getObjectPool(AgentOutputStream.class).borrowObject(); // fixed aos.writeString(data.getAgentId(), APMConstants.AGENT_ID_LEN); aos.writeByte((byte) data.getTypeCd()); aos.writeString(data.getReqId(), APMConstants.REQ_ID_LEN); aos.writeShort(data.getReqSeq()); aos.writeString(data.getReqChkDtm(), APMConstants.DTM_LEN); aos.writeString(data.getInOutCl(), APMConstants.INOUT_CL_LEN); aos.writeInt(data.getElapsedTime()); // 파일 타입일 때는 ip/port가 없으므로 빈 값으로 보낸다. aos.writeString("", APMConstants.IP_LEN); aos.writeInt(0); aos.writeInt(0); aos.writeString(data.getFilePath()); aos.writeByte((byte) APMConstants.COL_DELIMITER); return aos.toByteArray(); } catch (Exception e) { e.printStackTrace(); } finally { try { ObjectFactory.getObjectPool(AgentOutputStream.class).returnObject(aos); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return aos.toByteArray(); }