本文整理汇总了Java中org.eclipse.jetty.util.BufferUtil类的典型用法代码示例。如果您正苦于以下问题:Java BufferUtil类的具体用法?Java BufferUtil怎么用?Java BufferUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BufferUtil类属于org.eclipse.jetty.util包,在下文中一共展示了BufferUtil类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: forwardIncoming
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
protected void forwardIncoming(Frame frame, ByteAccumulator accumulator)
{
DataFrame newFrame = new DataFrame(frame);
// Unset RSV1 since it's not compressed anymore.
newFrame.setRsv1(false);
ByteBuffer buffer = getBufferPool().acquire(accumulator.getLength(),false);
try
{
BufferUtil.flipToFill(buffer);
accumulator.transferTo(buffer);
newFrame.setPayload(buffer);
nextIncomingFrame(newFrame);
}
finally
{
getBufferPool().release(buffer);
}
}
示例2: onContent
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
@Override
public void onContent(final Response serverResponse, ByteBuffer content, final Callback callback) {
try {
int contentBytes = content.remaining();
_log.debug("{} received server content: {} bytes", dialog.id(), contentBytes);
hasContent = true;
boolean committed = dialog.hasAttribute(WRITE_LISTENER_ATTRIBUTE);
length += contentBytes;
boolean finished = length == dialog.getResponseContentLength();
ProxyWriter proxyWriter = write(content, finished, callback);
if (finished)
proxyWriter.offer(BufferUtil.EMPTY_BUFFER, complete);
if (committed) {
proxyWriter.onWritePossible();
} else {
dialog.write(proxyWriter);
}
} catch (Throwable x) {
callback.failed(x);
}
}
示例3: onSuccess
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
@Override
public void onSuccess(final Response serverResponse) {
try {
if (hasContent) {
// If we had unknown length content, we need to call the
// transformer to signal that the content is finished.
if (dialog.getResponseContentLength() < 0) {
ProxyWriter proxyWriter = write(BufferUtil.EMPTY_BUFFER, true, complete);
proxyWriter.onWritePossible();
}
} else {
complete.succeeded();
}
} catch (Throwable x) {
complete.failed(x);
}
}
示例4: onContent
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
@Override
public void onContent(Response response, ByteBuffer buffer, Callback callback) {
if (logger.isDebugEnabled()) {
logger.debug("received response chunk {} {}", response, BufferUtil.toSummaryString(buffer));
}
content.offer(new ContentChunk(buffer, callback));
}
示例5: onContent
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
@Override
public void onContent(Response response, ByteBuffer content) {
logger.debug("Jetty received response content of size {}", String.valueOf(content.remaining()));
JSONObject responseJson = new JSONObject();
try {
responseJson.put("id", mRequestId);
responseJson.put("body", BufferUtil.toArray(content));
socket.emit("responseContentBinary", responseJson);
logger.debug("Sent content to request {}", mRequestId);
} catch (JSONException e) {
logger.error("{}", e.getMessage());
}
}
示例6: onAllDataRead
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
@Override
public void onAllDataRead() throws IOException {
// succeeded?
if (!provider.isClosed()) {
process(BufferUtil.EMPTY_BUFFER, new Callback(){
@Override
public void failed(Throwable x) {
dialog.abort(x);
}
}, true);
}
_log.debug("{} proxying content to upstream completed", dialog.id());
super.close();
}
示例7: process
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
@Override
protected Action process() throws Exception {
ServletInputStream input = dialog.requestInputStream();
while (input.isReady() && !input.isFinished()) {
int read = input.read(buffer);
_log.debug("{} asynchronous read {} bytes on {}", dialog.id(), read, input);
if (read < 0)
return Action.SUCCEEDED;
if (contentLength > 0 && read > 0)
length += read;
ByteBuffer content = read > 0 ? ByteBuffer.wrap(buffer, 0, read) : BufferUtil.EMPTY_BUFFER;
boolean finished = length == contentLength;
process(content, this, finished);
if (read > 0)
return Action.SCHEDULED;
}
if (input.isFinished()) {
_log.debug("{} asynchronous read complete on {}", dialog.id(), input);
return Action.SUCCEEDED;
} else {
_log.debug("{} asynchronous read pending on {}", dialog.id(), input);
return Action.IDLE;
}
}
示例8: write
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
private ProxyWriter write(ByteBuffer content, boolean finished, Callback callback) throws Throwable {
int contentBytes = content.remaining();
ProxyWriter proxyWriter = dialog.attribute(WRITE_LISTENER_ATTRIBUTE, () -> new ProxyWriter(dialog));
ContentTransformer transformer = dialog.attribute(SERVER_TRANSFORMER, strategy::responseTransform);
try {
transformer.transform(content, finished, buffers);
} catch (IOException x) {
_log.info("Exception while transforming " + transformer, x);
throw x;
}
int newContentBytes = 0;
int size = buffers.size();
if (size > 0) {
Callback counter = size == 1 ? callback : new CountingCallback(callback, size);
for (int i = 0; i < size; ++i) {
ByteBuffer buffer = buffers.get(i);
newContentBytes += buffer.remaining();
proxyWriter.offer(buffer, counter);
}
buffers.clear();
} else {
proxyWriter.offer(BufferUtil.EMPTY_BUFFER, callback);
}
_log.debug("{} downstream content transformation {} -> {} bytes", dialog.id(), contentBytes, newContentBytes);
return proxyWriter;
}
示例9: onContent
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
@Override
public void onContent(Response response, ByteBuffer byteBuffer) {
LOG.info("content: " + BufferUtil.toString(byteBuffer));
LOG.info("");
}
示例10: onContent
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
@Override
public void onContent(Response response, ByteBuffer content) {
byte[] bytes = BufferUtil.toArray(content);
utf8Content.append(bytes, 0, bytes.length);
}
示例11: EchoConnection
import org.eclipse.jetty.util.BufferUtil; //导入依赖的package包/类
public EchoConnection(ByteBufferPool pool, EndPoint endp, Executor executor) {
super(endp, executor);
_bufferPool = pool;
if (_bufferPool == null)
_buffer = BufferUtil.allocate(BUF_MAX_LEN);
}