• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ContentEncoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: produceContent

import org.apache.http.nio.ContentEncoder; //导入依赖的package包/类
@Override
public synchronized void produceContent(ContentEncoder encoder,
        IOControl ioctrl) throws IOException {
    checkCanceled(isCanceled);

    byte[] tmp = new byte[4096];
    int len = httpInStream.read(tmp);
    ByteBuffer buffer = ByteBuffer.wrap(tmp, 0, len);
    encoder.write(buffer);
    writeLength += len;

    if (httpListener != null) {
        httpListener.onHttpWrite(writeLength, contentLength);
    }
    checkCanceled(isCanceled);
}
 
开发者ID:shisoft,项目名称:WebQQCore,代码行数:17,代码来源:ApacheHttpService.java


示例2: produceContent

import org.apache.http.nio.ContentEncoder; //导入依赖的package包/类
public void produceContent(
        final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
    synchronized (this.httpExchange) {
        this.httpExchange.setOriginIOControl(ioctrl);
        // Send data to the origin server
        ByteBuffer buf = this.httpExchange.getInBuffer();
        buf.flip();
        int n = encoder.write(buf);
        buf.compact();
        System.out.println("[proxy->origin] " + this.httpExchange.getId() + " " + n + " bytes written");
        ConsoleFactory.printToConsole("[proxy->origin] " + this.httpExchange.getId() + " " + n + " bytes written",true);
        // If there is space in the buffer and the message has not been
        // transferred, make sure the client is sending more data
        if (buf.hasRemaining() && !this.httpExchange.isRequestReceived()) {
            if (this.httpExchange.getClientIOControl() != null) {
                this.httpExchange.getClientIOControl().requestInput();
                System.out.println("[proxy->origin] " + this.httpExchange.getId() + " request client input");
                ConsoleFactory.printToConsole("[proxy->origin] " + this.httpExchange.getId() + " request client input",true);
            }
        }
        if (buf.position() == 0) {
            if (this.httpExchange.isRequestReceived()) {
                encoder.complete();
                System.out.println("[proxy->origin] " + this.httpExchange.getId() + " content fully written");
                ConsoleFactory.printToConsole("[proxy->origin] " + this.httpExchange.getId() + " content fully written",true);
            } else {
                // Input buffer is empty. Wait until the client fills up
                // the buffer
                ioctrl.suspendOutput();
                System.out.println("[proxy->origin] " + this.httpExchange.getId() + " suspend origin output");
                ConsoleFactory.printToConsole("[proxy->origin] " + this.httpExchange.getId() + " suspend origin output",true);
            }
        }
    }
}
 
开发者ID:HuaweiSNC,项目名称:OpsDev,代码行数:36,代码来源:NHttpReverseProxy.java


示例3: outputReady

