List of usage examples for io.netty.buffer ByteBuf toString
public abstract String toString(Charset charset);
From source file:com.turo.pushy.apns.ApnsClientHandler.java
License:Open Source License
@Override public void onGoAwayRead(final ChannelHandlerContext context, final int lastStreamId, final long errorCode, final ByteBuf debugData) { log.info("Received GOAWAY from APNs server: {}", debugData.toString(StandardCharsets.UTF_8)); }
From source file:com.turo.pushy.apns.auth.AuthenticationToken.java
License:Open Source License
static String encodeUnpaddedBase64UrlString(final byte[] data) { final ByteBuf wrappedString = Unpooled.wrappedBuffer(data); final ByteBuf encodedString = Base64.encode(wrappedString, Base64Dialect.URL_SAFE); final String encodedUnpaddedString = encodedString.toString(StandardCharsets.US_ASCII).replace("=", ""); wrappedString.release();/*from w ww. j a v a2 s . c om*/ encodedString.release(); return encodedUnpaddedString; }
From source file:com.turo.pushy.apns.server.ParsingMockApnsServerListenerAdapter.java
License:Open Source License
private static ApnsPushNotification parsePushNotification(final Http2Headers headers, final ByteBuf payload) { final UUID apnsId; {/*from w w w . j a v a2 s . com*/ final CharSequence apnsIdSequence = headers.get(APNS_ID_HEADER); UUID apnsIdFromHeaders; try { apnsIdFromHeaders = apnsIdSequence != null ? FastUUID.parseUUID(apnsIdSequence) : null; } catch (final IllegalArgumentException e) { log.error("Failed to parse `apns-id` header: {}", apnsIdSequence, e); apnsIdFromHeaders = null; } apnsId = apnsIdFromHeaders; } final String deviceToken; { final CharSequence pathSequence = headers.get(Http2Headers.PseudoHeaderName.PATH.value()); if (pathSequence != null) { final String pathString = pathSequence.toString(); deviceToken = pathString.startsWith(APNS_PATH_PREFIX) ? pathString.substring(APNS_PATH_PREFIX.length()) : null; } else { deviceToken = null; } } final String topic; { final CharSequence topicSequence = headers.get(APNS_TOPIC_HEADER); topic = topicSequence != null ? topicSequence.toString() : null; } final DeliveryPriority deliveryPriority; { final Integer priorityCode = headers.getInt(APNS_PRIORITY_HEADER); DeliveryPriority priorityFromCode; try { priorityFromCode = priorityCode != null ? DeliveryPriority.getFromCode(priorityCode) : null; } catch (final IllegalArgumentException e) { priorityFromCode = null; } deliveryPriority = priorityFromCode; } final Date expiration; { final Integer expirationTimestamp = headers.getInt(APNS_EXPIRATION_HEADER); expiration = expirationTimestamp != null ? new Date(expirationTimestamp * 1000) : null; } final String collapseId; { final CharSequence collapseIdSequence = headers.get(APNS_COLLAPSE_ID_HEADER); collapseId = collapseIdSequence != null ? collapseIdSequence.toString() : null; } // One challenge here is that we don't actually know that a push notification is valid, even if it's // accepted by the push notification handler (since we might be using a handler that blindly accepts // everything), so we want to use a lenient push notification implementation. return new LenientApnsPushNotification(deviceToken, topic, payload != null ? payload.toString(StandardCharsets.UTF_8) : null, expiration, deliveryPriority, collapseId, apnsId); }
From source file:com.uber.tchannel.messages.JSONSerializer.java
License:Open Source License
@Override public String decodeEndpoint(ByteBuf arg1) { String endpoint = arg1.toString(CharsetUtil.UTF_8); return endpoint; }
From source file:com.uber.tchannel.messages.JSONSerializer.java
License:Open Source License
@Override public Map<String, String> decodeHeaders(ByteBuf arg2) { String headerJSON = arg2.toString(CharsetUtil.UTF_8); Map<String, String> headers = null; if (headerJSON != null && !headerJSON.isEmpty() && !headerJSON.equals("\"\"")) { headers = new Gson().fromJson(headerJSON, HEADER_TYPE); }//from www . ja v a2s .c o m return (headers == null) ? new HashMap<String, String>() : headers; }
From source file:com.uber.tchannel.messages.JSONSerializer.java
License:Open Source License
@Override public <T> T decodeBody(ByteBuf arg3, Class<T> bodyType) { String bodyJSON = arg3.toString(CharsetUtil.UTF_8); return GSON.fromJson(bodyJSON, bodyType); }
From source file:com.uber.tchannel.messages.JSONSerializerTest.java
License:Open Source License
@Test public void testEncodeEmptyHeaders() throws Exception { Map<String, String> emptyHeaders = new HashMap<>(); ByteBuf encodedHeaders = serializer.encodeHeaders(emptyHeaders); assertEquals("{}", encodedHeaders.toString(CharsetUtil.UTF_8)); }
From source file:com.vmware.xenon.common.http.netty.NettyHttpEventStreamHandler.java
License:Open Source License
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception { ByteBuf rawEvent = (ByteBuf) super.decode(ctx, buffer); if (rawEvent == null) { return null; }/*from ww w . j a v a 2 s . co m*/ String serializedEvent = rawEvent.toString(ServerSentEventConverter.ENCODING_CHARSET); rawEvent.release(); ServerSentEvent event = ServerSentEventConverter.INSTANCE.deserialize(serializedEvent); EventStreamMessage message = new EventStreamMessage(); message.event = event; return message; }
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameEncoderTest.java
License:Open Source License
@Test public void testTestEncode() throws Exception { VantageSerialFrameEncoder encoder = new VantageSerialFrameEncoder(); com.whizzosoftware.hobson.davisvantage.api.command.Test test = new com.whizzosoftware.hobson.davisvantage.api.command.Test(); ByteBuf buf = Unpooled.buffer(); encoder.encode(null, test, buf);/*from w ww. j a v a 2s. c om*/ assertEquals("TEST\n", buf.toString(Charset.forName("UTF8"))); }
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameEncoderTest.java
License:Open Source License
@Test public void testVersion() throws Exception { VantageSerialFrameEncoder encoder = new VantageSerialFrameEncoder(); VersionRequest ver = new VersionRequest(); ByteBuf buf = Unpooled.buffer(); encoder.encode(null, ver, buf);//from ww w . j av a 2 s .com assertEquals("VER\n", buf.toString(Charset.forName("UTF8"))); }