当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.wrap方法代码示例

本文整理汇总了Java中org.apache.mina.common.ByteBuffer.wrap方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.wrap方法的具体用法?Java ByteBuffer.wrap怎么用?Java ByteBuffer.wrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.common.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.wrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
@Override
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        final byte[] input = ((MaplePacket) message).getBytes();
        final byte[] unencrypted = new byte[input.length];
        System.arraycopy(input, 0, unencrypted, 0, input.length);

        final byte[] ret = new byte[unencrypted.length + 4];

        final byte[] header = client.getSendCrypto().getPacketHeader(unencrypted.length);
        synchronized(client.getSendCrypto()){
            MapleCustomEncryption.encryptData(unencrypted);
            client.getSendCrypto().crypt(unencrypted);

            System.arraycopy(header, 0, ret, 0, 4);
            System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);

            final ByteBuffer out_buffer = ByteBuffer.wrap(ret);
            out.write(out_buffer);
        }
    } else { // no client object created yet, send unencrypted (hello)
            out.write(ByteBuffer.wrap(((MaplePacket) message).getBytes()));
    }
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:27,代码来源:MaplePacketEncoder.java

示例2: testRead

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void testRead() {
    try {
        XMLLightweightParser parser = new XMLLightweightParser("UTF-8");
        String xml1 = "<ab>\u1000</a";
        String xml2 = "b>";
        ByteBuffer buffer1 = ByteBuffer.wrap(xml1.getBytes("UTF-8"));
        ByteBuffer buffer2 = ByteBuffer.wrap(xml2.getBytes("UTF-8"));

        parser.read(buffer1);
        parser.read(buffer2);

        if (!parser.areThereMsgs())
            Assert.fail("No messages found");

        String msgs[] = parser.getMsgs();
        if (msgs.length > 1) {
            Assert.fail("More than one message found");
        }
        else {
            Assert.assertEquals(xml1 + xml2, msgs[0]);
        }
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire-connectionmanager,代码行数:26,代码来源:XMLLightweightParserTest.java

示例3: testToByteArray

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void testToByteArray() {
    byte[] in = "Hello World".getBytes();
    ByteBuffer bb = ByteBuffer.wrap(in);

    byte[] out = MinaConverter.toByteArray(bb);

    for (int i = 0; i < out.length; i++) {
        assertEquals(in[i], out[i]);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:MinaConverterTest.java

示例4: testToString

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void testToString() throws UnsupportedEncodingException {
    String in = "Hello World \u4f60\u597d";
    ByteBuffer bb = ByteBuffer.wrap(in.getBytes("UTF-8"));
    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");

    String out = MinaConverter.toString(bb, exchange);
    assertEquals("Hello World \u4f60\u597d", out);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:MinaConverterTest.java

示例5: testToStringTwoTimes

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void testToStringTwoTimes() throws UnsupportedEncodingException {
    String in = "Hello World \u4f60\u597d";
    ByteBuffer bb = ByteBuffer.wrap(in.getBytes("UTF-8"));
    Exchange exchange = new DefaultExchange(new DefaultCamelContext());
    exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");

    String out = MinaConverter.toString(bb, exchange);
    assertEquals("Hello World \u4f60\u597d", out);

    // should be possible to convert to string without affecting the ByteBuffer
    out = MinaConverter.toString(bb, exchange);
    assertEquals("Hello World \u4f60\u597d", out);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:MinaConverterTest.java

示例6: testToInputStream

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void testToInputStream() throws Exception {
    byte[] in = "Hello World".getBytes();
    ByteBuffer bb = ByteBuffer.wrap(in);

    InputStream is = MinaConverter.toInputStream(bb);
    for (byte b : in) {
        int out = is.read();
        assertEquals(b, out);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:11,代码来源:MinaConverterTest.java

示例7: writeMapToData

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
@ Override
protected void writeMapToData()
{
    BBEncoder encoder = new BBEncoder(1024);
    encoder.writeMap(_map);
    _data = ByteBuffer.wrap(encoder.segment());
}
 
开发者ID:wso2,项目名称:andes,代码行数:8,代码来源:AMQPEncodedMapMessage.java

示例8: setText

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void setText(String text) throws JMSException
{
    checkWritable();

    clearBody();
    try
    {
        if (text != null)
        {
            final String encoding = getEncoding();
            if (encoding == null || encoding.equalsIgnoreCase("UTF-8"))
            {
                _data = ByteBuffer.wrap(Strings.toUTF8(text));
                setEncoding("UTF-8");
            }
            else
            {
                _data = ByteBuffer.wrap(text.getBytes(encoding));
            }
            _data.position(_data.limit());
            _changedData=true;
        }
        _decodedValue = text;
    }
    catch (UnsupportedEncodingException e)
    {
        // should never occur
        JMSException jmse = new JMSException("Unable to decode text data");
        jmse.setLinkedException(e);
        jmse.initCause(e);
        throw jmse;
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:34,代码来源:JMSTextMessage.java

示例9: create010MessageWithBody

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
protected AbstractJMSMessage create010MessageWithBody(long messageNbr, MessageProperties msgProps,
                                                      DeliveryProperties deliveryProps,  
                                                      java.nio.ByteBuffer body) throws AMQException
{
    ByteBuffer data;
    final boolean debug = _logger.isDebugEnabled();


    if (body != null)
    {
        data = ByteBuffer.wrap(body);
    }
    else // body == null
    {
        data = ByteBuffer.allocate(0);
    }

    if (debug)
    {
        _logger.debug("Creating message from buffer with position=" + data.position() + " and remaining=" + data
                .remaining());
    }
    AMQMessageDelegate delegate = new AMQMessageDelegate_0_10(msgProps, deliveryProps, messageNbr);

    AbstractJMSMessage message = createMessage(delegate, data);
    return message;
}
 
开发者ID:wso2,项目名称:andes,代码行数:28,代码来源:AbstractJMSMessageFactory.java

示例10: toNioByteBuffer

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public java.nio.ByteBuffer toNioByteBuffer()
{
    final java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate((int) getSize());

    ByteBuffer buf = ByteBuffer.wrap(buffer);
    writePayload(buf);    
    buffer.flip();
    return buffer;
}
 
开发者ID:wso2,项目名称:andes,代码行数:10,代码来源:AMQDataBlock.java

示例11: decodeUpToContentType

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
private void decodeUpToContentType()
{
    ByteBuffer buffer = ByteBuffer.wrap(_encodedForm);

    if ((_propertyFlags & (CONTENT_TYPE_MASK)) != 0)
    {
        _contentType = EncodingUtils.readAMQShortString(buffer);
    }

    _decodedContentType = true;
}
 
开发者ID:wso2,项目名称:andes,代码行数:12,代码来源:BasicContentHeaderProperties.java

示例12: testWeirdoContent

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public void testWeirdoContent() throws Exception {
    final String[] testStanzas =
    {
            "<?xml version=\"1.0\"?>",
            "<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\"jabber:client\" to=\"localhost\" >",
            "<emppartag test=\"1\"/>",
            "<cdatatest><![CDATA[just<ignore everything& >>here<<<<< /> />]]&gt;]]></cdatatest>",
            "<esctest param=\"1\"> this \" is / a test /> test /> </esctest>",
            "<comtest>this <!-- comment --> is a comment</comtest>",
            "<emptag/>",
            "<iq type=\"get\" id=\"aab1a\" ><query xmlns=\"jabber:iq:roster\"/> <tag> text </tag></iq>",
            "<iq type=\"get\" id=\"aab1a\" ><query xmlns=\"jabber:iq:roster\"/> </iq>",
            "<message><body xmlns=\"http://idetalk.com/namespace\">12\"</body></message>" ,
            "<message to=\"[email protected]\" id=\"XRk8p-X\"><body> /> /> </body></message>" ,
    };
    String testMsg = "";
    for(String s : testStanzas) {
        testMsg += s;
    }
    ByteBuffer mybuffer = ByteBuffer.wrap(testMsg.getBytes());
    parser.read(mybuffer);

    String[] msgs = parser.getMsgs();
    for(int i = 0; i < testStanzas.length; i++) {
        assertTrue(i < msgs.length);
        assertEquals(testStanzas[i], msgs[i]);
    }
}
 
开发者ID:igniterealtime,项目名称:Openfire-connectionmanager,代码行数:29,代码来源:XMLLightweightParserTest.java

示例13: decodeContent

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
/**
 * Method to decode content of a single message into text
 *
 * @param amqMessage     the message of which content need to be decoded
 * @param messageContent the byte array of message content to be decoded
 * @return A string array representing the decoded message content
 * @throws MBeanException
 */
private String[] decodeContent(AMQMessage amqMessage, byte[] messageContent) throws MBeanException {

    try {
        //get encoding
        String encoding = amqMessage.getMessageHeader().getEncoding();
        if (encoding == null) {
            encoding = "UTF-8";
        }
        //get mime type of message
        String mimeType = amqMessage.getMessageHeader().getMimeType();
        // setting default mime type
        if (StringUtils.isBlank(mimeType)) {
            mimeType = MIME_TYPE_TEXT_PLAIN;
        }
        //create message content to readable text from ByteBuffer
        ByteBuffer wrapMsgContent = ByteBuffer.wrap(messageContent);
        String content[] = new String[2];
        String summaryMsg = "";
        String wholeMsg = "";

        //get TextMessage content to display
        if (mimeType.equals(MIME_TYPE_TEXT_PLAIN) || mimeType.equals(MIMI_TYPE_TEXT_XML)) {
            wholeMsg = extractTextMessageContent(wrapMsgContent, encoding);
            //get ByteMessage content to display
        } else if (mimeType.equals(MIME_TYPE_APPLICATION_OCTET_STREAM)) {
            wholeMsg = extractByteMessageContent(wrapMsgContent, messageContent);
            //get ObjectMessage content to display
        } else if (mimeType.equals(MIME_TYPE_APPLICATION_JAVA_OBJECT_STREAM)) {
            wholeMsg = "This Operation is Not Supported!";
            //get StreamMessage content to display
        } else if (mimeType.equals(MIME_TYPE_JMS_STREAM_MESSAGE)) {
            wholeMsg = extractStreamMessageContent(wrapMsgContent, encoding);
            //get MapMessage content to display
        } else if (mimeType.equals(MIME_TYPE_AMQP_MAP) || mimeType.equals(MIME_TYPE_JMS_MAP_MESSAGE)) {
            wholeMsg = extractMapMessageContent(wrapMsgContent);
        }
        //trim content to summary and whole message
        if (wholeMsg.length() >= CHARACTERS_TO_SHOW) {
            summaryMsg = wholeMsg.substring(0, CHARACTERS_TO_SHOW);
        } else {
            summaryMsg = wholeMsg;
        }
        if (wholeMsg.length() > MESSAGE_DISPLAY_LENGTH_MAX) {
            wholeMsg = wholeMsg.substring(0, MESSAGE_DISPLAY_LENGTH_MAX - 3) +
                    DISPLAY_CONTINUATION + DISPLAY_LENGTH_EXCEEDED;
        }
        content[0] = summaryMsg;
        content[1] = wholeMsg;
        return content;
    } catch (CharacterCodingException exception) {
        throw new MBeanException(exception, "Error occurred in browse queue.");
    }
}
 
开发者ID:wso2,项目名称:andes,代码行数:62,代码来源:QueueManagementInformationMBean.java

示例14: convertToBody

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public AMQBody convertToBody(java.nio.ByteBuffer buf)
{
    return new ContentBody(ByteBuffer.wrap(buf));
}
 
开发者ID:wso2,项目名称:andes,代码行数:5,代码来源:MethodConverter_0_9.java

示例15: decodeBuffer

import org.apache.mina.common.ByteBuffer; //导入方法依赖的package包/类
public ArrayList<AMQDataBlock> decodeBuffer(java.nio.ByteBuffer buf) throws AMQFrameDecodingException, AMQProtocolVersionException
{

    // get prior remaining data from accumulator
    ArrayList<AMQDataBlock> dataBlocks = new ArrayList<AMQDataBlock>();
    ByteBuffer msg;
    // if we have a session buffer, append data to that otherwise
    // use the buffer read from the network directly
    if( _remainingBuf != null )
    {
        _remainingBuf.put(buf);
        _remainingBuf.flip();
        msg = _remainingBuf;
    }
    else
    {
        msg = ByteBuffer.wrap(buf);
    }
    
    if (_expectProtocolInitiation  
        || (firstDecode
            && (msg.remaining() > 0)
            && (msg.get(msg.position()) == (byte)'A')))
    {
        if (_piDecoder.decodable(msg.buf()))
        {
            dataBlocks.add(new ProtocolInitiation(msg.buf()));
        }
    }
    else
    {
        boolean enoughData = true;
        while (enoughData)
        {
            int pos = msg.position();

            enoughData = _dataBlockDecoder.decodable(msg);
            msg.position(pos);
            if (enoughData)
            {
                dataBlocks.add(_dataBlockDecoder.createAndPopulateFrame(_bodyFactory, msg));
            }
            else
            {
                _remainingBuf = SIMPLE_BYTE_BUFFER_ALLOCATOR.allocate(msg.remaining(), false);
                _remainingBuf.setAutoExpand(true);
                _remainingBuf.put(msg);
            }
        }
    }
    if(firstDecode && dataBlocks.size() > 0)
    {
        firstDecode = false;
    }
    return dataBlocks;
}
 
开发者ID:wso2,项目名称:andes,代码行数:57,代码来源:AMQDecoder.java


注:本文中的org.apache.mina.common.ByteBuffer.wrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。