Source:
<code>public void onMessage(byte[] data, int offset, int length) { byte version = data[offset]; byte type; byte flags; switch (version) { case 1: type = data[offset + 1]; flags = data[offset + 2]; break; case 2: type = data[offset + 2]; flags = data[offset + 3]; break; default: log.error("ignoring message with unsupported encoding version {}", version); return; } Kind kind; try { kind = Kind.fromBinaryType(type); } catch (IllegalArgumentException iae) { log.error("ignoring message with unsupported type {}", type); return; } String channelName = new String(data, offset + BINARY_PREAMBLE_LENGTH, MAX_CHANNEL_NAME_LENGTH); <START> byte[] body = Arrays.copyOfRange(data, offset + BINARY_HEADER_LENGTH, offset + length); <END> boolean compressed = (flags & (1 << 0)) != 0; if (compressed) { ByteArrayInputStream bais = new ByteArrayInputStream(body); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { GZIPInputStream gzip = new GZIPInputStream(bais); try { IOUtils.copy(gzip, baos); } finally { IOUtils.closeQuietly(gzip); } body = baos.toByteArray(); } catch (IOException ioe) { log.error("failed to process message", ioe); return; } finally { IOUtils.closeQuietly(baos); IOUtils.closeQuietly(bais); } } boolean json = (flags & (1 << 1)) != 0; if (json) { onMessage(new String(body, UTF_8)); return; } Map<String, Object> message = null; switch (kind) { case DATA: message = decodeBinaryDataMessage(version, body); break; default: log.error("ignoring message with unsupported binary encoding of kind {}", kind); return; } if (message != null) { TransportChannel channel = channels.get(channelName); if (channel != null && !channel.isClosed()) { try { StreamMessage streamMessage = new StreamMessage("data", null, objectMapper.writeValueAsString(message)); channel.offer(streamMessage); } catch (JsonProcessingException ex) { log.error("failed to process message", ex); } } else { log.debug("ignoring message. channel not found {}", channelName); } } }</code><technical_language>add charset do require ascii channel names</technical_language>

Target:
public void onMessage(byte[] data, int offset, int length) { byte version = data[offset]; byte type; byte flags; switch (version) { case 1: type = data[offset + 1]; flags = data[offset + 2]; break; case 2: type = data[offset + 2]; flags = data[offset + 3]; break; default: log.error("ignoring message with unsupported encoding version {}", version); return; } Kind kind; try { kind = Kind.fromBinaryType(type); } catch (IllegalArgumentException iae) { log.error("ignoring message with unsupported type {}", type); return; } String channelName = new String(data, offset + BINARY_PREAMBLE_LENGTH, MAX_CHANNEL_NAME_LENGTH, ASCII); byte[] body = Arrays.copyOfRange(data, offset + BINARY_HEADER_LENGTH, offset + length); boolean compressed = (flags & (1 << 0)) != 0; if (compressed) { ByteArrayInputStream bais = new ByteArrayInputStream(body); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { GZIPInputStream gzip = new GZIPInputStream(bais); try { IOUtils.copy(gzip, baos); } finally { IOUtils.closeQuietly(gzip); } body = baos.toByteArray(); } catch (IOException ioe) { log.error("failed to process message", ioe); return; } finally { IOUtils.closeQuietly(baos); IOUtils.closeQuietly(bais); } } boolean json = (flags & (1 << 1)) != 0; if (json) { onMessage(new String(body, UTF_8)); return; } Map<String, Object> message = null; switch (kind) { case DATA: message = decodeBinaryDataMessage(version, body); break; default: log.error("ignoring message with unsupported binary encoding of kind {}", kind); return; } if (message != null) { TransportChannel channel = channels.get(channelName); if (channel != null && !channel.isClosed()) { try { StreamMessage streamMessage = new StreamMessage("data", null, objectMapper.writeValueAsString(message)); channel.offer(streamMessage); } catch (JsonProcessingException ex) { log.error("failed to process message", ex); } } else { log.debug("ignoring message. channel not found {}", channelName); } } }