本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}