本文整理汇总了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;
}
示例2: cloneBuffer
import io.apiman.gateway.engine.io.IApimanBuffer; //导入方法依赖的package包/类
@Override
public IApimanBuffer cloneBuffer(IApimanBuffer buffer) {
return new ByteBuffer(buffer.getBytes());
}
示例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());
}