List of usage examples for io.netty.util CharsetUtil US_ASCII
Charset US_ASCII
To view the source code for io.netty.util CharsetUtil US_ASCII.
Click Source Link
From source file:nl.thijsalders.spigotproxy.haproxy.HAProxyMessageDecoder.java
License:Apache License
@Override protected final void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { // determine the specification version if (version == -1) { if ((version = findVersion(in)) == -1) { return; }// w ww . java 2s . co m } ByteBuf decoded; if (version == 1) { decoded = decodeLine(ctx, in); } else { decoded = decodeStruct(ctx, in); } if (decoded != null) { finished = true; try { if (version == 1) { out.add(HAProxyMessage.decodeHeader(decoded.toString(CharsetUtil.US_ASCII))); } else { out.add(HAProxyMessage.decodeHeader(decoded)); } } catch (HAProxyProtocolException e) { fail(ctx, null, e); } } }
From source file:openbns.commons.net.codec.sts.HttpHeaderEntity.java
License:Apache License
public HttpHeaderEntity(String name) { this.name = name; hash = StsHeaders.hash(name); bytes = name.getBytes(CharsetUtil.US_ASCII); }
From source file:openbns.commons.net.codec.sts.StsMethod.java
License:Apache License
private StsMethod(String name, boolean bytes) { if (name == null) { throw new NullPointerException("name"); }//from w ww .jav a 2 s. c o m name = name.trim(); if (name.isEmpty()) { throw new IllegalArgumentException("empty name"); } for (int i = 0; i < name.length(); i++) { if (Character.isISOControl(name.charAt(i)) || Character.isWhitespace(name.charAt(i))) { throw new IllegalArgumentException("invalid character in name"); } } this.name = name; if (bytes) { this.bytes = name.getBytes(CharsetUtil.US_ASCII); } else { this.bytes = null; } }
From source file:openbns.commons.net.codec.sts.StsResponseStatus.java
License:Apache License
private StsResponseStatus(int code, String reasonPhrase, boolean bytes) { if (code < 0) { throw new IllegalArgumentException("code: " + code + " (expected: 0+)"); }/*from w ww . j a v a 2 s.co m*/ if (reasonPhrase == null) { throw new NullPointerException("reasonPhrase"); } for (int i = 0; i < reasonPhrase.length(); i++) { char c = reasonPhrase.charAt(i); // Check prohibited characters. switch (c) { case '\n': case '\r': throw new IllegalArgumentException( "reasonPhrase contains one of the following prohibited characters: " + "\\r\\n: " + reasonPhrase); } } this.code = code; this.reasonPhrase = reasonPhrase; if (bytes) { this.bytes = (code + " " + reasonPhrase).getBytes(CharsetUtil.US_ASCII); } else { this.bytes = null; } }
From source file:org.acmsl.queryj.debugging.netty.NettyServerChannelHandler.java
License:Open Source License
/** * {@inheritDoc}//from www .jav a 2s.c o m */ @Override public void channelRead(@NotNull final ChannelHandlerContext ctx, @NotNull final Object msg) { try { @NotNull final ByteBuf buffer = (ByteBuf) msg; @NotNull final byte[] aux = new byte[buffer.readableBytes()]; for (int index = 0; index < aux.length; index++) { aux[index] = buffer.readByte(); } // System.out.println("Received " + new String(aux, CharsetUtil.US_ASCII)); processCommand(new String(aux, CharsetUtil.US_ASCII), this.m__Listener); } finally { ReferenceCountUtil.release(msg); } final ChannelFuture future = ctx.writeAndFlush("ACK"); future.addListener(channelFuture -> { System.out.println("Closing context"); ctx.close(); }); /* try { ctx.channel().closeFuture().sync(); } catch (@NotNull final InterruptedException ex) { }*/ }
From source file:org.apache.tajo.util.StringUtils.java
License:Apache License
/** * Check Seven-bit ASCII/* w ww. j a va2 s . c o m*/ */ public static boolean isPureAscii(String v) { // get thread-safe encoder CharsetEncoder asciiEncoder = CharsetUtil.getEncoder(CharsetUtil.US_ASCII); return asciiEncoder.canEncode(v); }
From source file:org.atmosphere.nettosphere.extra.FlashPolicyServerHandler.java
License:Apache License
private ByteBuf getPolicyFileContents() throws Exception { return Unpooled.copiedBuffer("<?xml version=\"1.0\"?>" + NEWLINE + "<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">" + NEWLINE + "" + NEWLINE + "<!-- Policy file for xmlsocket://socks.example.com -->" + NEWLINE + "<cross-domain-policy> " + NEWLINE + "" + NEWLINE + " <!-- This is a master socket policy file -->" + NEWLINE + " <!-- No other socket policies on the host will be permitted -->" + NEWLINE + " <site-control permitted-cross-domain-policies=\"master-only\"/>" + NEWLINE + "" + NEWLINE + " <!-- Instead of setting to-ports=\"*\", administrator's can use ranges and commas -->" + NEWLINE + " <allow-access-from domain=\"*\" to-ports=\"8080\" />" + NEWLINE + "" + NEWLINE + "</cross-domain-policy>" + NEWLINE, CharsetUtil.US_ASCII); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecode() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();//ww w . j ava 2 s .co m assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); ch.finish(); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeNulDelimiter() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.nulDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\0second\0third", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();/*from w ww .j a va 2s.c om*/ assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); ch.finish(); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); }
From source file:org.graylog2.inputs.transports.netty.LenientDelimiterBasedFrameDecoderTest.java
License:Open Source License
@Test public void testDecodeAndEmitLastLine() throws Exception { EmbeddedChannel ch = new EmbeddedChannel( new LenientDelimiterBasedFrameDecoder(8192, true, Delimiters.lineDelimiter())); ch.writeInbound(Unpooled.copiedBuffer("first\r\nsecond\nthird", CharsetUtil.US_ASCII)); ByteBuf buf = ch.readInbound();/* w ww . j a va2s . c o m*/ assertEquals("first", buf.toString(CharsetUtil.US_ASCII)); ByteBuf buf2 = ch.readInbound(); assertEquals("second", buf2.toString(CharsetUtil.US_ASCII)); // Close channel assertTrue(ch.finish()); ByteBuf buf3 = ch.readInbound(); assertEquals("third", buf3.toString(CharsetUtil.US_ASCII)); assertNull(ch.readInbound()); assertFalse(ch.finish()); ReferenceCountUtil.release(ch.readInbound()); buf.release(); buf2.release(); buf3.release(); }