org.apache.flink.shaded.netty4.io.netty.util.CharsetUtil Java Examples

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.util.CharsetUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testReaderIndexLargerThanWriterIndex() {
    String content1 = "hello";
    String content2 = "world";
    int length = content1.length() + content2.length();
    ByteBuf buffer = newBuffer(length);
    buffer.setIndex(0, 0);
    buffer.writeCharSequence(content1, CharsetUtil.US_ASCII);
    buffer.markWriterIndex();
    buffer.skipBytes(content1.length());
    buffer.writeCharSequence(content2, CharsetUtil.US_ASCII);
    buffer.skipBytes(content2.length());
    assertTrue(buffer.readerIndex() <= buffer.writerIndex());

    try {
        buffer.resetWriterIndex();
    } finally {
        buffer.release();
    }
}
 
Example #2
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testReaderIndexLargerThanWriterIndex() {
    String content1 = "hello";
    String content2 = "world";
    int length = content1.length() + content2.length();
    ByteBuf buffer = newBuffer(length);
    buffer.setIndex(0, 0);
    buffer.writeCharSequence(content1, CharsetUtil.US_ASCII);
    buffer.markWriterIndex();
    buffer.skipBytes(content1.length());
    buffer.writeCharSequence(content2, CharsetUtil.US_ASCII);
    buffer.skipBytes(content2.length());
    assertTrue(buffer.readerIndex() <= buffer.writerIndex());

    try {
        buffer.resetWriterIndex();
    } finally {
        buffer.release();
    }
}
 
Example #3
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testReaderIndexLargerThanWriterIndex() {
    String content1 = "hello";
    String content2 = "world";
    int length = content1.length() + content2.length();
    ByteBuf buffer = newBuffer(length);
    buffer.setIndex(0, 0);
    buffer.writeCharSequence(content1, CharsetUtil.US_ASCII);
    buffer.markWriterIndex();
    buffer.skipBytes(content1.length());
    buffer.writeCharSequence(content2, CharsetUtil.US_ASCII);
    buffer.skipBytes(content2.length());
    assertTrue(buffer.readerIndex() <= buffer.writerIndex());

    try {
        buffer.resetWriterIndex();
    } finally {
        buffer.release();
    }
}
 
Example #4
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testSetGetCharSequence(Charset charset) {
    ByteBuf buf = newBuffer(1024);
    CharBuffer sequence = CharsetUtil.US_ASCII.equals(charset)
            ? ASCII_CHARS : EXTENDED_ASCII_CHARS;
    int bytes = buf.setCharSequence(1, sequence, charset);
    assertEquals(sequence, CharBuffer.wrap(buf.getCharSequence(1, bytes, charset)));
    buf.release();
}
 
Example #5
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testToString() {
    ByteBuf copied = copiedBuffer("Hello, World!", CharsetUtil.ISO_8859_1);
    buffer.clear();
    buffer.writeBytes(copied);
    assertEquals("Hello, World!", buffer.toString(CharsetUtil.ISO_8859_1));
    copied.release();
}
 
Example #6
Source File: MesosArtifactServer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a simple  error response message.
 *
 * @param ctx    The channel context to write the response to.
 * @param status The response status.
 */
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
	FullHttpResponse response = new DefaultFullHttpResponse(
		HTTP_1_1, status, Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8));
	HttpHeaders.setHeader(response, CONTENT_TYPE, "text/plain; charset=UTF-8");

	// close the connection as soon as the error message is sent.
	ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example #7
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testWriteReadCharSequence(Charset charset) {
    ByteBuf buf = newBuffer(1024);
    CharBuffer sequence = CharsetUtil.US_ASCII.equals(charset)
            ? ASCII_CHARS : EXTENDED_ASCII_CHARS;
    buf.writerIndex(1);
    int bytes = buf.writeCharSequence(sequence, charset);
    buf.readerIndex(1);
    assertEquals(sequence, CharBuffer.wrap(buf.readCharSequence(bytes, charset)));
    buf.release();
}
 
