From 54cbcf9acf0a6f99126562ae5e5dd72e91175b77 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 14 Jun 2018 16:33:40 +1200 Subject: Release allocated buffer --- .../traccar/protocol/HuabaoProtocolEncoder.java | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/protocol/HuabaoProtocolEncoder.java b/src/org/traccar/protocol/HuabaoProtocolEncoder.java index a622fdb9a..a2702fec7 100644 --- a/src/org/traccar/protocol/HuabaoProtocolEncoder.java +++ b/src/org/traccar/protocol/HuabaoProtocolEncoder.java @@ -30,24 +30,27 @@ public class HuabaoProtocolEncoder extends BaseProtocolEncoder { @Override protected Object encodeCommand(Command command) { - ByteBuf id = Unpooled.wrappedBuffer( - DataConverter.parseHex(getUniqueId(command.getDeviceId()))); // TODO ref count - - ByteBuf data = Unpooled.buffer(); - byte[] time = DataConverter.parseHex(new SimpleDateFormat("yyMMddHHmmss").format(new Date())); - - switch (command.getType()) { - case Command.TYPE_ENGINE_STOP: - data.writeByte(0x01); - data.writeBytes(time); - return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data); - case Command.TYPE_ENGINE_RESUME: - data.writeByte(0x00); - data.writeBytes(time); - return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data); - default: - Log.warning(new UnsupportedOperationException(command.getType())); - return null; + ByteBuf id = Unpooled.wrappedBuffer( + DataConverter.parseHex(getUniqueId(command.getDeviceId()))); + try { + ByteBuf data = Unpooled.buffer(); + byte[] time = DataConverter.parseHex(new SimpleDateFormat("yyMMddHHmmss").format(new Date())); + + switch (command.getType()) { + case Command.TYPE_ENGINE_STOP: + data.writeByte(0x01); + data.writeBytes(time); + return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data); + case Command.TYPE_ENGINE_RESUME: + data.writeByte(0x00); + data.writeBytes(time); + return HuabaoProtocolDecoder.formatMessage(HuabaoProtocolDecoder.MSG_OIL_CONTROL, id, data); + default: + Log.warning(new UnsupportedOperationException(command.getType())); + return null; + } + } finally { + id.release(); } } -- cgit v1.2.3