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


Java ChannelBuffer.setBytes方法代碼示例

本文整理匯總了Java中org.jboss.netty.buffer.ChannelBuffer.setBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelBuffer.setBytes方法的具體用法?Java ChannelBuffer.setBytes怎麽用?Java ChannelBuffer.setBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jboss.netty.buffer.ChannelBuffer的用法示例。


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

示例1: onGuestScienceData

import org.jboss.netty.buffer.ChannelBuffer; //導入方法依賴的package包/類
public void onGuestScienceData(Message msg) {
     String apkFullName = "", topic = "";
     // Check to make sure the message contains the full name of the guest science apk
     if (!msg.getData().containsKey("apkFullName")) {
         mLogger.error(LOG_TAG, "Guest science message doesn't contain the full apk name and " +
                 "will not be processed!");
         return;
     }

     apkFullName = msg.getData().getString("apkFullName");

     if (msg.getData().containsKey("topic")) {
         topic = msg.getData().getString("topic");
         if (topic.length() > 32) {
             mLogger.error(LOG_TAG, "The topic string in the guest science message is too " +
                     "big to send to the ground so the message will not be sent. Length must " +
                     " be no more than 32 characters not " + topic.length() + ".");
             return;
         }
     }

     byte[] data = null;
     if (!msg.getData().containsKey("data")) {
         mLogger.error(LOG_TAG, "Guest science message doesn't contain data and will not be " +
                 "processed.");
         return;
     } else {
         data = msg.getData().getByteArray("data");
         if (data.length > 2048) {
             mLogger.error(LOG_TAG, "The data in the guest science message is too big to send " +
                     "to the ground so the message will not be sent. Length of data must be no" +
                     " more than 2048 bytes not " + data.length + ".");
             return;
         }
     }

     GuestScienceData dataMsg = mMessageFactory.newFromType(GuestScienceData._TYPE);
     Header hdr = mMessageFactory.newFromType(Header._TYPE);

     hdr.setStamp(mNodeConfig.getTimeProvider().getCurrentTime());
     dataMsg.setHeader(hdr);

     dataMsg.setApkName(apkFullName);

     if (msg.what == MessageType.STRING.toInt()) {
         dataMsg.setDataType(GuestScienceData.STRING);
     } else if (msg.what == MessageType.JSON.toInt()) {
         dataMsg.setDataType(GuestScienceData.JSON);
     } else if (msg.what == MessageType.BINARY.toInt()) {
         dataMsg.setDataType(GuestScienceData.BINARY);
     } else {
         mLogger.error(LOG_TAG, "Message type in guest science message is unknown so the message " +
                 "will not be sent to the ground.");
         return;
     }

     dataMsg.setTopic(topic);

     ChannelBuffer dataBuff = dataMsg.getData();
     dataBuff.setBytes(0, data);
     dataBuff.setIndex(0, data.length);
     dataMsg.setData(dataBuff);
     mDataPublisher.publish(dataMsg);
}
 
開發者ID:nasa,項目名稱:astrobee_android,代碼行數:65,代碼來源:ManagerNode.java


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