當前位置: 首頁>>代碼示例>>Java>>正文


Java DecodeException類代碼示例

本文整理匯總了Java中javax.websocket.DecodeException的典型用法代碼示例。如果您正苦於以下問題:Java DecodeException類的具體用法?Java DecodeException怎麽用?Java DecodeException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DecodeException類屬於javax.websocket包,在下文中一共展示了DecodeException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decode

import javax.websocket.DecodeException; //導入依賴的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;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:22,代碼來源:PojoMessageHandlerWholeBinary.java

示例2: decode

import javax.websocket.DecodeException; //導入依賴的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;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:25,代碼來源:PojoMessageHandlerWholeText.java

示例3: decode

import javax.websocket.DecodeException; //導入依賴的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;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:21,代碼來源:PojoMessageHandlerWholeBinary.java

示例4: decode

import javax.websocket.DecodeException; //導入依賴的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;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:24,代碼來源:PojoMessageHandlerWholeText.java

示例5: from_byteBuffer

import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void from_byteBuffer() throws IOException, DecodeException {
	final String input = "MESSAGE\ndestination:wonderland\nsubscription:a\ncontent-length:4\n\nbody\u0000";
	final Frame frame;
	try (InputStream is = new ByteArrayInputStream(input.getBytes()))  {
		frame = Encoding.from(ByteBuffer.wrap(input.getBytes(UTF_8)));
	}
	assertEquals(Command.MESSAGE, frame.command());
	assertEquals(4, frame.headers().size());

	// ensure header order is maintained
	final Iterator<Entry<Header, List<String>>> itr = frame.headers().entrySet().iterator();
	final Entry<Header, List<String>> header2 = itr.next();
	assertEquals("destination", header2.getKey().value());
	assertEquals(1, header2.getValue().size());
	assertEquals("wonderland", header2.getValue().get(0));
	final Entry<Header, List<String>> header1 = itr.next();
	assertEquals("subscription", header1.getKey().value());
	assertEquals(1, header1.getValue().size());
	assertEquals("a", header1.getValue().get(0));
	assertEquals(ByteBuffer.wrap("body".getBytes(StandardCharsets.UTF_8)), frame.body().get());
}
 
開發者ID:dansiviter,項目名稱:cito,代碼行數:23,代碼來源:EncodingTest.java

示例6: decode

import javax.websocket.DecodeException; //導入依賴的package包/類
/**
 * @see javax.websocket.Decoder.Text#decode(String)
 * @see javax.websocket.Decoder.Binary#decode(ByteBuffer)
 */
