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


Java ByteStreams.read方法代码示例

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


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

示例1: findClassInJarFile

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
protected Class<?> findClassInJarFile(String qualifiedClassName) throws ClassNotFoundException {
    URI classUri = URIUtil.buildUri(StandardLocation.CLASS_OUTPUT, qualifiedClassName);
    String internalClassName = classUri.getPath().substring(1);
    JarFile jarFile = null;
    try {
        for (int i = 0; i < jarFiles.size(); i++) {
            jarFile = jarFiles.get(i);
            JarEntry jarEntry = jarFile.getJarEntry(internalClassName);
            if (jarEntry != null) {
                InputStream inputStream = jarFile.getInputStream(jarEntry);
                try {
                    byte[] byteCode = new byte[(int) jarEntry.getSize()];
                    ByteStreams.read(inputStream, byteCode, 0, byteCode.length);
                    return defineClass(qualifiedClassName, byteCode, 0, byteCode.length);
                } finally {
                    Closeables.closeQuietly(inputStream);
                }
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(String.format("Failed to lookup class %s in jar file %s", qualifiedClassName, jarFile), e);
    }
    return null;
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:25,代码来源:SimpleClassLoader.java

示例2: decodeMessage

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
private Message decodeMessage(ChannelHandlerContext ctx, List<Frame> frames) throws IOException {
    long frameType = frames.get(0).getType();

    byte[] payload = new byte[frames.size() == 1 ? frames.get(0).getSize() : frames.get(0).totalFrameSize];
    int pos = 0;
    for (Frame frame : frames) {
        pos += ByteStreams.read(frame.getStream(), payload, pos, frame.getSize());
    }

    if (loggerWire.isDebugEnabled()) {
        loggerWire.debug("Recv: Encoded: {} [{}]", frameType, Hex.toHexString(payload));
    }

    Message msg = createMessage((byte) frameType, payload);

    if (loggerNet.isInfoEnabled()) {
        loggerNet.info("From: \t{} \tRecv: \t{}", channel, msg.toString());
    }

    ethereumListener.onRecvMessage(channel, msg);

    channel.getNodeStatistics().rlpxInMessages.add();
    return msg;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:25,代码来源:MessageCodec.java

示例3: decodeMessage

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
private Message decodeMessage(ChannelHandlerContext ctx, List<Frame> frames) throws IOException {
    long frameType = frames.get(0).getType();

    byte[] payload = new byte[frames.size() == 1 ? frames.get(0).getSize() : frames.get(0).totalFrameSize];
    int pos = 0;
    for (Frame frame : frames) {
        pos += ByteStreams.read(frame.getStream(), payload, pos, frame.getSize());
    }

    if (loggerWire.isDebugEnabled())
        loggerWire.debug("Recv: Encoded: {} [{}]", frameType, Hex.toHexString(payload));

    Message msg;
    try {
        msg = createMessage((byte) frameType, payload);
    } catch (Exception ex) {
        loggerNet.debug("Incorrectly encoded message from: \t{}, dropping peer", channel);
        channel.disconnect(ReasonCode.BAD_PROTOCOL);
        return null;
    }

    if (loggerNet.isDebugEnabled())
        loggerNet.debug("From: {}    Recv:  {}", channel, msg.toString());

    ethereumListener.onRecvMessage(channel, msg);

    channel.getNodeStatistics().rlpxInMessages.add();
    return msg;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:30,代码来源:MessageCodec.java

示例4: read

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public int read(byte[] bytes) throws IosDeviceException {
  try {
    return ByteStreams.read(socketIn, bytes, 0, bytes.length);
  } catch (IOException e) {
    throw new IosDeviceException(device(), e);
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:9,代码来源:IosDeviceSocket.java

示例5: read

import com.google.common.io.ByteStreams; //导入方法依赖的package包/类
@Override
public int read(byte[] bytes) throws IosDeviceException {
  if (closed) {
    throw new IosDeviceException(device(), "socket closed");
  }
  try {
    return ByteStreams.read(input, bytes, 0, bytes.length);
  } catch (IOException e) {
    throw new IosDeviceException(device(), e);
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:12,代码来源:FakeIosDeviceSocket.java


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