use of org.java_websocket.framing.FramedataImpl1 in project quorrabot by GloriousEggroll.
the class Draft_75 method translateRegularFrame.
protected List<Framedata> translateRegularFrame(ByteBuffer buffer) throws InvalidDataException {
while (buffer.hasRemaining()) {
byte newestByte = buffer.get();
if (newestByte == START_OF_FRAME) {
// Beginning of Frame
if (readingState) {
throw new InvalidFrameException("unexpected START_OF_FRAME");
}
readingState = true;
} else if (newestByte == END_OF_FRAME) {
// End of Frame
if (!readingState) {
throw new InvalidFrameException("unexpected END_OF_FRAME");
}
// START_OF_FRAME, thus we will send 'null' as the sent message.
if (this.currentFrame != null) {
currentFrame.flip();
FramedataImpl1 curframe = new FramedataImpl1();
curframe.setPayload(currentFrame);
curframe.setFin(true);
curframe.setOptcode(Opcode.TEXT);
readyframes.add(curframe);
this.currentFrame = null;
buffer.mark();
}
readingState = false;
} else if (readingState) {
// Regular frame data, add to current frame buffer //TODO This code is very expensive and slow
if (currentFrame == null) {
currentFrame = createBuffer();
} else if (!currentFrame.hasRemaining()) {
currentFrame = increaseBuffer(currentFrame);
}
currentFrame.put(newestByte);
} else {
return null;
}
}
// if no error occurred this block will be reached
/*if( readingState ) {
checkAlloc(currentFrame.position()+1);
}*/
List<Framedata> frames = readyframes;
readyframes = new LinkedList<Framedata>();
return frames;
}
use of org.java_websocket.framing.FramedataImpl1 in project quorrabot by GloriousEggroll.
the class Draft_75 method createFrames.
@Override
public List<Framedata> createFrames(String text, boolean mask) {
FrameBuilder frame = new FramedataImpl1();
try {
frame.setPayload(ByteBuffer.wrap(Charsetfunctions.utf8Bytes(text)));
} catch (InvalidDataException e) {
throw new NotSendableException(e);
}
frame.setFin(true);
frame.setOptcode(Opcode.TEXT);
frame.setTransferemasked(mask);
return Collections.singletonList((Framedata) frame);
}
Aggregations