Example #8
Source File: HttpTestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
	LOG.debug("Received {}", msg);

	if (msg instanceof HttpResponse) {
		HttpResponse response = (HttpResponse) msg;

		currentStatus = response.getStatus();
		currentType = response.headers().get(HttpHeaders.Names.CONTENT_TYPE);
		currentLocation = response.headers().get(HttpHeaders.Names.LOCATION);

		if (HttpHeaders.isTransferEncodingChunked(response)) {
			LOG.debug("Content is chunked");
		}
	}

	if (msg instanceof HttpContent) {
		HttpContent content = (HttpContent) msg;

		// Add the content
		currentContent += content.content().toString(CharsetUtil.UTF_8);

		// Finished with this
		if (content instanceof LastHttpContent) {
			responses.add(new SimpleHttpResponse(currentStatus, currentType,
					currentContent, currentLocation));

			currentStatus = null;
			currentType = null;
			currentLocation = null;
			currentContent = "";

			ctx.close();
		}
	}
}
 
Example #9
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testToString() {
    ByteBuf copied = copiedBuffer("Hello, World!", CharsetUtil.ISO_8859_1);
    buffer.clear();
    buffer.writeBytes(copied);
    assertEquals("Hello, World!", buffer.toString(CharsetUtil.ISO_8859_1));
    copied.release();
}
 
Example #10
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
	LOG.debug("Received {}", msg);

	if (msg instanceof HttpResponse) {
		HttpResponse response = (HttpResponse) msg;

		currentStatus = response.getStatus();
		currentType = response.headers().get(HttpHeaders.Names.CONTENT_TYPE);
		currentLocation = response.headers().get(HttpHeaders.Names.LOCATION);

		if (HttpHeaders.isTransferEncodingChunked(response)) {
			LOG.debug("Content is chunked");
		}
	}

	if (msg instanceof HttpContent) {
		HttpContent content = (HttpContent) msg;

		// Add the content
		currentContent += content.content().toString(CharsetUtil.UTF_8);

		// Finished with this
		if (content instanceof LastHttpContent) {
			responses.add(new SimpleHttpResponse(currentStatus, currentType,
					currentContent, currentLocation));

			currentStatus = null;
			currentType = null;
			currentLocation = null;
			currentContent = "";

			ctx.close();
		}
	}
}
 
Example #11
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void testSetGetCharSequence(Charset charset) {
    ByteBuf buf = newBuffer(1024);
    CharBuffer sequence = CharsetUtil.US_ASCII.equals(charset)
            ? ASCII_CHARS : EXTENDED_ASCII_CHARS;
    int bytes = buf.setCharSequence(1, sequence, charset);
    assertEquals(sequence, CharBuffer.wrap(buf.getCharSequence(1, bytes, charset)));
    buf.release();
}
 
Example #12
Source File: MesosArtifactServer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a simple  error response message.
 *
 * @param ctx    The channel context to write the response to.
 * @param status The response status.
 */
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
	FullHttpResponse response = new DefaultFullHttpResponse(
		HTTP_1_1, status, Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8));
	HttpHeaders.setHeader(response, CONTENT_TYPE, "text/plain; charset=UTF-8");

	// close the connection as soon as the error message is sent.
	ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example #13
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
private void testWriteReadCharSequence(Charset charset) {
    ByteBuf buf = newBuffer(1024);
    CharBuffer sequence = CharsetUtil.US_ASCII.equals(charset)
            ? ASCII_CHARS : EXTENDED_ASCII_CHARS;
    buf.writerIndex(1);
    int bytes = buf.writeCharSequence(sequence, charset);
    buf.readerIndex(1);
    assertEquals(sequence, CharBuffer.wrap(buf.readCharSequence(bytes, charset)));
    buf.release();
}
 
