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

Java DataBuffer类代码示例

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

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



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

示例1: renderInternal

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Override
protected Mono<Void> renderInternal(Map<String, Object> model, MediaType contentType,
                                    ServerWebExchange exchange) {
    Resource resource = resolveResource();
    if (resource == null) {
        return Mono.error(new IllegalStateException(
                "Could not find Mustache template with URL [" + getUrl() + "]"));
    }
    DataBuffer dataBuffer = exchange.getResponse().bufferFactory().allocateBuffer();
    try (Reader reader = getReader(resource)) {
        Template template = this.compiler.compile(reader);
        Charset charset = getCharset(contentType).orElse(getDefaultCharset());
        try (Writer writer = new OutputStreamWriter(dataBuffer.asOutputStream(),
                charset)) {
            template.execute(model, writer);
            writer.flush();
        }
    }
    catch (Exception ex) {
        DataBufferUtils.release(dataBuffer);
        return Mono.error(ex);
    }
    return exchange.getResponse().writeWith(Flux.just(dataBuffer));
}
 
开发者ID:hantsy,项目名称:spring-reactive-sample,代码行数:25,代码来源:MustacheView.java


示例2: exchange

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@GetMapping("/exchange")
public Mono<Void> exchange(ServerWebExchange webExchange) {
    ServerHttpResponse response = webExchange.getResponse();
    response.setStatusCode(HttpStatus.OK);
    response.getHeaders().setContentType(MediaType.TEXT_PLAIN);
    DataBuffer dataBuffer = factory.allocateBuffer().write("Using exchange!".getBytes(StandardCharsets.UTF_8));
    return response.writeWith(Mono.just(dataBuffer));
}
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:9,代码来源:SampleController.java


