本文整理汇总了Java中javax.websocket.Decoder类的典型用法代码示例。如果您正苦于以下问题:Java Decoder类的具体用法?Java Decoder怎么用?Java Decoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Decoder类属于javax.websocket包,在下文中一共展示了Decoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import javax.websocket.Decoder; //导入依赖的package包/类
@Override
protected Object decode(ByteBuffer message) throws DecodeException {
for (Decoder decoder : decoders) {
if (decoder instanceof Binary) {
if (((Binary<?>) decoder).willDecode(message)) {
return ((Binary<?>) decoder).decode(message);
}
} else {
byte[] array = new byte[message.limit() - message.position()];
message.get(array);
ByteArrayInputStream bais = new ByteArrayInputStream(array);
try {
return ((BinaryStream<?>) decoder).decode(bais);
} catch (IOException ioe) {
throw new DecodeException(message, sm.getString(
"pojoMessageHandlerWhole.decodeIoFail"), ioe);
}
}
}
return null;
}
示例2: decode
import javax.websocket.Decoder; //导入依赖的package包/类
@Override
protected Object decode(String message) throws DecodeException {
// Handle primitives
if (primitiveType != null) {
return Util.coerceToType(primitiveType, message);
}
// Handle full decoders
for (Decoder decoder : decoders) {
if (decoder instanceof Text) {
if (((Text<?>) decoder).willDecode(message)) {
return ((Text<?>) decoder).decode(message);
}
} else {
StringReader r = new StringReader(message);
try {
return ((TextStream<?>) decoder).decode(r);
} catch (IOException ioe) {
throw new DecodeException(message, sm.getString(
"pojoMessageHandlerWhole.decodeIoFail"), ioe);
}
}
}
return null;
}
示例3: DefaultServerEndpointConfig
import javax.websocket.Decoder; //导入依赖的package包/类
DefaultServerEndpointConfig(Class<?> endpointClass,
String path,
List<String> subprotocols,
List<Extension> extensions,
List<Class<? extends Encoder>> encoders,
List<Class<? extends Decoder>> decoders,
ServerEndpointConfig.Configurator serverEndpointConfigurator) {
this.path = path;
this.endpointClass = endpointClass;
this.subprotocols = Collections.unmodifiableList(subprotocols);
this.extensions = Collections.unmodifiableList(extensions);
this.encoders = Collections.unmodifiableList(encoders);
this.decoders = Collections.unmodifiableList(decoders);
if (serverEndpointConfigurator == null) {
this.serverEndpointConfigurator = ServerEndpointConfig.Configurator.fetchContainerDefaultConfigurator();
} else{
this.serverEndpointConfigurator = serverEndpointConfigurator;
}
}
示例4: decode
import javax.websocket.Decoder; //导入依赖的package包/类
@Override
protected Object decode(ByteBuffer message) throws DecodeException {
for (Decoder decoder : decoders) {
if (decoder instanceof Binary) {
if (((Binary<?>) decoder).willDecode(message)) {
return ((Binary<?>) decoder).decode(message);
}
} else {
byte[] array = new byte[message.limit() - message.position()];
message.get(array);
ByteArrayInputStream bais = new ByteArrayInputStream(array);
try {
return ((BinaryStream<?>) decoder).decode(bais);
} catch (IOException ioe) {
throw new DecodeException(message, sm.getString("pojoMessageHandlerWhole.decodeIoFail"), ioe);
}
}
}
return null;
}
示例5: decode
import javax.websocket.Decoder; //导入依赖的package包/类
@Override
protected Object decode(String message) throws DecodeException {
// Handle primitives
if (primitiveType != null) {
return Util.coerceToType(primitiveType, message);
}
// Handle full decoders
for (Decoder decoder : decoders) {
if (decoder instanceof Text) {
if (((Text<?>) decoder).willDecode(message)) {
return ((Text<?>) decoder).decode(message);
}
} else {
StringReader r = new StringReader(message);
try {
return ((TextStream<?>) decoder).decode(r);
} catch (IOException ioe) {
throw new DecodeException(message, sm.getString("pojoMessageHandlerWhole.decodeIoFail"), ioe);
}
}
}
return null;
}
示例6: createConfiguredServerEndpoint
import javax.websocket.Decoder; //导入依赖的package包/类
private ConfiguredServerEndpoint createConfiguredServerEndpoint(String selectedProtocol,
List<Extension> selectedExtensions, Endpoint endpoint, HttpServletRequest servletRequest) {
String path = servletRequest.getRequestURI(); // shouldn't matter
ServerEndpointRegistration endpointRegistration = new ServerEndpointRegistration(path, endpoint);
endpointRegistration.setSubprotocols(Arrays.asList(selectedProtocol));
endpointRegistration.setExtensions(selectedExtensions);
EncodingFactory encodingFactory = new EncodingFactory(
Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap());
try {
return (endpointConstructorWithEndpointFactory ?
endpointConstructor.newInstance(endpointRegistration,
new EndpointInstanceFactory(endpoint), null, encodingFactory, null) :
endpointConstructor.newInstance(endpointRegistration,
new EndpointInstanceFactory(endpoint), null, encodingFactory));
}
catch (Exception ex) {
throw new HandshakeFailureException("Failed to instantiate ConfiguredServerEndpoint", ex);
}
}
示例7: createWsServerEndpointConfig
import javax.websocket.Decoder; //导入依赖的package包/类
protected ServerEndpointConfig createWsServerEndpointConfig(ServletContext servletContext) {
final List<Class<? extends Encoder>> encoders = new LinkedList<>();
final List<Class<? extends Decoder>> decoders = new LinkedList<>();
encoders.add(OutputMessageEncoder.class);
decoders.add(InputMessageDecoder.class);
final ServerEndpointConfig endpointConfig =
create(CheWSConnection.class, websocketContext + websocketEndPoint)
.configurator(createConfigurator())
.encoders(encoders)
.decoders(decoders)
.build();
endpointConfig
.getUserProperties()
.put(EVERREST_PROCESSOR_ATTRIBUTE, getEverrestProcessor(servletContext));
endpointConfig
.getUserProperties()
.put(EVERREST_CONFIG_ATTRIBUTE, getEverrestConfiguration(servletContext));
endpointConfig.getUserProperties().put(EXECUTOR_ATTRIBUTE, createExecutor(servletContext));
return endpointConfig;
}
示例8: createEventbusServerEndpointConfig
import javax.websocket.Decoder; //导入依赖的package包/类
protected ServerEndpointConfig createEventbusServerEndpointConfig(ServletContext servletContext) {
final List<Class<? extends Encoder>> encoders = new LinkedList<>();
final List<Class<? extends Decoder>> decoders = new LinkedList<>();
encoders.add(OutputMessageEncoder.class);
decoders.add(InputMessageDecoder.class);
final ServerEndpointConfig endpointConfig =
create(CheWSConnection.class, websocketContext + eventBusEndPoint)
.configurator(createConfigurator())
.encoders(encoders)
.decoders(decoders)
.build();
endpointConfig
.getUserProperties()
.put(EVERREST_PROCESSOR_ATTRIBUTE, getEverrestProcessor(servletContext));
endpointConfig
.getUserProperties()
.put(EVERREST_CONFIG_ATTRIBUTE, getEverrestConfiguration(servletContext));
endpointConfig.getUserProperties().put(EXECUTOR_ATTRIBUTE, createExecutor(servletContext));
return endpointConfig;
}
示例9: buildServerEndpointConfig
import javax.websocket.Decoder; //导入依赖的package包/类
@Override
protected ServerEndpointConfig buildServerEndpointConfig(String path, WebSocket wseAnnotation,
Class<?> annotatedClass, String[] subProtocols,
List<Class<? extends Encoder>> encoderClasses,
List<Class<? extends Decoder>> decoderClasses) {
int max = getMaxSessions(annotatedClass);
if (max != -1) {
TyrusServerEndpointConfig.Builder builder =
TyrusServerEndpointConfig.Builder
.create(annotatedClass, path)
.encoders(encoderClasses)
.decoders(decoderClasses)
.subprotocols(Arrays.asList(subProtocols));
if (!ServerEndpointConfig.Configurator.class.equals(wseAnnotation.configurator())) {
builder = builder.configurator(Injections.getOrCreate(manager, wseAnnotation.configurator()));
}
return builder.maxSessions(max).build();
}
return super.buildServerEndpointConfig(path, wseAnnotation, annotatedClass,
subProtocols, encoderClasses, decoderClasses);
}
示例10: PojoEndpointClient
import javax.websocket.Decoder; //导入依赖的package包/类
public PojoEndpointClient(Object pojo,
List<Class<? extends Decoder>> decoders) throws DeploymentException {
setPojo(pojo);
setMethodMapping(
new PojoMethodMapping(pojo.getClass(), decoders, null));
setPathParameters(Collections.<String,String>emptyMap());
}
示例11: matchDecoders
import javax.websocket.Decoder; //导入依赖的package包/类
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target,
EndpointConfig endpointConfig, boolean binary) {
DecoderMatch decoderMatch = matchDecoders(target, endpointConfig);
if (binary) {
if (decoderMatch.getBinaryDecoders().size() > 0) {
return decoderMatch.getBinaryDecoders();
}
} else if (decoderMatch.getTextDecoders().size() > 0) {
return decoderMatch.getTextDecoders();
}
return null;
}
示例12: DefaultServerEndpointConfig
import javax.websocket.Decoder; //导入依赖的package包/类
DefaultServerEndpointConfig(
Class<?> endpointClass, String path,
List<String> subprotocols, List<Extension> extensions,
List<Class<? extends Encoder>> encoders,
List<Class<? extends Decoder>> decoders,
Configurator serverEndpointConfigurator) {
this.endpointClass = endpointClass;
this.path = path;
this.subprotocols = subprotocols;
this.extensions = extensions;
this.encoders = encoders;
this.decoders = decoders;
this.serverEndpointConfigurator = serverEndpointConfigurator;
}
示例13: init
import javax.websocket.Decoder; //导入依赖的package包/类
@PostConstruct
public void init(){
try {
WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
List<Class<? extends Decoder>> decoders = new ArrayList<>();
decoders.add(MeetupRSVPJSONDecoder.class);
session = webSocketContainer.connectToServer(new MeetupRSVPsWebSocketClient(),
ClientEndpointConfig.Builder.create().decoders(decoders).build(),
URI.create("ws://stream.meetup.com/2/rsvps"));
} catch (DeploymentException | IOException ex) {
Logger.getLogger(MeetupRSVPsWebSocketClientSession.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例14: matchDecoders
import javax.websocket.Decoder; //导入依赖的package包/类
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target, EndpointConfig endpointConfig,
boolean binary) {
DecoderMatch decoderMatch = matchDecoders(target, endpointConfig);
if (binary) {
if (decoderMatch.getBinaryDecoders().size() > 0) {
return decoderMatch.getBinaryDecoders();
}
} else if (decoderMatch.getTextDecoders().size() > 0) {
return decoderMatch.getTextDecoders();
}
return null;
}
示例15: DefaultServerEndpointConfig
import javax.websocket.Decoder; //导入依赖的package包/类
DefaultServerEndpointConfig(Class<?> endpointClass, String path, List<String> subprotocols,
List<Extension> extensions, List<Class<? extends Encoder>> encoders,
List<Class<? extends Decoder>> decoders, Configurator serverEndpointConfigurator) {
this.endpointClass = endpointClass;
this.path = path;
this.subprotocols = subprotocols;
this.extensions = extensions;
this.encoders = encoders;
this.decoders = decoders;
this.serverEndpointConfigurator = serverEndpointConfigurator;
}