use of org.eclipse.jetty.websocket.jsr356.samples.Fruit in project jetty.project by eclipse.
the class BadDualDecoder method decode.
@Override
public Fruit decode(String s) throws DecodeException {
Pattern pat = Pattern.compile("([^|]*)|([^|]*)");
Matcher mat = pat.matcher(s);
if (!mat.find()) {
throw new DecodeException(s, "Unable to find Fruit reference encoded in text message");
}
Fruit fruit = new Fruit();
fruit.name = mat.group(1);
fruit.color = mat.group(2);
return fruit;
}
use of org.eclipse.jetty.websocket.jsr356.samples.Fruit in project jetty.project by eclipse.
the class BadDualDecoder method decode.
@Override
public Fruit decode(ByteBuffer bytes) throws DecodeException {
try {
int id = bytes.get(bytes.position());
if (id != FruitBinaryEncoder.FRUIT_ID_BYTE) {
// not a binary fruit object
throw new DecodeException(bytes, "Not an encoded Binary Fruit object");
}
Fruit fruit = new Fruit();
fruit.name = getUTF8String(bytes);
fruit.color = getUTF8String(bytes);
return fruit;
} catch (BufferUnderflowException e) {
throw new DecodeException(bytes, "Unable to read Fruit from binary message", e);
}
}
Aggregations