aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/HuabaoProtocolEncoder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-06-14 16:33:40 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-06-14 16:33:40 +1200
commit54cbcf9acf0a6f99126562ae5e5dd72e91175b77 (patch)
tree6463bdbdbc9bfa31c79f6e5629aff878d8ab813c /src/org/traccar/protocol/HuabaoProtocolEncoder.java
parenta20b967182f824b98dd39d3e85294fe3d0a7d0d4 (diff)
downloadtrackermap-server-54cbcf9acf0a6f99126562ae5e5dd72e91175b77.tar.gz
trackermap-server-54cbcf9acf0a6f99126562ae5e5dd72e91175b77.tar.bz2
trackermap-server-54cbcf9acf0a6f99126562ae5e5dd72e91175b77.zip
Release allocated buffer
Diffstat (limited to 'src/org/traccar/protocol/HuabaoProtocolEncoder.java')
-rw-r--r--src/org/traccar/protocol/HuabaoProtocolEncoder.java39
1 files changed, 21 insertions, 18 deletions
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();
}
}