import org.apache.http.nio.ContentEncoder; //导入依赖的package包/类
public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) {
    System.out.println(conn + " [client<-proxy] output ready");

    HttpContext context = conn.getContext();
    ProxyTask proxyTask = (ProxyTask) context.getAttribute(ProxyTask.ATTRIB);

    synchronized (proxyTask) {
        ConnState connState = proxyTask.getClientState();
        if (connState != ConnState.RESPONSE_SENT
                && connState != ConnState.RESPONSE_BODY_STREAM) {
            throw new IllegalStateException("Illegal client connection state: " + connState);
        }

        HttpResponse response = proxyTask.getResponse();
        if (response == null) {
            throw new IllegalStateException("HTTP request is null");
        }
        
        try {

            ByteBuffer src = proxyTask.getOutBuffer();
            src.flip();
            int bytesWritten = encoder.write(src);
            System.out.println(conn + " [client<-proxy] " + bytesWritten + " bytes written");
            System.out.println(conn + " [client<-proxy] " + encoder);
            src.compact();

            if (src.position() == 0) {

                if (proxyTask.getOriginState() == ConnState.RESPONSE_BODY_DONE) {
                    encoder.complete();
                } else {
                    // Input output is empty. Wait until the origin handler 
                    // fills up the buffer
                    conn.suspendOutput();
                }
            }

            // Update connection state
            if (encoder.isCompleted()) {
                System.out.println(conn + " [proxy] response body sent");
                proxyTask.setClientState(ConnState.RESPONSE_BODY_DONE);
                if (!this.connStrategy.keepAlive(response, context)) {
                    System.out.println(conn + " [client<-proxy] close connection");
                    proxyTask.setClientState(ConnState.CLOSING);
                    conn.close();
                } else {
                    // Reset connection state
                    proxyTask.reset();
                    conn.requestInput();
                    // Ready to deal with a new request
                }
            } else {
                proxyTask.setClientState(ConnState.RESPONSE_BODY_STREAM);
                // Make sure origin input is active
                proxyTask.getOriginIOControl().requestInput();
            }
            
        } catch (IOException ex) {
            shutdownConnection(conn);
        } 
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:64,代码来源:NHttpReverseProxy.java


示例4: outputReady

import org.apache.http.nio.ContentEncoder; //导入依赖的package包/类
public void outputReady(NHttpClientConnection conn, ContentEncoder encoder) {
    this.handler.outputReady(conn, encoder);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:4,代码来源:NHttpClientConnManagement.java


示例5: MyHttpAsyncContentProducer

import org.apache.http.nio.ContentEncoder; //导入依赖的package包/类
MyHttpAsyncContentProducer(final Function<ContentEncoder, ContentWriter> producerFunc) {
  this.producerFunc = producerFunc;
  writer = null;
}
 
开发者ID:SumoLogic,项目名称:epigraph,代码行数:5,代码来源:FormatBasedServerProtocol.java


示例6: produceContent

import org.apache.http.nio.ContentEncoder; //导入依赖的package包/类
@Override
public void produceContent(final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
  writer = producerFunc.apply(encoder);
  writer.write();
}
 
开发者ID:SumoLogic,项目名称:epigraph,代码行数:6,代码来源:FormatBasedServerProtocol.java


示例7: produceContent

import org.apache.http.nio.ContentEncoder; //导入依赖的package包/类
@Override
public synchronized void produceContent(final ContentEncoder encoder, final IOControl ioctrl)
        throws IOException {
    final boolean first;

    if (this.mItemIterator == null) {
        this.mItemIterator = this.mItems.iterator();
        first = true;
    } else {
        first = false;
    }

    if (this.mItem == null && this.mItemIterator.hasNext()) {
        this.mItem = this.mItemIterator.next();
        this.mMultipartHeaderIndex = 0;
    }

    if (this.mItem != null) {
        if (!this.writeHeader(encoder, ioctrl, this.mItem, first)) {
            return;
        }

        if (this.mFileChannel == null) {
            this.mFile = new RandomAccessFile(this.mItem.getFile(), "r");
            this.mFileChannel = this.mFile.getChannel();
            this.mFilePosition = 0;
        }

        final long transferred;

        if (encoder instanceof FileContentEncoder) {
            transferred = ((FileContentEncoder) encoder).transfer(this.mFileChannel, this.mFilePosition, Integer.MAX_VALUE);

        } else {
            transferred = this.mFileChannel.transferTo(this.mFilePosition, Integer.MAX_VALUE, new ContentEncoderChannel(encoder));

        }

        if (transferred > 0) {
            this.mFilePosition += transferred;
        }

        if (this.mFilePosition >= this.mFileChannel.size()) {
            IOUtils.closeQuietly(this.mFileChannel);
            IOUtils.closeQuietly(this.mFile);
            this.mFileChannel = null;
            this.mFile = null;
            this.mItem = null;
        }
    }

    if (this.mItem == null && !this.mItemIterator.hasNext() && this.writeFooter(encoder, ioctrl)) {
        encoder.complete();
    }
}
 
开发者ID:mwaylabs,项目名称:relution-jenkins-plugin,代码行数:56,代码来源:ZeroCopyFileRequestProducer.java


示例8: ContentEncodingOutputStream

import org.apache.http.nio.ContentEncoder; //导入依赖的package包/类
public ContentEncodingOutputStream(final @NotNull ContentEncoder encoder) {this.encoder = encoder;} 
开发者ID:SumoLogic,项目名称:epigraph,代码行数:2,代码来源:ContentEncodingOutputStream.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CompletionProposal类代码示例发布时间:2022-05-22
下一篇:
Java IScannerInfo类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap