本文整理汇总了Java中org.jboss.netty.buffer.ChannelBuffer.toString方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelBuffer.toString方法的具体用法?Java ChannelBuffer.toString怎么用?Java ChannelBuffer.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.netty.buffer.ChannelBuffer
的用法示例。
在下文中一共展示了ChannelBuffer.toString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
char first = (char) buf.getByte(0);
if (first == '$') {
return decodeBinary(buf, channel, remoteAddress);
} else if (first == '(') {
String sentence = buf.toString(StandardCharsets.US_ASCII);
if (sentence.contains("W01")) {
return decodeW01(sentence, channel, remoteAddress);
} else {
return decodeU01(sentence, channel, remoteAddress);
}
}
return null;
}
示例2: parseIdentification
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
int length = buf.readUnsignedShort();
String imei = buf.toString(buf.readerIndex(), length, StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (channel != null) {
ChannelBuffer response = ChannelBuffers.directBuffer(1);
if (deviceSession != null) {
response.writeByte(1);
} else {
response.writeByte(0);
}
channel.write(response);
}
return deviceSession;
}
示例3: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
index = buf.indexOf(index + 1, buf.writerIndex(), (byte) ',');
String type = buf.toString(index + 1, 3, StandardCharsets.US_ASCII);
switch (type) {
case "D03":
if (channel != null) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
String imei = Context.getIdentityManager().getById(deviceSession.getDeviceId()).getUniqueId();
String content = "D00,camera_picture.jpg,0";
int length = 1 + imei.length() + 1 + content.length() + 5;
String response = String.format("@@O%02d,%s,%s*", length, imei, content);
response += Checksum.sum(response) + "\r\n";
channel.write(response);
}
return null;
case "CCC":
return decodeBinaryMessage(channel, remoteAddress, buf);
default:
return decodeRegularMessage(channel, remoteAddress, buf);
}
}
示例4: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
String marker = buf.toString(0, 1, StandardCharsets.US_ASCII);
switch (marker) {
case "*":
String sentence = buf.toString(StandardCharsets.US_ASCII);
int typeStart = sentence.indexOf(',', sentence.indexOf(',') + 1) + 1;
int typeEnd = sentence.indexOf(',', typeStart);
if (typeEnd > 0) {
String type = sentence.substring(typeStart, typeEnd);
switch (type) {
case "NBR":
return decodeLbs(sentence, channel, remoteAddress);
case "LINK":
return decodeLink(sentence, channel, remoteAddress);
case "V3":
return decodeV3(sentence, channel, remoteAddress);
default:
return decodeText(sentence, channel, remoteAddress);
}
} else {
return null;
}
case "$":
return decodeBinary(buf, channel, remoteAddress);
case "X":
default:
return null;
}
}
示例5: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
HttpRequest request = (HttpRequest) msg;
ChannelBuffer buf = request.getContent();
buf.skipBytes("id=".length());
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '&');
String uniqueId = buf.toString(buf.readerIndex(), index - buf.readerIndex(), StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, uniqueId);
if (deviceSession == null) {
return null;
}
buf.skipBytes(uniqueId.length());
buf.skipBytes("&bin=".length());
short packetId = buf.readUnsignedByte();
short offset = buf.readUnsignedByte(); // dataOffset
short packetCount = buf.readUnsignedByte();
buf.readUnsignedByte(); // reserved
buf.readUnsignedByte(); // timezone
buf.skipBytes(offset - 5);
if (channel != null) {
sendContinue(channel);
sendResponse(channel, packetId, packetCount);
}
if (packetId == 0x31 || packetId == 0x32 || packetId == 0x36) {
if (simple) {
return parseFormatA1(deviceSession, buf);
} else {
return parseFormatA(deviceSession, buf);
}
} //else if (0x34 0x38 0x4F 0x59)
return null;
}
示例6: isBinary
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
public static boolean isBinary(ChannelBuffer buf) {
String header = buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII);
if (header.equals("+ACK")) {
return buf.getByte(buf.readerIndex() + header.length()) != (byte) ':';
} else {
return BINARY_HEADERS.contains(header);
}
}
示例7: decodeBinaryMessage
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private List<Position> decodeBinaryMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
List<Position> positions = new LinkedList<>();
String flag = buf.toString(2, 1, StandardCharsets.US_ASCII);
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
String imei = buf.toString(index + 1, 15, StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
buf.skipBytes(index + 1 + 15 + 1 + 3 + 1 + 2 + 2 + 4);
while (buf.readableBytes() >= 0x34) {
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
position.setLatitude(buf.readInt() * 0.000001);
position.setLongitude(buf.readInt() * 0.000001);
position.setTime(new Date((946684800 + buf.readUnsignedInt()) * 1000)); // 946684800 = 2000-01-01
position.setValid(buf.readUnsignedByte() == 1);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
int rssi = buf.readUnsignedByte();
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.set(Position.KEY_HDOP, buf.readUnsignedShort() * 0.1);
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
position.set("runtime", buf.readUnsignedInt());
position.setNetwork(new Network(CellTower.from(
buf.readUnsignedShort(), buf.readUnsignedShort(),
buf.readUnsignedShort(), buf.readUnsignedShort(),
rssi)));
position.set(Position.KEY_STATUS, buf.readUnsignedShort());
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01);
position.set(Position.KEY_POWER, buf.readUnsignedShort());
buf.readUnsignedInt(); // geo-fence
positions.add(position);
}
if (channel != null) {
StringBuilder command = new StringBuilder("@@");
command.append(flag).append(27 + positions.size() / 10).append(",");
command.append(imei).append(",CCC,").append(positions.size()).append("*");
int checksum = 0;
for (int i = 0; i < command.length(); i += 1) {
checksum += command.charAt(i);
}
command.append(String.format("%02x", checksum & 0xff).toUpperCase());
command.append("\r\n");
channel.write(command.toString()); // delete processed data
}
return positions;
}
示例8: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
buf.skipBytes(1); // header
int type = buf.readUnsignedByte();
ChannelBuffer dataSequence = buf.readBytes(10);
int length = buf.readUnsignedByte();
if (type == MSG_LOGIN_REQUEST || type == MSG_LOGIN_REQUEST_2) {
ChannelBuffer data = buf.readBytes(length);
String id;
if (type == MSG_LOGIN_REQUEST) {
id = data.toString(StandardCharsets.US_ASCII);
} else {
id = data.copy(1, 15).toString(StandardCharsets.US_ASCII);
}
if (getDeviceSession(channel, remoteAddress, id) != null) {
ChannelBuffer response = ChannelBuffers.dynamicBuffer();
response.writeByte(MODE_GPRS);
response.writeBytes(data);
sendResponse(channel, MSG_LOGIN_RESPONSE, dataSequence, response);
}
} else if (type == MSG_HEARTBEAT_REQUEST) {
sendResponse(channel, MSG_HEARTBEAT_RESPONSE, dataSequence, buf.readBytes(length));
} else {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Parser parser = new Parser(PATTERN, buf.readBytes(length).toString(StandardCharsets.US_ASCII));
if (!parser.matches()) {
return null;
}
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
return position;
}
return null;
}
示例9: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
buf.skipBytes(2); // header
buf.readShort(); // length
ChannelBuffer id = buf.readBytes(7);
int command = buf.readUnsignedShort();
ChannelBuffer response;
if (channel != null) {
if (command == MSG_LOGIN) {
response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
sendResponse(channel, remoteAddress, id, MSG_LOGIN_RESPONSE, response);
return null;
} else if (command == MSG_HEARTBEAT) {
response = ChannelBuffers.wrappedBuffer(new byte[]{0x01});
sendResponse(channel, remoteAddress, id, MSG_HEARTBEAT, response);
return null;
} else if (command == MSG_SERVER) {
response = ChannelBuffers.copiedBuffer(getServer(channel), StandardCharsets.US_ASCII);
sendResponse(channel, remoteAddress, id, MSG_SERVER, response);
return null;
}
}
Position position = new Position();
position.setProtocol(getProtocolName());
if (command == MSG_ALARM) {
short alarmCode = buf.readUnsignedByte();
position.set(Position.KEY_ALARM, decodeAlarm(alarmCode));
if (alarmCode >= 0x02 && alarmCode <= 0x05) {
position.set(Position.PREFIX_IN + alarmCode, 1);
} else if (alarmCode >= 0x32 && alarmCode <= 0x35) {
position.set(Position.PREFIX_IN + (alarmCode - 0x30), 0);
}
} else if (command == MSG_POSITION_LOGGED) {
buf.skipBytes(6);
}
DeviceSession deviceSession = identify(id, channel, remoteAddress);
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
if (command == MSG_RFID) {
for (int i = 0; i < 15; i++) {
long rfid = buf.readUnsignedInt();
if (rfid != 0) {
String card = String.format("%010d", rfid);
position.set("card" + (i + 1), card);
position.set(Position.KEY_DRIVER_UNIQUE_ID, card);
}
}
}
String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 4, StandardCharsets.US_ASCII);
if (command == MSG_POSITION || command == MSG_POSITION_LOGGED || command == MSG_ALARM) {
return decodeRegular(position, sentence);
} else if (command == MSG_RFID) {
return decodeRfid(position, sentence);
} else if (command == MSG_OBD_RT) {
return decodeObd(position, sentence);
} else if (command == MSG_OBD_RTA) {
return decodeObdA(position, sentence);
}
return null;
}
示例10: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
buf.skipBytes(2); // header
buf.readUnsignedShort(); // length
String imei = ChannelBuffers.hexDump(buf.readBytes(7));
DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, imei, imei + Checksum.luhn(Long.parseLong(imei)));
if (deviceSession == null) {
return null;
}
int type = buf.readUnsignedShort();
if (type == MSG_LOCATION_REPORT || type == MSG_LOCATION_REQUEST) {
String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 8, StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.hasNext(15)) {
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setSpeed(parser.nextDouble(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
} else {
getLastLocation(position, null);
}
position.setNetwork(new Network(CellTower.from(
parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0))));
return position;
}
return null;
}
示例11: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// Find IMEI number
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new ChannelBufferIndexFinder() {
@Override
public boolean find(ChannelBuffer buffer, int guessedIndex) {
if (buffer.writerIndex() - guessedIndex >= IMEI_LENGTH) {
for (int i = 0; i < IMEI_LENGTH; i++) {
if (!Character.isDigit((char) buffer.getByte(guessedIndex + i))) {
return false;
}
}
return true;
}
return false;
}
});
if (index == -1) {
return null;
}
String imei = buf.toString(index, IMEI_LENGTH, StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
// Find NMEA sentence
int start = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GPRMC"));
if (start == -1) {
return null;
}
String sentence = buf.toString(start, buf.readableBytes() - start, StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
return position;
}
示例12: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
buf.skipBytes(2); // header
Position position = new Position();
position.setProtocol(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedShort()));
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.set("mode", buf.readUnsignedByte());
position.set(Position.KEY_COMMAND, buf.readUnsignedByte());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
buf.skipBytes(5); // status
buf.readUnsignedShort(); // idleCount
buf.readUnsignedShort(); // idleTime in seconds
position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
// Parse GPRMC
int end = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
String gprmc = buf.toString(buf.readerIndex(), end - buf.readerIndex(), StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, gprmc);
if (!parser.matches()) {
return null;
}
DateBuilder dateBuilder = new DateBuilder()
.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
return position;
}
示例13: decode
import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < MINIMUM_LENGTH) {
return null;
}
if (isBinary(buf)) {
int length;
switch (buf.toString(buf.readerIndex(), 4, StandardCharsets.US_ASCII)) {
case "+ACK":
length = buf.getUnsignedByte(buf.readerIndex() + 6);
break;
case "+INF":
case "+BNF":
length = buf.getUnsignedShort(buf.readerIndex() + 7);
break;
case "+HBD":
length = buf.getUnsignedByte(buf.readerIndex() + 5);
break;
case "+CRD":
case "+BRD":
length = buf.getUnsignedShort(buf.readerIndex() + 6);
break;
default:
length = buf.getUnsignedShort(buf.readerIndex() + 9);
break;
}
if (buf.readableBytes() >= length) {
return buf.readBytes(length);
}
} else {
int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '$');
if (endIndex < 0) {
endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
}
if (endIndex > 0) {
ChannelBuffer frame = buf.readBytes(endIndex - buf.readerIndex());
buf.readByte(); // delimiter
return frame;
}
}
return null;
}