当前位置: 首页>>代码示例>>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;未经允许,请勿转载。