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


Java IoCallback类代码示例

本文整理汇总了Java中io.undertow.io.IoCallback的典型用法代码示例。如果您正苦于以下问题:Java IoCallback类的具体用法?Java IoCallback怎么用?Java IoCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: writeBuffer

import io.undertow.io.IoCallback; //导入依赖的package包/类
private boolean writeBuffer(final ByteBuffer buffer, final IoCallback callback) {
    StringBuilder builder = new StringBuilder();
    try {
        builder.append(charsetDecoder.decode(buffer));
    } catch (CharacterCodingException e) {
        callback.onException(exchange, this, e);
        return false;
    }
    String data = builder.toString();
    writer.write(data);
    if (writer.checkError()) {
        callback.onException(exchange, this, new IOException());
        return false;
    }
    return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:BlockingWriterSenderImpl.java

示例2: queue

import io.undertow.io.IoCallback; //导入依赖的package包/类
private void queue(final ByteBuffer[] byteBuffers, final IoCallback ioCallback) {
    //if data is sent from withing the callback we queue it, to prevent the stack growing indefinitely
    if (next != null || pendingFile != null) {
        throw UndertowMessages.MESSAGES.dataAlreadyQueued();
    }
    StringBuilder builder = new StringBuilder();
    for (ByteBuffer buffer : byteBuffers) {
        try {
            builder.append(charsetDecoder.decode(buffer));
        } catch (CharacterCodingException e) {
            ioCallback.onException(exchange, this, e);
            return;
        }
    }
    this.next = builder.toString();
    queuedCallback = ioCallback;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:BlockingWriterSenderImpl.java

示例3: writeBinary

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Override
public UndertowResponse writeBinary(ISObject binary) {
    beforeWritingContent();
    File file = tryGetFileFrom(binary);
    if (null == file) {
        byte[] ba = binary.asByteArray();
        ByteBuffer buffer = ByteBuffer.wrap(ba);
        hse.getResponseSender().send(buffer);
    } else {
        try {
            hse.getResponseSender().transferFrom(FileChannel.open(file.toPath()), IoCallback.END_EXCHANGE);
            endAsync = true;
        } catch (IOException e) {
            endAsync = false;
            throw E.ioException(e);
        }
    }
    afterWritingContent();
    return this;
}
 
开发者ID:actframework,项目名称:actframework,代码行数:21,代码来源:UndertowResponse.java

示例4: onException

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Test
public void onException() throws Exception {
  IOException x = new IOException("intentional err");
  new MockUnit(IoCallback.class, HttpServerExchange.class, Sender.class, Logger.class)
      .expect(unit -> {
        unit.mockStatic(LoggerFactory.class);

        Logger log = unit.get(Logger.class);
        log.error("execution of {} resulted in exception", "/assets/main.js", x);

        expect(LoggerFactory.getLogger(NativeResponse.class)).andReturn(log);
        HttpServerExchange exchange = unit.get(HttpServerExchange.class);
        expect(exchange.getRequestPath()).andReturn("/assets/main.js");
        unit.get(IoCallback.class).onException(exchange, unit.get(Sender.class), x);
      })
      .run(unit -> {
        new LogIoCallback(unit.get(IoCallback.class))
            .onException(unit.get(HttpServerExchange.class), unit.get(Sender.class), x);
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:21,代码来源:LogIoCallbackTest.java

示例5: send

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Test
public void send() throws Exception {
  byte[] bytes = {0};
  CountDownLatch latch = new CountDownLatch(1);
  new MockUnit(HttpServerExchange.class, Sender.class)
    .expect(unit -> {
      Sender sender = unit.get(Sender.class);
      sender.send(eq(ByteBuffer.wrap(bytes)), unit.capture(IoCallback.class));

      HttpServerExchange exchange = unit.get(HttpServerExchange.class);
      expect(exchange.getResponseSender()).andReturn(sender);
    })
    .run(unit -> {
      new UndertowSse(unit.get(HttpServerExchange.class))
        .send(Optional.of("id"), bytes).whenComplete((id, x) -> {
        if (id != null) {
          assertEquals("id", id.get());
          latch.countDown();
        }
      });
    }, unit -> {
      IoCallback callback = unit.captured(IoCallback.class).iterator().next();
      callback.onComplete(unit.get(HttpServerExchange.class), unit.get(Sender.class));
      latch.await();
    });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:UndertowSseTest.java

示例6: sendNoIoThread2Chunks

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Test
public void sendNoIoThread2Chunks() throws Exception {
  new MockUnit(ReadableByteChannel.class, HttpServerExchange.class, IoCallback.class,
      Sender.class, PooledByteBuffer.class)
      .expect(exchange)
      .expect(noIoThread)
      .expect(pooled)
      .expect(readLargeChunk)
      .expect(transferEncoding)
      .expect(sendChunk)
      .expect(noIoThread)
      .expect(pooled)
      .expect(readChunk)
      .expect(sendChunk)
      .run(unit -> {
        ChunkedStream chunkedStream = new ChunkedStream();
        chunkedStream.send(unit.get(ReadableByteChannel.class),
            unit.get(HttpServerExchange.class), unit.get(IoCallback.class));
        chunkedStream.onComplete(unit.get(HttpServerExchange.class), unit.get(Sender.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:ChunkedStreamTest.java

示例7: sendNoIoThread2ChunksWithLen

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Test
public void sendNoIoThread2ChunksWithLen() throws Exception {
  new MockUnit(ReadableByteChannel.class, HttpServerExchange.class, IoCallback.class,
      Sender.class, PooledByteBuffer.class)
      .expect(exchange)
      .expect(noIoThread)
      .expect(pooled)
      .expect(readLargeChunk)
      .expect(len)
      .expect(sendChunk)
      .expect(noIoThread)
      .expect(pooled)
      .expect(readChunk)
      .expect(sendChunk)
      .run(unit -> {
        ChunkedStream chunkedStream = new ChunkedStream();
        chunkedStream.send(unit.get(ReadableByteChannel.class),
            unit.get(HttpServerExchange.class), unit.get(IoCallback.class));
        chunkedStream.onComplete(unit.get(HttpServerExchange.class), unit.get(Sender.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:ChunkedStreamTest.java

示例8: sendIoThread

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Test
public void sendIoThread() throws Exception {
  new MockUnit(ReadableByteChannel.class, HttpServerExchange.class, IoCallback.class,
      Sender.class, PooledByteBuffer.class)
      .expect(exchange)
      .expect(ioThread)
      .expect(pooled)
      .expect(readChunk)
      .expect(nolen)
      .expect(sendChunk)
      .run(unit -> {
        ChunkedStream chunkedStream = new ChunkedStream();
        chunkedStream.send(unit.get(ReadableByteChannel.class),
            unit.get(HttpServerExchange.class), unit.get(IoCallback.class));
        chunkedStream.run();
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:18,代码来源:ChunkedStreamTest.java

示例9: send

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Override
public void send(final ByteBuffer buffer, final IoCallback callback) {
    if (inCall) {
        queue(new ByteBuffer[]{buffer}, callback);
        return;
    }
    if (writeBuffer(buffer, callback)) {
        invokeOnComplete(callback);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:BlockingWriterSenderImpl.java

示例10: transferFrom

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Override
public void transferFrom(FileChannel source, IoCallback callback) {
    if (inCall) {
        queue(source, callback);
        return;
    }
    performTransfer(source, callback);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:BlockingWriterSenderImpl.java

示例11: performTransfer

import io.undertow.io.IoCallback; //导入依赖的package包/类
private void performTransfer(FileChannel source, IoCallback callback) {

        ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
        try {
            long pos = source.position();
            long size = source.size();
            while (size - pos > 0) {
                int ret = source.read(buffer);
                if (ret <= 0) {
                    break;
                }
                pos += ret;
                buffer.flip();
                if (!writeBuffer(buffer, callback)) {
                    return;
                }
                buffer.clear();
            }

            if (pos != size) {
                throw new EOFException("Unexpected EOF reading file");
            }

        } catch (IOException e) {
            callback.onException(exchange, this, e);
        }
        invokeOnComplete(callback);
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:BlockingWriterSenderImpl.java

示例12: sendContinueResponse

import io.undertow.io.IoCallback; //导入依赖的package包/类
/**
 * Sends a continuation using async IO, and calls back when it is complete.
 *
 * @param exchange The exchange
 * @param callback The completion callback
 */
public static void sendContinueResponse(final HttpServerExchange exchange, final IoCallback callback) {
    if (!exchange.isResponseChannelAvailable()) {
        callback.onException(exchange, null, UndertowMessages.MESSAGES.cannotSendContinueResponse());
        return;
    }
    internalSendContinueResponse(exchange, callback);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:HttpContinue.java

示例13: send

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Override
public void send(final ByteBuffer[] srcs, final IoCallback callback) {
    ByteBuffer[] origSrc = new ByteBuffer[srcs.length];
    long total = 0;
    for (int i = 0; i < srcs.length; i++) {
        origSrc[i] = srcs[i].duplicate();
        total += origSrc[i].remaining();
    }
    handleUpdate(origSrc, total);
    delegate.send(srcs, callback);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:ResponseCachingSender.java

示例14: close

import io.undertow.io.IoCallback; //导入依赖的package包/类
@Override
public void close(final IoCallback callback) {
    if (written != length) {
        cacheEntry.disable();
        cacheEntry.dereference();
    }
    delegate.close();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:ResponseCachingSender.java

示例15: send

import io.undertow.io.IoCallback; //导入依赖的package包/类
public void send(final ReadableByteChannel source, final HttpServerExchange exchange,
        final IoCallback callback) {
    this.source = source;
    this.exchange = exchange;
    this.callback = callback;
    this.sender = exchange.getResponseSender();
    ServerConnection connection = exchange.getConnection();
    this.pooled = connection.getByteBufferPool().allocate();
    this.bufferSize = connection.getBufferSize();

    onComplete(exchange, sender);
}
 
开发者ID:MTDdk,项目名称:jawn,代码行数:13,代码来源:UndertowResponse.java


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