Example #14
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void testWriteReadCharSequence(Charset charset) {
    ByteBuf buf = newBuffer(1024);
    CharBuffer sequence = CharsetUtil.US_ASCII.equals(charset)
            ? ASCII_CHARS : EXTENDED_ASCII_CHARS;
    buf.writerIndex(1);
    int bytes = buf.writeCharSequence(sequence, charset);
    buf.readerIndex(1);
    assertEquals(sequence, CharBuffer.wrap(buf.readCharSequence(bytes, charset)));
    buf.release();
}
 
Example #15
Source File: MesosArtifactServer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Writes a simple  error response message.
 *
 * @param ctx    The channel context to write the response to.
 * @param status The response status.
 */
private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
	FullHttpResponse response = new DefaultFullHttpResponse(
		HTTP_1_1, status, Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8));
	HttpHeaders.setHeader(response, CONTENT_TYPE, "text/plain; charset=UTF-8");

	// close the connection as soon as the error message is sent.
	ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example #16
Source File: HttpTestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
	LOG.debug("Received {}", msg);

	if (msg instanceof HttpResponse) {
		HttpResponse response = (HttpResponse) msg;

		currentStatus = response.getStatus();
		currentType = response.headers().get(HttpHeaders.Names.CONTENT_TYPE);
		currentLocation = response.headers().get(HttpHeaders.Names.LOCATION);

		if (HttpHeaders.isTransferEncodingChunked(response)) {
			LOG.debug("Content is chunked");
		}
	}

	if (msg instanceof HttpContent) {
		HttpContent content = (HttpContent) msg;

		// Add the content
		currentContent += content.content().toString(CharsetUtil.UTF_8);

		// Finished with this
		if (content instanceof LastHttpContent) {
			responses.add(new SimpleHttpResponse(currentStatus, currentType,
					currentContent, currentLocation));

			currentStatus = null;
			currentType = null;
			currentLocation = null;
			currentContent = "";

			ctx.close();
		}
	}
}
 
Example #17
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalReferenceCountException.class)
public void testSetIso88591CharSequenceAfterRelease() {
    testSetCharSequenceAfterRelease0(CharsetUtil.ISO_8859_1);
}
 
Example #18
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWriteReadIso88591CharSequence() {
    testWriteReadCharSequence(CharsetUtil.ISO_8859_1);
}
 
Example #19
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWriteReadUtf8CharSequence() {
    testWriteReadCharSequence(CharsetUtil.UTF_8);
}
 
Example #20
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testWriteReadUsAsciiCharSequence() {
    testWriteReadCharSequence(CharsetUtil.US_ASCII);
}
 
Example #21
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetUsAsciiCharSequence() {
    testSetGetCharSequence(CharsetUtil.US_ASCII);
}
 
Example #22
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetUtf16CharSequence() {
    testSetGetCharSequence(CharsetUtil.UTF_16);
}
 
Example #23
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetIso88591CharSequence() {
    testSetGetCharSequence(CharsetUtil.ISO_8859_1);
}
 
Example #24
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetUtf8CharSequence() {
    testSetGetCharSequence(CharsetUtil.UTF_8);
}
 
Example #25
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testSetUsAsciiCharSequence() {
    testSetGetCharSequence(CharsetUtil.US_ASCII);
}
 
Example #26
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testSetUtf16CharSequenceNoExpand() {
    testSetCharSequenceNoExpand(CharsetUtil.UTF_16);
}
 
Example #27
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testSetIso88591CharSequenceNoExpand() {
    testSetCharSequenceNoExpand(CharsetUtil.ISO_8859_1);
}
 
Example #28
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testSetUtf8CharSequenceNoExpand() {
    testSetCharSequenceNoExpand(CharsetUtil.UTF_8);
}
 
Example #29
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testSetUsAsciiCharSequenceNoExpand() {
    testSetCharSequenceNoExpand(CharsetUtil.US_ASCII);
}
 
Example #30
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test(expected = IndexOutOfBoundsException.class)
public void testSetUtf8CharSequenceNoExpand() {
    testSetCharSequenceNoExpand(CharsetUtil.UTF_8);
}