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


Java Bytes.toArray方法代碼示例

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


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

示例1: toArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
    if (componentType == boolean.class) {
        return Booleans.toArray((Collection) values);
    } else if (componentType == byte.class) {
        return Bytes.toArray((Collection) values);
    } else if (componentType == short.class) {
        return Shorts.toArray((Collection) values);
    } else if (componentType == int.class) {
        return Ints.toArray((Collection) values);
    } else if (componentType == long.class) {
        return Longs.toArray((Collection) values);
    } else if (componentType == float.class) {
        return Floats.toArray((Collection) values);
    } else if (componentType == double.class) {
        return Doubles.toArray((Collection) values);
    } else if (componentType == char.class) {
        return Chars.toArray((Collection) values);
    }
    return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
 
開發者ID:TNG,項目名稱:ArchUnit,代碼行數:22,代碼來源:JavaClassProcessor.java

示例2: getLsrHeaderAsByteArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Gets LS request packet header as byte array.
 *
 * @return LS request packet header as byte array
 */
public byte[] getLsrHeaderAsByteArray() {
    List<Byte> headerLst = new ArrayList<>();

    try {
        headerLst.add((byte) this.ospfVersion());
        headerLst.add((byte) this.ospfType());
        headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.ospfPacLength())));
        headerLst.addAll(Bytes.asList(this.routerId().toOctets()));
        headerLst.addAll(Bytes.asList(this.areaId().toOctets()));
        headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.checksum())));
        headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.authType())));
        //Authentication is 0 always. Total 8 bytes consist of zero
        byte[] auth = new byte[OspfUtil.EIGHT_BYTES];
        headerLst.addAll(Bytes.asList(auth));
    } catch (Exception e) {
        log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
        return Bytes.toArray(headerLst);
    }

    return Bytes.toArray(headerLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:LsRequest.java

示例3: getLsrBodyAsByteArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Gets LS request packet body as byte array.
 *
 * @return LS request packet body as byte array
 */
public byte[] getLsrBodyAsByteArray() {
    List<Byte> bodyLst = new ArrayList<>();

    try {
        for (LsRequestPacket lsrPacket : linkStateRequests) {
            bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(lsrPacket.lsType())));
            bodyLst.addAll(Bytes.asList(InetAddress.getByName(lsrPacket.linkStateId()).getAddress()));
            bodyLst.addAll(Bytes.asList(InetAddress.getByName(lsrPacket.ownRouterId()).getAddress()));
        }
    } catch (Exception e) {
        log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
        return Bytes.toArray(bodyLst);
    }

    return Bytes.toArray(bodyLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:22,代碼來源:LsRequest.java

示例4: getLsuHeaderAsByteArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Gets lsu header.
 *
 * @return lsu header as byte array
 */
public byte[] getLsuHeaderAsByteArray() {
    List<Byte> headerLst = new ArrayList<>();
    try {
        headerLst.add((byte) this.ospfVersion());
        headerLst.add((byte) this.ospfType());
        headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.ospfPacLength())));
        headerLst.addAll(Bytes.asList(this.routerId().toOctets()));
        headerLst.addAll(Bytes.asList(this.areaId().toOctets()));
        headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.checksum())));
        headerLst.addAll(Bytes.asList(OspfUtil.convertToTwoBytes(this.authType())));
        //Authentication is 0 always. Total 8 bytes consist of zero
        byte[] auth = new byte[OspfUtil.EIGHT_BYTES];
        headerLst.addAll(Bytes.asList(auth));
    } catch (Exception e) {
        log.debug("Error::LSUpdate::getLsuHeaderAsByteArray:: {}", e.getMessage());
        return Bytes.toArray(headerLst);
    }

    return Bytes.toArray(headerLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:26,代碼來源:LsUpdate.java

示例5: getLsAckBodyAsByteArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Gets LsAck body as byte array.
 *
 * @return byte array
 */
public byte[] getLsAckBodyAsByteArray() {
    List<Byte> bodyLst = new ArrayList<>();

    try {
        for (LsaHeader lsaHeader : linkStateHeaders) {
            if (lsaHeader.lsType() == OspfParameters.LINK_LOCAL_OPAQUE_LSA ||
                    lsaHeader.lsType() == OspfParameters.AREA_LOCAL_OPAQUE_LSA ||
                    lsaHeader.lsType() == OspfParameters.AS_OPAQUE_LSA) {
                OpaqueLsaHeader header = (OpaqueLsaHeader) lsaHeader;
                bodyLst.addAll(Bytes.asList(header.getOpaqueLsaHeaderAsByteArray()));
            } else {
                bodyLst.addAll(Bytes.asList(lsaHeader.getLsaHeaderAsByteArray()));
            }
        }
    } catch (Exception e) {
        log.debug("Error::getLsAckBodyAsByteArray {}", e.getMessage());
        return Bytes.toArray(bodyLst);
    }

    return Bytes.toArray(bodyLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:LsAcknowledge.java

示例6: getLsaBodyAsByteArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Gets the LSA body as byte array.
 *
 * @return the lsa body as byte array
 * @throws Exception might throws exception while parsing packet
 */
public byte[] getLsaBodyAsByteArray() throws Exception {
    List<Byte> bodyLst = new ArrayList<>();
    if (this.opaqueId() == 1) {
        for (TopLevelTlv tlv : this.topLevelValues) {
            //Check the sub type of lsa and build bytes accordingly
            if (tlv instanceof RouterTlv) {
                RouterTlv routerTlv = (RouterTlv) tlv;
                bodyLst.addAll(Bytes.asList(routerTlv.asBytes()));
            } else if (tlv instanceof LinkTlv) {
                LinkTlv linkTlv = (LinkTlv) tlv;
                bodyLst.addAll(Bytes.asList(linkTlv.asBytes()));
            }
        }
    } else {
        return opaqueInfo;
    }

    return Bytes.toArray(bodyLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:26,代碼來源:OpaqueLsa10.java

示例7: getLsaBodyAsByteArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Gets LSA body as byte array.
 *
 * @return LSA body as byte array
 * @throws OspfParseException might throws exception while parsing packet
 */
public byte[] getLsaBodyAsByteArray() throws OspfParseException {
    List<Byte> bodyLst = new ArrayList<>();

    try {
        bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));
        //add each attachedRouters details
        for (Ip4Address attachedRouter : attachedRouters) {
            //attached router
            bodyLst.addAll(Bytes.asList(attachedRouter.toOctets()));
        }
    } catch (Exception e) {
        log.debug("Error::NetworkLSA::getLsrBodyAsByteArray {}", e.getMessage());
        throw new OspfParseException(OspfErrorType.OSPF_MESSAGE_ERROR, OspfErrorType.BAD_MESSAGE);
    }

    return Bytes.toArray(bodyLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:NetworkLsa.java

示例8: read

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
private void read(SocketChannel channel) throws Exception {
    LinkedList<Byte> list = new LinkedList<>();
    ByteBuffer buf = ByteBuffer.allocate(1024);
    int bytesRead = channel.read(buf);
    // 如果讀取到-1,則說明客戶端關閉了該鏈接
    if (bytesRead == -1) {
        log.info("Close channel {}", channel.getRemoteAddress());
        channel.close();
        return;
    }
    // 非阻塞IO可以讀取0個字節,這種數據應該手動丟棄
    if (bytesRead == 0) return;

    // 讀取所有的數據
    while (bytesRead > 0) {
        buf.flip();
        while (buf.hasRemaining()) {
            list.add(buf.get());
        }
        buf.clear();
        bytesRead = channel.read(buf);
    }
    String request = new String(Bytes.toArray(list), Constants.DEFAULT_ENCODING);
    try {
        // 寫回響應
        response(request, channel);
    } catch (Exception e) {
        e.printStackTrace();
        // 返回錯誤信息
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        e.printStackTrace(printWriter);
        serverError(stringWriter.toString(), channel);
    }
}
 
開發者ID:RitterHou,項目名稱:Geisha,代碼行數:36,代碼來源:NioServer.java

示例9: getLsaBodyAsByteArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Gets LSA body as byte array.
 *
 * @return byte array contains LSA body
 * @throws OspfParseException might throws exception while parsing buffer
 */
public byte[] getLsaBodyAsByteArray() throws OspfParseException {
    List<Byte> bodyLst = new ArrayList<>();

    try {
        bodyLst.addAll(Bytes.asList(this.networkMask().toOctets()));

        //add each OSPFExternalDestination details
        for (OspfExternalDestination externalDest : externalDestinations) {
            if (externalDest.isType1orType2Metric()) {
                //add 1 followed by 7 zeros equals to decimal 128
                bodyLst.add((byte) 128);
            } else {
                bodyLst.add((byte) 0);
            }

            bodyLst.addAll(Bytes.asList(OspfUtil.convertToThreeBytes(externalDest.metric())));
            bodyLst.addAll(Bytes.asList(externalDest.forwardingAddress().toOctets()));
            bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(externalDest.externalRouterTag())));
        }
    } catch (Exception e) {
        log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
        return Bytes.toArray(bodyLst);
    }

    return Bytes.toArray(bodyLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:33,代碼來源:ExternalLsa.java

示例10: lspEntryAsBytes

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Returns LSP entry values as bytes of LSP entry.
 *
 * @return byteArray LSP entry values as bytes of LSP entry
 */
public byte[] lspEntryAsBytes() {
    List<Byte> bytes = new ArrayList<>();
    bytes.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.remainingTime())));
    bytes.addAll(IsisUtil.sourceAndLanIdToBytes(this.lspId()));
    bytes.addAll(Bytes.asList(IsisUtil.convertToFourBytes(this.lspSequenceNumber())));
    bytes.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.lspChecksum())));
    return Bytes.toArray(bytes);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:14,代碼來源:LspEntry.java

