use of org.eclipse.jetty.websocket.common.frames.DataFrame in project jetty.project by eclipse.
the class WebSocketRemoteEndpoint method sendPartialString.
@Override
public void sendPartialString(String fragment, boolean isLast) throws IOException {
boolean first = lockMsg(MsgType.PARTIAL_TEXT);
try {
if (LOG.isDebugEnabled()) {
LOG.debug("sendPartialString({}, {})", fragment, isLast);
}
DataFrame frame = first ? new TextFrame() : new ContinuationFrame();
frame.setPayload(BufferUtil.toBuffer(fragment, StandardCharsets.UTF_8));
frame.setFin(isLast);
blockingWrite(frame);
} finally {
if (isLast)
unlockMsg(MsgType.PARTIAL_TEXT);
}
}
use of org.eclipse.jetty.websocket.common.frames.DataFrame in project jetty.project by eclipse.
the class CompressExtension method forwardIncoming.
protected void forwardIncoming(Frame frame, ByteAccumulator accumulator) {
DataFrame newFrame = new DataFrame(frame);
// Unset RSV1 since it's not compressed anymore.
newFrame.setRsv1(false);
ByteBuffer buffer = getBufferPool().acquire(accumulator.getLength(), false);
try {
BufferUtil.flipToFill(buffer);
accumulator.transferTo(buffer);
newFrame.setPayload(buffer);
nextIncomingFrame(newFrame);
} finally {
getBufferPool().release(buffer);
}
}
use of org.eclipse.jetty.websocket.common.frames.DataFrame in project jetty.project by eclipse.
the class ParserTest method testParseCase6_2_3.
/**
* Similar to the server side 6.2.3 testcase. Lots of small 1 byte UTF8 Text frames, representing 1 overall text message.
*/
@Test
public void testParseCase6_2_3() {
String utf8 = "Hello-습@쎟쎤쎼쎠쎡-UTF-8!!";
byte[] msg = StringUtil.getUtf8Bytes(utf8);
List<WebSocketFrame> send = new ArrayList<>();
int textCount = 0;
int continuationCount = 0;
int len = msg.length;
boolean continuation = false;
byte[] mini;
for (int i = 0; i < len; i++) {
DataFrame frame = null;
if (continuation) {
frame = new ContinuationFrame();
continuationCount++;
} else {
frame = new TextFrame();
textCount++;
}
mini = new byte[1];
mini[0] = msg[i];
frame.setPayload(ByteBuffer.wrap(mini));
boolean isLast = (i >= (len - 1));
frame.setFin(isLast);
send.add(frame);
continuation = true;
}
send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
ByteBuffer completeBuf = UnitGenerator.generate(send);
UnitParser parser = new UnitParser();
IncomingFramesCapture capture = new IncomingFramesCapture();
parser.setIncomingFramesHandler(capture);
parser.parse(completeBuf);
capture.assertErrorCount(0);
capture.assertHasFrame(OpCode.TEXT, textCount);
capture.assertHasFrame(OpCode.CONTINUATION, continuationCount);
capture.assertHasFrame(OpCode.CLOSE, 1);
}
use of org.eclipse.jetty.websocket.common.frames.DataFrame in project jetty.project by eclipse.
the class TestABCase6 method fragmentText.
/**
* Split a message byte array into a series of fragments (frames + continuations) of 1 byte message contents each.
* @param frames the frames
* @param msg the message
*/
protected void fragmentText(List<WebSocketFrame> frames, byte[] msg) {
int len = msg.length;
boolean continuation = false;
byte[] mini;
for (int i = 0; i < len; i++) {
DataFrame frame = null;
if (continuation) {
frame = new ContinuationFrame();
} else {
frame = new TextFrame();
}
mini = new byte[1];
mini[0] = msg[i];
frame.setPayload(ByteBuffer.wrap(mini));
boolean isLast = (i >= (len - 1));
frame.setFin(isLast);
frames.add(frame);
continuation = true;
}
}
use of org.eclipse.jetty.websocket.common.frames.DataFrame in project jetty.project by eclipse.
the class WebSocketRemoteEndpoint method sendPartialBytes.
@Override
public void sendPartialBytes(ByteBuffer fragment, boolean isLast) throws IOException {
boolean first = lockMsg(MsgType.PARTIAL_BINARY);
try {
if (LOG.isDebugEnabled()) {
LOG.debug("sendPartialBytes({}, {})", BufferUtil.toDetailString(fragment), isLast);
}
DataFrame frame = first ? new BinaryFrame() : new ContinuationFrame();
frame.setPayload(fragment);
frame.setFin(isLast);
blockingWrite(frame);
} finally {
if (isLast)
unlockMsg(MsgType.PARTIAL_BINARY);
}
}
Aggregations