示例3: buildBody

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
private BodyInserter<?, ? super ClientHttpRequest> buildBody(Object[] args) {
    if (bodyIndex == null) {
        return BodyInserters.empty();
    }
    
    Object body = args[bodyIndex];
    if (isDataBufferPublisher(requestBodyType)) {
        return BodyInserters.fromDataBuffers((Publisher<DataBuffer>) body);
    } else if (isPublisher(requestBodyType)) {
        return BodyInserters.fromPublisher((Publisher) body, requestBodyType.getGeneric(0).getRawClass());
    } else if (isResource(requestBodyType)) {
        return BodyInserters.fromResource((Resource) body);
    } else if (isFormData(requestBodyType)) {
        return BodyInserters.fromFormData((MultiValueMap<String, String>) body);
    } else {
        return BodyInserters.fromObject(body);
    }
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:19,代码来源:RequestTemplate.java


示例4: post

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@PostMapping
public Mono<ResponseEntity<String>> post(@PathVariable String applicationId,
		ServerHttpRequest request) {
	return configure(this.webClient.post(), applicationId, request) //
			.flatMap(spec -> spec
					.header(CONTENT_TYPE, request.getHeaders().getFirst(CONTENT_TYPE)) //
					.body(request.getBody(), DataBuffer.class) //
					.exchange() //
					.flatMap(res -> res.bodyToMono(String.class) //
							.map(b -> ResponseEntity.status(res.statusCode()).body(b)) //
							.switchIfEmpty(emptyResponse(res))));
}
 
开发者ID:making,项目名称:spring-boot-actuator-dashboard,代码行数:13,代码来源:ProxyController.java


示例5: readToString

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
public static String readToString(DataBuffer dataBuffer) {
    try {
        return FileCopyUtils.copyToString(new InputStreamReader(dataBuffer.asInputStream()));
    }
    catch (IOException e) {
        return e.getMessage();
    }
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:9,代码来源:DataBuffers.java


示例6: readMono

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Test
public void readMono(){
    HttpStatus status = HttpStatus.BAD_REQUEST;
    ClientHttpResponse httpResponse = request(status, "Exception Mono error message");
    RuntimeException exception = new HttpServerException(status);
    when(errorDecoder.decode(same(status), any(DataBuffer.class))).thenReturn(exception);

    StepVerifier.create(errorReader.readMono(httpResponse))
            .verifyError(HttpServerException.class);
    
    verify(errorDecoder).decode(same(status), any(DataBuffer.class));
    verifyNoMoreInteractions(errorDecoder);
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:14,代码来源:DecoderHttpErrorReaderTest.java


示例7: read

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Test
public void read(){
    HttpStatus status = HttpStatus.BAD_REQUEST;
    ClientHttpResponse httpResponse = request(status, "Exception Flux error message");
    RuntimeException exception = new HttpServerException(status);
    when(errorDecoder.decode(same(status), any(DataBuffer.class))).thenReturn(exception);
    
    StepVerifier.create(errorReader.read(httpResponse))
            .verifyError(HttpServerException.class);
    
    verify(errorDecoder).decode(same(status), any(DataBuffer.class));
    verifyNoMoreInteractions(errorDecoder);
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:14,代码来源:DecoderHttpErrorReaderTest.java


示例8: ConvertedBodyResponse

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
private ConvertedBodyResponse(ClientResponse response,
                              Function<Flux<DataBuffer>, Flux<DataBuffer>> converter,
                              MediaType contentType) {
    this.response = response;
    this.converter = converter;
    this.headers = new Headers() {
        @Override
        public OptionalLong contentLength() {
            return response.headers().contentLength();
        }

        @Override
        public Optional<MediaType> contentType() {
            return Optional.ofNullable(contentType);
        }

        @Override
        public List<String> header(String headerName) {
            if (headerName.equals(HttpHeaders.CONTENT_TYPE)) {
                return singletonList(contentType.toString());
            }
            return response.headers().header(headerName);
        }

        @Override
        public HttpHeaders asHttpHeaders() {
            HttpHeaders newHeaders = new HttpHeaders();
            newHeaders.putAll(response.headers().asHttpHeaders());
            newHeaders.replace(HttpHeaders.CONTENT_TYPE, singletonList(contentType.toString()));
            return HttpHeaders.readOnlyHttpHeaders(newHeaders);
        }
    };
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:34,代码来源:InstanceFilterFunctions.java


示例9: body

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Override
public <T> T body(BodyExtractor<T, ? super ClientHttpResponse> extractor) {
    return response.body((inputMessage, context) -> {
        ClientHttpResponse convertedMessage = new ClientHttpResponseDecorator(inputMessage) {
            @Override
            public Flux<DataBuffer> getBody() {
                return super.getBody().transform(ConvertedBodyResponse.this.converter);
            }
        };
        return extractor.extract(convertedMessage, context);
    });
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:13,代码来源:InstanceFilterFunctions.java


示例10: convertUsing

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <S, T> Function<Flux<DataBuffer>, Flux<DataBuffer>> convertUsing(ParameterizedTypeReference<S> sourceType,
                                                                                ParameterizedTypeReference<T> targetType,
                                                                                Function<S, T> converterFn) {
    return input -> DECODER.decodeToMono(input, ResolvableType.forType(sourceType), null, null)
                           .map(body -> converterFn.apply((S) body))
                           .flatMapMany(output -> ENCODER.encode(Mono.just(output), new DefaultDataBufferFactory(),
                                   ResolvableType.forType(targetType), null, null));
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:10,代码来源:LegacyEndpointConverters.java


示例11: should_convert_health

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Test
public void should_convert_health() {
    LegacyEndpointConverter converter = LegacyEndpointConverters.health();
    assertThat(converter.canConvert("health")).isTrue();
    assertThat(converter.canConvert("foo")).isFalse();

    Flux<DataBuffer> legacyInput = this.read("health-legacy.json");

    Flux<Object> converted = converter.convert(legacyInput).transform(this::unmarshal);
    Flux<Object> expected = this.read("health-expected.json").transform(this::unmarshal);

    StepVerifier.create(Flux.zip(converted, expected))
                .assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
                .verifyComplete();
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:16,代码来源:LegacyEndpointConvertersTest.java


示例12: should_convert_env

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Test
public void should_convert_env() {
    LegacyEndpointConverter converter = LegacyEndpointConverters.env();
    assertThat(converter.canConvert("env")).isTrue();
    assertThat(converter.canConvert("foo")).isFalse();

    Flux<DataBuffer> legacyInput = this.read("env-legacy.json");

    Flux<Object> converted = converter.convert(legacyInput).transform(this::unmarshal);
    Flux<Object> expected = this.read("env-expected.json").transform(this::unmarshal);

    StepVerifier.create(Flux.zip(converted, expected))
                .assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
                .verifyComplete();
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:16,代码来源:LegacyEndpointConvertersTest.java


示例13: should_convert_trace

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Test
public void should_convert_trace() {
    LegacyEndpointConverter converter = LegacyEndpointConverters.httptrace();
    assertThat(converter.canConvert("httptrace")).isTrue();
    assertThat(converter.canConvert("foo")).isFalse();

    Flux<DataBuffer> legacyInput = this.read("httptrace-legacy.json");

    Flux<Object> converted = converter.convert(legacyInput).transform(this::unmarshal);
    Flux<Object> expected = this.read("httptrace-expected.json").transform(this::unmarshal);

    StepVerifier.create(Flux.zip(converted, expected))
                .assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
                .verifyComplete();
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:16,代码来源:LegacyEndpointConvertersTest.java


示例14: should_convert_threaddump

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Test
public void should_convert_threaddump() {
    LegacyEndpointConverter converter = LegacyEndpointConverters.threaddump();
    assertThat(converter.canConvert("threaddump")).isTrue();
    assertThat(converter.canConvert("foo")).isFalse();

    Flux<DataBuffer> legacyInput = this.read("threaddump-legacy.json");

    Flux<Object> converted = converter.convert(legacyInput).transform(this::unmarshal);
    Flux<Object> expected = this.read("threaddump-expected.json").transform(this::unmarshal);

    StepVerifier.create(Flux.zip(converted, expected))
                .assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
                .verifyComplete();
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:16,代码来源:LegacyEndpointConvertersTest.java


示例15: should_convert_liquibase

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Test
public void should_convert_liquibase() {
    LegacyEndpointConverter converter = LegacyEndpointConverters.liquibase();
    assertThat(converter.canConvert("liquibase")).isTrue();
    assertThat(converter.canConvert("foo")).isFalse();

    Flux<DataBuffer> legacyInput = this.read("liquibase-legacy.json");

    Flux<Object> converted = converter.convert(legacyInput).transform(this::unmarshal);
    Flux<Object> expected = this.read("liquibase-expected.json").transform(this::unmarshal);

    StepVerifier.create(Flux.zip(converted, expected))
                .assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
                .verifyComplete();
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:16,代码来源:LegacyEndpointConvertersTest.java


示例16: should_convert_flyway

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Test
public void should_convert_flyway() {
    LegacyEndpointConverter converter = LegacyEndpointConverters.flyway();
    assertThat(converter.canConvert("flyway")).isTrue();
    assertThat(converter.canConvert("foo")).isFalse();

    Flux<DataBuffer> legacyInput = this.read("flyway-legacy.json");

    Flux<Object> converted = converter.convert(legacyInput).transform(this::unmarshal);
    Flux<Object> expected = this.read("flyway-expected.json").transform(this::unmarshal);

    StepVerifier.create(Flux.zip(converted, expected))
                .assertNext(t -> assertThat(t.getT1()).isEqualTo(t.getT2()))
                .verifyComplete();
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:16,代码来源:LegacyEndpointConvertersTest.java


示例17: decode

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Override
public HttpClientException decode(HttpStatus httpStatus, DataBuffer inputMessage) {
    return new HttpClientException(httpStatus, DataBuffers.readToString(inputMessage));
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:5,代码来源:HttpClientErrorDecoder.java


示例18: decode

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Override
public HttpServerException decode(HttpStatus httpStatus, DataBuffer inputMessage) {
    return new HttpServerException(httpStatus, DataBuffers.readToString(inputMessage));
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:5,代码来源:HttpServerErrorDecoder.java


示例19: create

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
private DataBuffer create(String value) {
    return new DefaultDataBufferFactory().wrap(value.getBytes());
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:4,代码来源:HttpServerErrorDecoderTest.java


示例20: encode

import org.springframework.core.io.buffer.DataBuffer; //导入依赖的package包/类
@Override
public Flux<DataBuffer> encode(Publisher publisher, DataBufferFactory dataBufferFactory, ResolvableType resolvableType, @Nullable MimeType mimeType, @Nullable Map map) {
    return null;
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:5,代码来源:DefaultExtendedClientCodecConfigurerTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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