Source:
<code>protected void encode(ChannelHandlerContext channelHandlerContext, Object object, <START> ByteBuf byteBuf) throws Exception { <END> try { if (object instanceof CorfuMsg) { CorfuMsg corfuMsg = (CorfuMsg) object; byteBuf.writeByte(LEGACY_CORFU_MSG_MARK); corfuMsg.serialize(byteBuf); } else if (object instanceof RequestMsg) { RequestMsg request = (RequestMsg) object; ByteBufOutputStream requestOutputStream = new ByteBufOutputStream(byteBuf); try { requestOutputStream.writeByte(PROTO_CORFU_REQUEST_MSG_MARK); request.writeTo(requestOutputStream); } catch(IOException e) { log.warn("encode[{}]: Exception occurred when encoding request {}, caused by {}", request.getHeader().getRequestId(), request.getHeader(), e.getCause(), e); } finally { IOUtils.closeQuietly(requestOutputStream); } } else if (object instanceof ResponseMsg) { ResponseMsg response = (ResponseMsg) object; ByteBufOutputStream responseOutputStream = new ByteBufOutputStream(byteBuf); try { responseOutputStream.writeByte(PROTO_CORFU_RESPONSE_MSG_MARK); response.writeTo(responseOutputStream); } catch(IOException e) { log.warn("encode[{}]: Exception occurred when encoding response {}, caused by {}", response.getHeader().getRequestId(), response.getHeader(), e.getCause(), e); } finally { IOUtils.closeQuietly(responseOutputStream); } } else { log.error("encode: Unknown object of class - received while encoding", object.getClass()); } if (log.isDebugEnabled()) { long prev = maxValue.get(); maxValue.accumulate(byteBuf.readableBytes()); long curr = maxValue.get(); if (prev < curr) { log.debug("encode: New max write buffer found {}", curr); } } } catch (Exception e) { log.error("encode: Error during serialization!", e); } }</code><technical_language>throws necessary</technical_language>

Target:
protected void encode(ChannelHandlerContext channelHandlerContext, Object object, ByteBuf byteBuf) { try { if (object instanceof CorfuMsg) { CorfuMsg corfuMsg = (CorfuMsg) object; byteBuf.writeByte(LEGACY_MSG_MARK.asByte()); corfuMsg.serialize(byteBuf); } else if (object instanceof RequestMsg) { RequestMsg request = (RequestMsg) object; try (ByteBufOutputStream requestOutputStream = new ByteBufOutputStream(byteBuf)) { try { requestOutputStream.writeByte(PROTO_REQUEST_MSG_MARK.asByte()); request.writeTo(requestOutputStream); } catch (IOException e) { log.warn("encode[{}]: Exception occurred when encoding request {}, caused by {}", request.getHeader().getRequestId(), request.getHeader(), e.getCause(), e); } } } else if (object instanceof ResponseMsg) { ResponseMsg response = (ResponseMsg) object; try (ByteBufOutputStream responseOutputStream = new ByteBufOutputStream(byteBuf)) { try { responseOutputStream.writeByte(PROTO_RESPONSE_MSG_MARK.asByte()); response.writeTo(responseOutputStream); } catch (IOException e) { log.warn("encode[{}]: Exception occurred when encoding response {}, caused by {}", response.getHeader().getRequestId(), response.getHeader(), e.getCause(), e); } } } else { log.error("encode: Unknown object of class - received while encoding", object.getClass()); } if (log.isDebugEnabled()) { long prev = maxValue.get(); maxValue.accumulate(byteBuf.readableBytes()); long curr = maxValue.get(); if (prev < curr) { log.debug("encode: New max write buffer found {}", curr); } } } catch (Exception e) { log.error("encode: Error during serialization!", e); } }