本文整理汇总了Java中org.glassfish.grizzly.Buffer类的典型用法代码示例。如果您正苦于以下问题:Java Buffer类的具体用法?Java Buffer怎么用?Java Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Buffer类属于org.glassfish.grizzly包,在下文中一共展示了Buffer类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: handleWrite
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
public NextAction handleWrite(FilterChainContext context) throws IOException {
Connection<?> connection = context.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // 不需要关闭
Object msg = context.getMessage();
codec.encode(channel, channelBuffer, msg);
GrizzlyChannel.removeChannelIfDisconnectd(connection);
Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
buffer.put(channelBuffer.toByteBuffer());
buffer.flip();
buffer.allowBufferDispose(true);
context.setMessage(buffer);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return context.getInvokeAction();
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:22,代码来源:GrizzlyCodecAdapter.java
示例2: handleWrite
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
public NextAction handleWrite(FilterChainContext context) throws IOException {
Connection<?> connection = context.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // 不需要关闭
Object msg = context.getMessage();
codec.encode(channel, channelBuffer, msg);
GrizzlyChannel.removeChannelIfDisconnectd(connection);
Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
buffer.put(channelBuffer.toByteBuffer());
buffer.flip();
buffer.allowBufferDispose(true);
context.setMessage(buffer);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return context.getInvokeAction();
}
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:22,代码来源:GrizzlyCodecAdapter.java
示例3: transformImpl
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected final TransformationResult<MessageLite, Buffer> transformImpl(
final AttributeStorage storage, final @NonNull MessageLite input)
throws TransformationException {
final MemoryManager memoryManager = obtainMemoryManager(storage);
final BufferOutputStream outputStream = new BufferOutputStream(memoryManager);
final byte[] encodedMessage = input.toByteArray();
try {
writeHeader(outputStream, encodedMessage.length);
outputStream.write(encodedMessage);
outputStream.close();
} catch (final IOException e) {
final String msg = "Error writing protobuf message to output stream.";
log.warn(msg, e);
return createErrorResult(IO_WRITE_ERROR, msg);
}
return createCompletedResult(outputStream.getBuffer().flip(), null);
}
开发者ID:novabyte,项目名称:grizzly-protobuf,代码行数:23,代码来源:AbstractProtobufEncoder.java
示例4: transformImpl
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
protected TransformationResult<Request, Buffer> transformImpl(AttributeStorage storage, Request request) throws TransformationException {
byte ver = request.getHeader().getSerializeVersion() ;
int pLen = request.getPayload() == null ? 0 : request.getPayload().length;
byte[] header = request.getHeader().toByte();
// encoding length , and check the max value of integer, should be 2GB
int totalLen = OFFSET + header.length + pLen + R_SIZE + H_SIZE;
if ( totalLen > Integer.MAX_VALUE ) {
throw new TransformationException( totalLen +" exceeding Integer.MAX_VALUE");
}
//logger.info("total "+totalLen+" hd "+header.length+" payload "+pLen);
// Retrieve the memory manager
//final MemoryManager memoryManager = ctx.getConnection().getTransport().getMemoryManager();
// allocate the buffer of required size
final Buffer bout = obtainMemoryManager(storage).allocate(totalLen);
// Instruct the FilterChain to call the next filter
bout.put(SIGNATURE);
bout.put(ver);
bout.putInt(totalLen);
bout.putShort((short) header.length);
bout.put(header);
// request type
bout.put((byte) request.getType().ordinal());
bout.put( request.getPayload());
bout.flip();
bout.allowBufferDispose(true);
return TransformationResult.createCompletedResult(bout, null);
}
开发者ID:viant,项目名称:CacheStore,代码行数:32,代码来源:RequestEncoder.java
示例5: transformImpl
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
protected TransformationResult<Buffer, Request> transformImpl(AttributeStorage storage, Buffer input) throws TransformationException {
//Integer packSize = lengthAttribute.get(storage);
VersionLength versionLength = lengthAttribute.get(storage);
if (versionLength == null) {
if (input.remaining() < OFFSET) {
return TransformationResult.createIncompletedResult(input);
}
byte signature = input.get();
byte ver = input.get();
int packSize = input.getInt();
if (signature != SIGNATURE ) {
//channel.close();
throw new TransformationException("expect "+SIGNATURE+" but get "+signature+" "+" "+input.toString());
}
if ( packSize < 0 || packSize > MAX_LEN ) {
//channel.close();
throw new TransformationException(packSize+" Exceed Integer.MAX_VALUE or MAX_LEN");
}
//use versionlength
versionLength = new VersionLength(packSize, ver);
//lengthAttribute.set(storage, packSize);
lengthAttribute.set(storage, versionLength);
}
if (input.remaining() < (versionLength.getLength() -OFFSET) ) {
//logger.info("packSize "+versionLength.getLength() + " remaining "+input.remaining() );
return TransformationResult.createIncompletedResult(input);
}
int tmpLimit = input.limit();
input.limit(input.position() + (versionLength.getLength() -OFFSET) );
Request request= doDecode(input, versionLength.getLength(), versionLength.getVersion() );
input.position(input.limit());
input.limit(tmpLimit);
return TransformationResult.createCompletedResult(
request, input);
}
开发者ID:viant,项目名称:CacheStore,代码行数:38,代码来源:RequestDecoder.java
示例6: doDecode
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
protected Request doDecode(Buffer buffer, int len, byte ver) {
//read all byte from buffer first, in case exception during de serialize
short headLen = buffer.getShort();
byte[] bytes = new byte[ (int) headLen];
buffer.get( bytes);
//read request type before payload
byte type = buffer.get();
byte[] payload = new byte[ len - headLen - OFFSET - R_SIZE - H_SIZE ];
buffer.get( payload);
Header header = Header.toHeader( bytes);
// assign serializeVersion
header.setSerializeVersion( ver);
return new Request( header, payload, getRequestType( type));
}
开发者ID:viant,项目名称:CacheStore,代码行数:15,代码来源:RequestDecoder.java
示例7: handleWrite
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
/**
* Method is called, when we write a data to the Connection.
*
* We override this method to perform GIOPMessage -> Buffer transformation.
*
* @param ctx Context of {@link FilterChainContext} processing
* @return the next action
* @throws java.io.IOException
*/
@Override
public NextAction handleWrite(final FilterChainContext ctx) throws IOException {
final Request request = ctx.getMessage();
byte ver = version;
int pLen = request.getPayload() == null ? 0 : request.getPayload().length;
byte[] header = request.getHeader().toByte();
// encoding length , and check the max value of integer, should be 2GB
int totalLen = TOTAL + header.length + pLen + R_SIZE;
if ( totalLen > Integer.MAX_VALUE ) {
throw new IOException( totalLen +" exceeding Integer.MAX_VALUE");
}
logger.info("total "+totalLen+" hd "+header.length+" payload "+pLen);
// Retrieve the memory manager
final MemoryManager memoryManager =
ctx.getConnection().getTransport().getMemoryManager();
// allocate the buffer of required size
final Buffer bout = memoryManager.allocate(totalLen);
// Instruct the FilterChain to call the next filter
bout.put(SIGNATURE);
bout.put(ver);
bout.putInt(totalLen);
bout.putShort((short) header.length);
bout.put(header);
// request type
bout.put((byte) request.getType().ordinal());
bout.put( request.getPayload());
// Set the Buffer as a context message
ctx.setMessage( bout.flip() );
return ctx.getInvokeAction();
}
开发者ID:viant,项目名称:CacheStore,代码行数:42,代码来源:RequestCoder.java
示例8: doDecode
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
protected Request doDecode(Buffer buffer, int len, byte ver) {
//read all byte from buffer first, in case exception during de serialize
short headLen = buffer.getShort();
byte[] bytes = new byte[ (int) headLen];
buffer.get( bytes);
//read request type before payload
byte type = buffer.get();
byte[] payload = new byte[ len - headLen - TOTAL - R_SIZE ];
buffer.get( payload);
Header header = Header.toHeader( bytes);
// assign serializeVersion
header.setSerializeVersion( ver);
return new Request( header, payload, getRequestType( type));
}
开发者ID:viant,项目名称:CacheStore,代码行数:15,代码来源:RequestCoder.java
示例9: handleWrite
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
public NextAction handleWrite(FilterChainContext ctx) throws IOException {
GrizzlyByteBufferWrapper wrapper = new GrizzlyByteBufferWrapper(ctx);
try {
ProtocolUtils.encode(ctx.getMessage(), wrapper);
final Buffer buffer = wrapper.getBuffer();
buffer.trim();
ctx.setMessage(buffer);
return ctx.getInvokeAction();
} catch (Exception e) {
throw new IOException("encode message to byte error", e);
}
}
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:15,代码来源:GrizzlyProtocolFilter.java
示例10: handleWrite
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
public NextAction handleWrite(FilterChainContext ctx) throws IOException {
// final Object message = ctx.getMessage();
//
// HeapBuffer buffer = (HeapBuffer) message;
// byte[] bytes = new byte[buffer.remaining()];
// buffer.get(bytes);
// byte[] encoded = binaryEncryptor.encrypt(bytes);
// Buffer buf = new HeapMemoryManager().wrap(encoded);
// ctx.setMessage(buf);
System.out.println(System.nanoTime() + ":write:"
+ ((Buffer) ctx.getMessage()).remaining());
return super.handleWrite(ctx);
}
开发者ID:chocotan,项目名称:kazeproxy,代码行数:15,代码来源:TunnelRedirectServerFilter.java
示例11: addToBuffer
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
public void addToBuffer(NIOInputStream in, ByteBuffer postBytes){
Buffer buffer = in.readBuffer();
ByteBuffer bb = buffer.toByteBuffer();
try {
postBytes.put(bb);
} finally {
buffer.tryDispose();
}
}
开发者ID:davruet,项目名称:shenanigans.io,代码行数:10,代码来源:AsyncPostHandler.java
示例12: readHeader
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public int readHeader(final Buffer input) throws IOException {
if (input == null) {
throw new IllegalArgumentException("'input' cannot be null.");
}
final byte[] messageLengthArr = new byte[headerLength];
input.get(messageLengthArr);
log.debug("inputRemaining={}", input.remaining());
return ByteBuffer.wrap(messageLengthArr).getInt();
}
开发者ID:novabyte,项目名称:grizzly-protobuf,代码行数:14,代码来源:FixedLengthProtobufDecoder.java
示例13: readHeader
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public int readHeader(final Buffer input) throws IOException {
if (input == null) {
throw new IllegalArgumentException("'input' cannot be null.");
}
final BufferInputStream inputStream = new BufferInputStream(input);
return CodedInputStream.readRawVarint32(input.get(), inputStream);
}
开发者ID:novabyte,项目名称:grizzly-protobuf,代码行数:11,代码来源:Varint32ProtobufDecoder.java
示例14: handleRead
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
public NextAction handleRead(FilterChainContext context) throws IOException {
Object message = context.getMessage();
Connection<?> connection = context.getConnection();
Channel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
if (message instanceof Buffer) { // 收到新的数据包
Buffer grizzlyBuffer = (Buffer) message; // 缓存
ChannelBuffer frame;
if (previousData.readable()) {
if (previousData instanceof DynamicChannelBuffer) {
previousData.writeBytes(grizzlyBuffer.toByteBuffer());
frame = previousData;
} else {
int size = previousData.readableBytes() + grizzlyBuffer.remaining();
frame = ChannelBuffers.dynamicBuffer(size > bufferSize ? size : bufferSize);
frame.writeBytes(previousData, previousData.readableBytes());
frame.writeBytes(grizzlyBuffer.toByteBuffer());
}
} else {
frame = ChannelBuffers.wrappedBuffer(grizzlyBuffer.toByteBuffer());
}
Object msg;
int savedReadIndex;
do {
savedReadIndex = frame.readerIndex();
try {
msg = codec.decode(channel, frame);
} catch (Exception e) {
previousData = ChannelBuffers.EMPTY_BUFFER;
throw new IOException(e.getMessage(), e);
}
if (msg == Codec2.DecodeResult.NEED_MORE_INPUT) {
frame.readerIndex(savedReadIndex);
return context.getStopAction();
} else {
if (savedReadIndex == frame.readerIndex()) {
previousData = ChannelBuffers.EMPTY_BUFFER;
throw new IOException("Decode without read data.");
}
if (msg != null) {
context.setMessage(msg);
return context.getInvokeAction();
} else {
return context.getInvokeAction();
}
}
} while (frame.readable());
} else { // 其它事件直接往下传
return context.getInvokeAction();
}
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:60,代码来源:GrizzlyCodecAdapter.java
示例15: service
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
public void service(Request request, Response response) throws Exception {
request.setCharacterEncoding("UTF-8");
Buffer postBody = request.getPostBody(1024);
String text = postBody.toStringContent();
if (request.getParameter("text") != null) {
text = request.getParameter("text");
}
String outputFormat = request.getParameter("format");
InputStream inputStream = new ByteArrayInputStream(text.getBytes());
OutputStream outputStream = new ByteArrayOutputStream();
TintRunner.OutputFormat format = TintRunner.getOutputFormat(outputFormat, TintRunner.OutputFormat.JSON);
pipeline.run(inputStream, outputStream, format);
LOGGER.debug("Text: {}", text);
String output = outputStream.toString();
writeOutput(response, contentTypes.get(format), output);
}
开发者ID:dhfbk,项目名称:tint,代码行数:27,代码来源:TintHandler.java
示例16: hasInputRemaining
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
public boolean hasInputRemaining(AttributeStorage storage, Buffer input) {
boolean result = input != null && input.hasRemaining();
//logger.info("hasInputRemaining "+result +" storage "+storage.getAttributes().toString() + " buffer "+input.toString());
return result;
}
开发者ID:viant,项目名称:CacheStore,代码行数:7,代码来源:RequestDecoder.java
示例17: handleRead
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
@Override
public NextAction handleRead(final FilterChainContext ctx) throws IOException {
final Buffer buffer = ctx.getMessage();
final int sourceBufferLength = buffer.remaining();
// If source buffer doesn't contain header
if (sourceBufferLength < TOTAL) {
// shutdownNow the filterchain processing and store sourceBuffer to be
// used next time
return ctx.getStopAction(buffer);
}
byte signature = buffer.get();
byte ver = buffer.get();
int totalLen = buffer.getInt();
if (signature != SIGNATURE ) {
//channel.close();
throw new IOException("expect "+SIGNATURE+" but get "+signature+" "+ ctx.getAddress().toString()
+" "+buffer.toString());
}
if ( totalLen < 0 || totalLen > MAX_LEN ) {
//channel.close();
throw new IOException(totalLen+" Exceed Integer.MAX_VALUE or MAX_LEN"+" "+ctx.getAddress().toString());
}
if ( sourceBufferLength < totalLen) {
logger.info("notready bufferlength "+sourceBufferLength+" totallen "+totalLen);
// shutdownNow the filterchain processing and store sourceBuffer to be
// used next time
return ctx.getStopAction(buffer);
}
else
logger.info("ready bufferlength "+sourceBufferLength+" totallen "+totalLen);
// shutdownNow the filterchain processing and store sourceBuffer to be
// Check if the source buffer has more than 1 complete GIOP message
// If yes - split up the first message and the remainder
final Buffer remainder = sourceBufferLength > totalLen?
buffer.split( totalLen) : null;
ctx.setMessage( doDecode( buffer, totalLen, ver));
// We can try to dispose the buffer
buffer.tryDispose();
// Instruct FilterChain to store the remainder (if any) and continue execution
return ctx.getInvokeAction(remainder);
}
开发者ID:viant,项目名称:CacheStore,代码行数:45,代码来源:RequestCoder.java
示例18: GrizzlyByteBufferWrapper
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
public GrizzlyByteBufferWrapper(Buffer buffer) {
this.buffer = buffer;
}
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:4,代码来源:GrizzlyByteBufferWrapper.java
示例19: getBuffer
import org.glassfish.grizzly.Buffer; //导入依赖的package包/类
public Buffer getBuffer() {
return buffer;
}
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:4,代码来源:GrizzlyByteBufferWrapper.java
注:本文中的org.glassfish.grizzly.Buffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论