本文整理汇总了Java中org.jboss.netty.buffer.ChannelBufferInputStream类的典型用法代码示例。如果您正苦于以下问题:Java ChannelBufferInputStream类的具体用法?Java ChannelBufferInputStream怎么用?Java ChannelBufferInputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChannelBufferInputStream类属于org.jboss.netty.buffer包,在下文中一共展示了ChannelBufferInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer buffer) throws Exception {
ChannelBuffer frame = (ChannelBuffer) super
.decode(ctx, channel, buffer);
if (frame == null) {
return null;
}
ChannelBufferInputStream in = new ChannelBufferInputStream(frame);
Hessian2Input jim = new Hessian2Input(in);
try {
Object o = jim.readObject();
return o;
} finally {
jim.close();
}
}
示例2: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx,
Channel channel,
ChannelBuffer buffer) throws Exception {
List<SyncMessage> ms = null;
ChannelBuffer frame = null;
while (null != (frame = (ChannelBuffer) super.decode(ctx, channel,
buffer))) {
if (ms == null) ms = new ArrayList<SyncMessage>();
ChannelBufferInputStream is = new ChannelBufferInputStream(frame);
TCompactProtocol thriftProtocol =
new TCompactProtocol(new TIOStreamTransport(is));
SyncMessage bsm = new SyncMessage();
bsm.read(thriftProtocol);
ms.add(bsm);
}
return ms;
}
示例3: parse
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
public void parse(HttpRequest req) throws IOException {
final JsonParser parser = jsonFactory.createJsonParser(
new ChannelBufferInputStream(req.getContent()));
parser.nextToken(); // Skip the wrapper
while (parser.nextToken() != JsonToken.END_OBJECT) {
final String metric = parser.getCurrentName();
JsonToken currentToken = parser.nextToken();
if (currentToken == JsonToken.START_OBJECT) {
parseMetricObject(metric, parser);
} else if (currentToken == JsonToken.START_ARRAY) {
int illegalTokens = parseMetricArray(metric, parser);
if(illegalTokens > 0) {
logger.warn("{} illegal tokens encountered", illegalTokens);
}
} else {
logger.warn("Illegal token: expected {} or {}, but was {}: {}",new Object[] {
JsonToken.START_OBJECT, JsonToken.START_ARRAY, currentToken, parser.getText()});
}
}
}
示例4: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer buffer) throws Exception {
ChannelBuffer frame = (ChannelBuffer) super
.decode(ctx, channel, buffer);
if (frame == null) {
return null;
}
ChannelBufferInputStream in = new ChannelBufferInputStream(frame);
JBossObjectInputStream jim = new JBossObjectInputStream(in);
try {
Object o = jim.readObject();
return o;
} finally {
jim.close();
}
}
示例5: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext context, Channel channel,
ChannelBuffer buffer) throws Exception {
if (buffer.readableBytes() < 2) {
return null;
}
byte byte1 = buffer.readByte();
byte byte2 = buffer.readByte();
if (byte1 != Constants.MAGIC_HIGH || byte2 != Constants.MAGIC_LOW) {
throw new RuntimeException("magic number not right");
}
ChannelBufferInputStream in = new ChannelBufferInputStream(buffer);
RpcResponse response = MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).decodeResponse(in);
return response;
}
示例6: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer buffer) throws Exception {
if (buffer.readableBytes() < 2) {
return null;
}
byte byte1 = buffer.readByte();
byte byte2 = buffer.readByte();
if (byte1!=Constants.MAGIC_HIGH || byte2!=Constants.MAGIC_LOW) {
throw new RuntimeException("magic number not right");
}
ChannelBufferInputStream in = new ChannelBufferInputStream(buffer);
RpcRequest request = MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).decodeRequest(in);
return request;
}
示例7: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel chan,
ChannelBuffer buffer, VoidEnum state) throws Exception {
Message message = serializer.deserialize(new ChannelBufferInputStream(buffer));
if (message instanceof VersionMessage)
onVersionMessage(message);
return message;
}
示例8: readEntryComplete
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
public void readEntryComplete(int rc, long ledgerId, final long entryId, final ChannelBuffer buffer, Object ctx) {
final LedgerEntry entry = (LedgerEntry) ctx;
if (rc != BKException.Code.OK) {
logErrorAndReattemptRead(entry, "Error: " + BKException.getMessage(rc), rc);
return;
}
ChannelBufferInputStream is;
try {
is = lh.macManager.verifyDigestAndReturnData(entryId, buffer);
} catch (BKDigestMatchException e) {
logErrorAndReattemptRead(entry, "Mac mismatch", BKException.Code.DigestMatchException);
return;
}
entry.entryDataStream = is;
/*
* The length is a long and it is the last field of the metadata of an entry.
* Consequently, we have to subtract 8 from METADATA_LENGTH to get the length.
*/
entry.length = buffer.getLong(DigestManager.METADATA_LENGTH - 8);
numPendingReads--;
if (numPendingReads == 0) {
cb.readComplete(BKException.Code.OK, lh, PendingReadOp.this, PendingReadOp.this.ctx);
}
}
示例9: invoke
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
/**
* Handles a prepared WebSocket API invocation
* @param asMap true if the JSON reponse is a map, false if it is an array
* @param request The prepared HTTP request so we can piggy-back on the existing RpcHandler services.
* @param response The JSONResponse to write back to
* @throws IOException thrown on IO errors
*/
protected void invoke(boolean asMap, HttpRequest request, JSONResponse response) throws IOException {
try {
JsonGenerator generator = response.writeHeader(asMap);
InvocationChannel ichannel = new InvocationChannel();
HttpQuery query = new HttpQuery(tsdb, request, ichannel);
String baseRoute = query.getQueryBaseRoute();
rpcHandler.messageReceived(null, new UpstreamMessageEvent(ichannel, request, null));
HttpResponse resp = (HttpResponse)ichannel.getWrites().get(0);
ChannelBuffer content = resp.getContent();
ChannelBufferInputStream cbis = new ChannelBufferInputStream(content);
ObjectReader reader = jsonMapper.reader();
JsonNode contentNode = reader.readTree(cbis);
cbis.close();
if(asMap) {
ObjectNode on = (ObjectNode)contentNode;
Iterator<Map.Entry<String, JsonNode>> nodeIter = on.fields();
while(nodeIter.hasNext()) {
Map.Entry<String, JsonNode> node = nodeIter.next();
generator.writeObjectField(node.getKey(), node.getValue());
}
} else {
ArrayNode an = (ArrayNode)contentNode;
for(int i = 0; i < an.size(); i++) {
generator.writeObject(an.get(i));
}
}
response.closeGenerator();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
示例10: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
{
if (!(msg instanceof ChannelBuffer))
{
return msg;
}
ChannelBuffer buf = (ChannelBuffer) msg;
if (buf.hasArray())
{
final int offset = buf.readerIndex();
if (extensionRegistry == null)
{
return prototype.newBuilderForType()
.mergeFrom(buf.array(), buf.arrayOffset() + offset, buf.readableBytes()).build();
}
else
{
return prototype.newBuilderForType()
.mergeFrom(buf.array(), buf.arrayOffset() + offset, buf.readableBytes(), extensionRegistry)
.build();
}
}
else
{
if (extensionRegistry == null)
{
return prototype.newBuilderForType().mergeFrom(new ChannelBufferInputStream((ChannelBuffer) msg))
.build();
}
else
{
return prototype.newBuilderForType()
.mergeFrom(new ChannelBufferInputStream((ChannelBuffer) msg), extensionRegistry).build();
}
}
}
示例11: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext channelHandlerContext,
Channel channel, Object o) throws Exception
{
ChannelBuffer cb = (ChannelBuffer)o;
Unpickler unpickler = new Unpickler();
return (unpickler.load(new ChannelBufferInputStream(cb)));
}
示例12: read
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
/**
* Return a {@link ChannelBufferInputStream} if the wrapped
* {@link ChannelBuffer} contains enough data. If not it will throw a
* {@link NotEnoughDataException}
*/
public InputStream read(int size, boolean extraCRLF) throws DecodingException {
int crlf = 0;
if (extraCRLF) {
crlf = 2;
}
if (maxLiteralSize > 0 && maxLiteralSize > size) {
throw new DecodingException(HumanReadableText.FAILED, "Specified literal is greater then the allowed size");
}
// Check if we have enough data
if (size + crlf > buffer.readableBytes()) {
// ok let us throw a exception which till the decoder how many more
// bytes we need
throw new NotEnoughDataException(size + read + crlf);
}
// Unset the next char.
nextSeen = false;
nextChar = 0;
// limit the size via commons-io as ChannelBufferInputStream size limiting is buggy
InputStream in = new BoundedInputStream(new ChannelBufferInputStream(buffer), size);
if (extraCRLF) {
return new EolInputStream(this, in);
} else {
return in;
}
}
示例13: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
public void decode( ChannelBuffer buffer ) throws IOException {
super.decode( buffer );
buffer.readInt();
fullCollectionName = readCString( buffer );
flags = buffer.readInt();
selector = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
update = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
}
示例14: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
public void decode( ChannelBuffer buffer ) throws IOException {
super.decode( buffer );
flags = buffer.readInt();
fullCollectionName = readCString( buffer );
numberToSkip = buffer.readInt();
numberToReturn = buffer.readInt();
query = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
if ( buffer.readable() ) {
returnFieldSelector = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
logger.info( "found fieldSeclector: {}", returnFieldSelector );
}
}
示例15: decode
import org.jboss.netty.buffer.ChannelBufferInputStream; //导入依赖的package包/类
@Override
public void decode( ChannelBuffer buffer ) throws IOException {
super.decode( buffer );
responseFlags = buffer.readInt();
cursorID = buffer.readLong();
startingFrom = buffer.readInt();
numberReturned = buffer.readInt();
while ( buffer.readable() ) {
documents.add( BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) ) );
}
}