示例11: tlvBodyAsBytes

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Returns TLV body of internal reachability TLV.
 *
 * @return byteArray TLV body of area address TLV
 */
private byte[] tlvBodyAsBytes() {
    List<Byte> bytes = new ArrayList<>();
    for (MetricOfInternalReachability metricOfInternalReachability :
            this.metricOfInternalReachability) {
        bytes.addAll(Bytes.asList(metricOfInternalReachability.asBytes()));
    }
    return Bytes.toArray(bytes);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:14,代碼來源:IpInternalReachabilityTlv.java

示例12: getTlvBodyAsByteArray

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Gets tlv body as byte array.
 *
 * @return tlv body as byte array
 * @throws Exception might throws exception while parsing buffer
 */
public byte[] getTlvBodyAsByteArray() throws Exception {

    List<Byte> bodyLst = new ArrayList<>();
    for (LinkSubType tlv : subTlv) {
        //Check the type of tlv and build bytes accordingly
        if (tlv instanceof LinkType) {
            LinkType linkType = (LinkType) tlv;
            bodyLst.addAll(Bytes.asList(linkType.asBytes()));
        } else if (tlv instanceof LinkId) {
            LinkId linkId = (LinkId) tlv;
            bodyLst.addAll(Bytes.asList(linkId.asBytes()));
        } else if (tlv instanceof LocalInterfaceIpAddress) {
            LocalInterfaceIpAddress localInterfaceIpAddress = (LocalInterfaceIpAddress) tlv;
            bodyLst.addAll(Bytes.asList(localInterfaceIpAddress.asBytes()));
        } else if (tlv instanceof RemoteInterfaceIpAddress) {
            RemoteInterfaceIpAddress remoteInterfaceIpAddress = (RemoteInterfaceIpAddress) tlv;
            bodyLst.addAll(Bytes.asList(remoteInterfaceIpAddress.asBytes()));
        } else if (tlv instanceof TrafficEngineeringMetric) {
            TrafficEngineeringMetric trafficEngineeringMetric = (TrafficEngineeringMetric) tlv;
            bodyLst.addAll(Bytes.asList(trafficEngineeringMetric.asBytes()));
        } else if (tlv instanceof MaximumBandwidth) {
            MaximumBandwidth maximumBandwidth = (MaximumBandwidth) tlv;
            bodyLst.addAll(Bytes.asList(maximumBandwidth.asBytes()));
        } else if (tlv instanceof MaximumReservableBandwidth) {
            MaximumReservableBandwidth maximumReservableBandwidth = (MaximumReservableBandwidth) tlv;
            bodyLst.addAll(Bytes.asList(maximumReservableBandwidth.asBytes()));
        } else if (tlv instanceof UnreservedBandwidth) {
            UnreservedBandwidth unreservedBandwidth = (UnreservedBandwidth) tlv;
            bodyLst.addAll(Bytes.asList(unreservedBandwidth.asBytes()));
        } else if (tlv instanceof AdministrativeGroup) {
            AdministrativeGroup administrativeGroup = (AdministrativeGroup) tlv;
            bodyLst.addAll(Bytes.asList(administrativeGroup.asBytes()));
        } else {
            UnknownLinkSubType unknownLinkSubType = (UnknownLinkSubType) tlv;
            bodyLst.addAll(Bytes.asList(unknownLinkSubType.asBytes()));
        }
    }
    return Bytes.toArray(bodyLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:46,代碼來源:LinkTlv.java

示例13: tlvBodyAsBytes

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Returns TLV body of LSP entries TLV.
 *
 * @return byteArray TLV body of LSP entries TLV
 */
private byte[] tlvBodyAsBytes() {
    List<Byte> bytes = new ArrayList<>();
    for (LspEntry lspEntry : lspEntryList) {
        bytes.addAll(Bytes.asList(lspEntry.lspEntryAsBytes()));
    }
    return Bytes.toArray(bytes);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:13,代碼來源:LspEntriesTlv.java

示例14: tlvBodyAsBytes

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Returns TLV body of IS extended reachability TLV.
 *
 * @return byteArray TLV body of IS extended reachability TLV.
 */
private byte[] tlvBodyAsBytes() {
    List<Byte> byteList = new ArrayList<>();
    for (NeighborForExtendedIs neighbor : this.neighbors) {
        byteList.addAll(Bytes.asList(neighbor.neighborBodyAsbytes()));
    }
    return Bytes.toArray(byteList);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:13,代碼來源:IsExtendedReachability.java

示例15: l1l2HelloPduBody

import com.google.common.primitives.Bytes; //導入方法依賴的package包/類
/**
 * Parse the ISIS L1L2 PDU body.
 *
 * @return ISIS L1L2 PDU body
 */
public byte[] l1l2HelloPduBody() {
    List<Byte> bodyLst = new ArrayList<>();

    bodyLst.add(this.circuitType());
    bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.sourceId()));
    bodyLst.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.holdingTime())));
    bodyLst.addAll(Bytes.asList(IsisUtil.convertToTwoBytes(this.pduLength())));
    bodyLst.add(this.priority);
    bodyLst.addAll(IsisUtil.sourceAndLanIdToBytes(this.lanId()));
    for (IsisTlv isisTlv : variableLengths) {
        bodyLst.addAll(TlvsToBytes.tlvToBytes(isisTlv));
    }
    return Bytes.toArray(bodyLst);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:20,代碼來源:L1L2HelloPdu.java


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