Fixing compilation issue surrounding deprecated Utf8PartialBuilder
This commit is contained in:
parent
01a5415796
commit
7a3f9bfeb7
|
@ -242,9 +242,7 @@ public class Utf8AppendableTest
|
|||
|
||||
utf8.append(TypeUtil.fromHexString(seq1));
|
||||
String ret1 = utf8.takePartialString();
|
||||
|
||||
String ret2 = utf8.takePartialString();
|
||||
|
||||
utf8.append(TypeUtil.fromHexString(seq2));
|
||||
String ret3 = utf8.takePartialString();
|
||||
|
||||
|
|
|
@ -20,27 +20,31 @@ package org.eclipse.jetty.websocket.common.message;
|
|||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.eclipse.jetty.util.Utf8StringBuilder;
|
||||
import org.eclipse.jetty.websocket.api.FrameCallback;
|
||||
import org.eclipse.jetty.websocket.api.extensions.Frame;
|
||||
import org.eclipse.jetty.websocket.common.util.Utf8PartialBuilder;
|
||||
|
||||
public class PartialTextMessageSink implements MessageSink
|
||||
{
|
||||
private final Function<PartialTextMessage, Void> onTextFunction;
|
||||
private final Utf8PartialBuilder utf8Partial;
|
||||
private final Utf8StringBuilder utf8Partial;
|
||||
|
||||
public PartialTextMessageSink(Function<PartialTextMessage, Void> function)
|
||||
{
|
||||
this.onTextFunction = function;
|
||||
this.utf8Partial = new Utf8PartialBuilder();
|
||||
this.utf8Partial = new Utf8StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(Frame frame, FrameCallback callback)
|
||||
{
|
||||
String partialText = utf8Partial.toPartialString(frame.getPayload());
|
||||
if(frame.hasPayload())
|
||||
{
|
||||
utf8Partial.append(frame.getPayload());
|
||||
}
|
||||
try
|
||||
{
|
||||
String partialText = utf8Partial.takePartialString();
|
||||
onTextFunction.apply(new PartialTextMessage(partialText,frame.isFin()));
|
||||
callback.succeed();
|
||||
}
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.common.util;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.Utf8Appendable;
|
||||
import org.eclipse.jetty.util.Utf8StringBuilder;
|
||||
|
||||
/**
|
||||
* Similar in scope to the {@link Utf8StringBuilder}, but allowing partially constructed Strings without throwing
|
||||
* Exceptions for incomplete UTF8 sequences.
|
||||
* <p>
|
||||
* A call to {@link #toPartialString(ByteBuffer)} will return the section of the String from the start to the last
|
||||
* completed UTF8 sequence. Leaving incomplete sequences for a subsequent call to complete.
|
||||
*/
|
||||
@Deprecated
|
||||
public class Utf8PartialBuilder
|
||||
{
|
||||
private final Utf8StringBuilder utf8 = new Utf8StringBuilder();
|
||||
|
||||
public Utf8PartialBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
public String toPartialString(ByteBuffer buf)
|
||||
{
|
||||
if (buf == null)
|
||||
{
|
||||
// no change, return empty
|
||||
return "";
|
||||
}
|
||||
utf8.append(buf);
|
||||
return utf8.takePartialString();
|
||||
}
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2017 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.websocket.tests;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.Hex;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.websocket.common.util.Utf8PartialBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test partial UTF8 String sequence building.
|
||||
*/
|
||||
public class Utf8PartialBuilderTest
|
||||
{
|
||||
private ByteBuffer toByteBuffer(String hexStr)
|
||||
{
|
||||
return ByteBuffer.wrap(Hex.asByteArray(hexStr));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartial_UnsplitCodepoint()
|
||||
{
|
||||
Utf8PartialBuilder utf8 = new Utf8PartialBuilder();
|
||||
|
||||
String seq1 = "Hello-\uC2B5@\uC39F\uC3A4";
|
||||
String seq2 = "\uC3BC\uC3A0\uC3A1-UTF-8!!";
|
||||
|
||||
String ret1 = utf8.toPartialString(BufferUtil.toBuffer(seq1,StandardCharsets.UTF_8));
|
||||
String ret2 = utf8.toPartialString(BufferUtil.toBuffer(seq2,StandardCharsets.UTF_8));
|
||||
|
||||
assertThat("Seq1",ret1,is(seq1));
|
||||
assertThat("Seq2",ret2,is(seq2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartial_SplitCodepoint()
|
||||
{
|
||||
Utf8PartialBuilder utf8 = new Utf8PartialBuilder();
|
||||
|
||||
String seq1 = "48656C6C6F2DEC8AB540EC8E9FEC8E";
|
||||
String seq2 = "A4EC8EBCEC8EA0EC8EA12D5554462D382121";
|
||||
|
||||
String ret1 = utf8.toPartialString(toByteBuffer(seq1));
|
||||
String ret2 = utf8.toPartialString(toByteBuffer(seq2));
|
||||
|
||||
assertThat("Seq1",ret1,is("Hello-\uC2B5@\uC39F"));
|
||||
assertThat("Seq2",ret2,is("\uC3A4\uC3BC\uC3A0\uC3A1-UTF-8!!"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartial_SplitCodepoint_WithNoBuf()
|
||||
{
|
||||
Utf8PartialBuilder utf8 = new Utf8PartialBuilder();
|
||||
|
||||
String seq1 = "48656C6C6F2DEC8AB540EC8E9FEC8E";
|
||||
String seq2 = "A4EC8EBCEC8EA0EC8EA12D5554462D382121";
|
||||
|
||||
String ret1 = utf8.toPartialString(toByteBuffer(seq1));
|
||||
String ret2 = utf8.toPartialString(BufferUtil.EMPTY_BUFFER);
|
||||
String ret3 = utf8.toPartialString(toByteBuffer(seq2));
|
||||
|
||||
assertThat("Seq1",ret1,is("Hello-\uC2B5@\uC39F"));
|
||||
assertThat("Seq2",ret2,is(""));
|
||||
assertThat("Seq3",ret3,is("\uC3A4\uC3BC\uC3A0\uC3A1-UTF-8!!"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue