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


Java IApimanBuffer.getBytes方法代码示例

本文整理汇总了Java中io.apiman.gateway.engine.io.IApimanBuffer.getBytes方法的典型用法代码示例。如果您正苦于以下问题:Java IApimanBuffer.getBytes方法的具体用法?Java IApimanBuffer.getBytes怎么用?Java IApimanBuffer.getBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.apiman.gateway.engine.io.IApimanBuffer的用法示例。


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

示例1: getResponseDataHandler

import io.apiman.gateway.engine.io.IApimanBuffer; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.policy.IDataPolicy#getResponseDataHandler(io.apiman.gateway.engine.beans.ApiResponse, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object)
 */
@Override
public IReadWriteStream<ApiResponse> getResponseDataHandler(final ApiResponse response,
        IPolicyContext context, Object policyConfiguration) {
    final DataFormat clientFormat = (DataFormat) context.getAttribute(CLIENT_FORMAT, null);
    final DataFormat serverFormat = (DataFormat) context.getAttribute(SERVER_FORMAT, null);

    if (isValidTransformation(clientFormat, serverFormat)) {
        final IBufferFactoryComponent bufferFactory = context.getComponent(IBufferFactoryComponent.class);
        final int contentLength = response.getHeaders().containsKey(CONTENT_LENGTH)
                ? Integer.parseInt(response.getHeaders().get(CONTENT_LENGTH))
                : 0;

        return new AbstractStream<ApiResponse>() {

            private IApimanBuffer readBuffer = bufferFactory.createBuffer(contentLength);

            @Override
            public ApiResponse getHead() {
                return response;
            }

            @Override
            protected void handleHead(ApiResponse head) {
            }

            @Override
            public void write(IApimanBuffer chunk) {
                byte[] bytes = chunk.getBytes();
                readBuffer.append(bytes);
            }

            @Override
            public void end() {
                if (readBuffer.length() > 0) {
                    DataTransformer dataTransformer = DataTransformerFactory.getDataTransformer(serverFormat, clientFormat);
                    IApimanBuffer writeBuffer = bufferFactory.createBuffer(readBuffer.length());

                    String data = dataTransformer.transform(new String(readBuffer.getBytes()));
                    writeBuffer.append(data);

                    super.write(writeBuffer);
                }
                super.end();
            }
        };
    }

    return null;
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:53,代码来源:TransformationPolicy.java

示例2: cloneBuffer

import io.apiman.gateway.engine.io.IApimanBuffer; //导入方法依赖的package包/类
@Override
public IApimanBuffer cloneBuffer(IApimanBuffer buffer) {
    return new ByteBuffer(buffer.getBytes());
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:5,代码来源:JsonpPolicyTest.java

示例3: cloneBuffer

import io.apiman.gateway.engine.io.IApimanBuffer; //导入方法依赖的package包/类
/**
 * @see io.apiman.gateway.engine.components.IBufferFactoryComponent#cloneBuffer(io.apiman.gateway.engine.io.IApimanBuffer)
 */
@Override
public IApimanBuffer cloneBuffer(IApimanBuffer buffer) {
    return new ByteBuffer(buffer.getBytes());
}
 
开发者ID:apiman,项目名称:apiman,代码行数:8,代码来源:ByteBufferFactoryComponent.java


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