@SuppressWarnings("unchecked")
public T decode(M message) throws DecodeException {
	try {
		return (T) getConversionService().convert(message, getMessageType(), getType());
	}
	catch (ConversionException ex) {
		if (message instanceof String) {
			throw new DecodeException((String) message,
					"Unable to decode websocket message using ConversionService", ex);
		}
		if (message instanceof ByteBuffer) {
			throw new DecodeException((ByteBuffer) message,
					"Unable to decode websocket message using ConversionService", ex);
		}
		throw ex;
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:ConvertingEncoderDecoderSupport.java

示例7: decode

import javax.websocket.DecodeException; //導入依賴的package包/類
@Override
public Message decode(String textMessage) throws DecodeException {

  Message msg = null;
  JsonObject obj = Json.createReader(new StringReader(textMessage)).
          readObject();

  try {
    DecoderHelper helper = new DecoderHelper(obj);
    msg = helper.getMessage();
    msg.init(obj);
  } catch (ApplicationException e) {
    logger.log(Level.SEVERE, e.getMessage(), e);
  }
  return msg;
}
 
開發者ID:hopshadoop,項目名稱:hopsworks,代碼行數:17,代碼來源:MessageDecoder.java

示例8: decode

import javax.websocket.DecodeException; //導入依賴的package包/類
/**
 * Decodes the message
 * @param message
 * @return
 * @throws DecodeException 
 */
@Override
public AbstractCommand decode(String message) throws DecodeException {
   logger.log(Level.INFO, "Decoding: {0}", message);
   JsonObject struct;
   try (JsonReader rdr = Json.createReader(new StringReader(message))) {
        struct = rdr.readObject();
   }   
   String type = struct.getString("type");
   CommandTypes cmdType = CommandTypes.valueOf(type);
    try {
        AbstractCommand cmd = (AbstractCommand)cmdType.getCommandClass().newInstance();
        cmd.decode(struct);
        return cmd;
    } catch (InstantiationException | IllegalAccessException ex) {
        Logger.getLogger(CommandMessageDecoder.class.getName()).log(Level.SEVERE, null, ex);
        throw new DecodeException(message,"Could not be decoded - invalid type.");
    }
}
 
開發者ID:rcuprak,項目名稱:actionbazaar,代碼行數:25,代碼來源:CommandMessageDecoder.java

示例9: testReadyNoSavedRoom

import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void testReadyNoSavedRoom(@Mocked RoomMediator room) throws DecodeException {

    ClientMediator mediator = new ClientMediator(nexus, drain, userId, signedJwt);

    String msgTxt = "ready,{}";
    RoutedMessage message = new RoutedMessage(msgTxt);
    System.out.println(message);

    new Expectations() {{
        nexus.join(mediator, null, "");
    }};

    mediator.ready(message);

    new Verifications() {{
        nexus.join(mediator, null, ""); times = 1;
        drain.send((RoutedMessage) any); times = 0;
    }};
}
 
開發者ID:gameontext,項目名稱:gameon-mediator,代碼行數:21,代碼來源:ClientMediatorTest.java

示例10: testReadyUserName

import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void testReadyUserName(@Mocked RoomMediator room) throws DecodeException {

    ClientMediator mediator = new ClientMediator(nexus, drain, userId, signedJwt);

    String msgTxt = "ready,{\"username\":\"TinyJamFilledMuffin\"}";
    RoutedMessage message = new RoutedMessage(msgTxt);
    System.out.println(message);

    new Expectations() {{
        nexus.join(mediator, null, "");
    }};

    mediator.ready(message);

    new Verifications() {{
        nexus.join(mediator, null, ""); times = 1;
        drain.send((RoutedMessage) any); times = 0;
    }};
}
 
開發者ID:gameontext,項目名稱:gameon-mediator,代碼行數:21,代碼來源:ClientMediatorTest.java

示例11: testReadyZeroBookmark

import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void testReadyZeroBookmark(@Mocked RoomMediator room) throws DecodeException {

    ClientMediator mediator = new ClientMediator(nexus, drain, userId, signedJwt);

    String msgTxt = "ready,{\"bookmark\":0}";
    RoutedMessage message = new RoutedMessage(msgTxt);
    System.out.println(message);

    new Expectations() {{
        nexus.join(mediator, null, "0");
    }};

    mediator.ready(message);

    new Verifications() {{
        nexus.join(mediator, null, "0"); times = 1;
        drain.send((RoutedMessage) any); times = 0;
    }};
}
 
開發者ID:gameontext,項目名稱:gameon-mediator,代碼行數:21,代碼來源:ClientMediatorTest.java

示例12: testReadySavedRoom

import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void testReadySavedRoom(@Mocked RoomMediator room) throws DecodeException {

    ClientMediator mediator = new ClientMediator(nexus, drain, userId, signedJwt);

    String msgTxt = "ready,{\"roomId\": \"roomId\",\"bookmark\": \"id\"}";
    RoutedMessage message = new RoutedMessage(msgTxt);
    System.out.println(message);

    new Expectations() {{
        nexus.join(mediator, roomId, "id");
    }};

    mediator.ready(message);

    new Verifications() {{
        nexus.join(mediator, roomId, "id"); times = 1;
        drain.send((RoutedMessage) any); times = 0;
    }};
}
 
開發者ID:gameontext,項目名稱:gameon-mediator,代碼行數:21,代碼來源:ClientMediatorTest.java

示例13: decode

import javax.websocket.DecodeException; //導入依賴的package包/類
@Override
public WebSocketMessage decode(ByteBuffer buffer) throws DecodeException {
    try {
        MessageProtos.Message decMsg =
            MessageProtos.Message.parseFrom(buffer.array());
        WebSocketMessage msg = new WebSocketMessage()
            .withEvent(decMsg.getEvent())
            .withChannel(decMsg.getChannel())
            .withFrom(decMsg.getFrom())
            .withId(decMsg.getId())
            .withPayload(decMsg.getData().toByteArray());
        return msg;
    }
    catch (IOException e) {
        throw new DecodeException(buffer, "Error parsing buffer.", e);
    }
}
 
開發者ID:cabol,項目名稱:west-java-client,代碼行數:18,代碼來源:WebSocketMessageCodec.java

示例14: shouldParseBasicObject

import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void shouldParseBasicObject() throws DecodeException {
    // given
    String validJson = "{'from' : 'Alice',"//
            + "'to' : 'Bob',"//
            + "'signal' : 'join',"//
            + "'content' : 'something'}";

    // when
    Message result = decoder.decode(validJson);

    // then
    assertNotNull(result);
    assertThat(result.getFrom(), is("Alice"));
    assertThat(result.getTo(), is("Bob"));
    assertThat(result.getSignal(), is("join"));
    assertThat(result.getContent(), is("something"));
}
 
開發者ID:mslosarz,項目名稱:nextrtc-signaling-server,代碼行數:19,代碼來源:MessageDecoderTest.java

示例15: shouldParseAlmostEmptyObject

import javax.websocket.DecodeException; //導入依賴的package包/類
@Test
public void shouldParseAlmostEmptyObject() throws DecodeException {
    // given
    String validJson = "{'signal' : 'join',"//
            + "'content' : 'something'}";

    // when
    Message result = decoder.decode(validJson);

    // then
    assertNotNull(result);
    assertThat(result.getFrom(), is(EMPTY));
    assertThat(result.getTo(), is(EMPTY));
    assertThat(result.getSignal(), is("join"));
    assertThat(result.getContent(), is("something"));
}
 
開發者ID:mslosarz,項目名稱:nextrtc-signaling-server,代碼行數:17,代碼來源:MessageDecoderTest.java


注:本文中的javax.websocket.DecodeException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。