gpt4 book ai didi

org.springframework.http.ZeroCopyHttpOutputMessage.writeWith()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 21:59:31 28 4
gpt4 key购买 nike

本文整理了Java中org.springframework.http.ZeroCopyHttpOutputMessage.writeWith()方法的一些代码示例,展示了ZeroCopyHttpOutputMessage.writeWith()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZeroCopyHttpOutputMessage.writeWith()方法的具体详情如下:
包路径:org.springframework.http.ZeroCopyHttpOutputMessage
类名称:ZeroCopyHttpOutputMessage
方法名:writeWith

ZeroCopyHttpOutputMessage.writeWith介绍

[英]Use the given File to write the body of the message to the underlying HTTP layer.
[中]使用给定的文件将消息体写入底层HTTP层。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Use the given {@link File} to write the body of the message to the underlying
 * HTTP layer.
 * @param file the file to transfer
 * @param position the position within the file from which the transfer is to begin
 * @param count the number of bytes to be transferred
 * @return a publisher that indicates completion or error.
 */
default Mono<Void> writeWith(File file, long position, long count) {
  return writeWith(file.toPath(), position, count);
}

代码示例来源:origin: org.springframework/spring-web

/**
 * Use the given {@link File} to write the body of the message to the underlying
 * HTTP layer.
 * @param file the file to transfer
 * @param position the position within the file from which the transfer is to begin
 * @param count the number of bytes to be transferred
 * @return a publisher that indicates completion or error.
 */
default Mono<Void> writeWith(File file, long position, long count) {
  return writeWith(file.toPath(), position, count);
}

代码示例来源:origin: spring-projects/spring-framework

private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region,
    ReactiveHttpOutputMessage message, Map<String, Object> hints) {
  if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) {
    try {
      File file = resource.getFile();
      long pos = region != null ? region.getPosition() : 0;
      long count = region != null ? region.getCount() : file.length();
      if (logger.isDebugEnabled()) {
        String formatted = region != null ? "region " + pos + "-" + (count) + " of " : "";
        logger.debug(Hints.getLogPrefix(hints) + "Zero-copy " + formatted + "[" + resource + "]");
      }
      return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
    }
    catch (IOException ex) {
      // should not happen
    }
  }
  return Optional.empty();
}

代码示例来源:origin: org.springframework/spring-web

private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region,
    ReactiveHttpOutputMessage message, Map<String, Object> hints) {
  if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) {
    try {
      File file = resource.getFile();
      long pos = region != null ? region.getPosition() : 0;
      long count = region != null ? region.getCount() : file.length();
      if (logger.isDebugEnabled()) {
        String formatted = region != null ? "region " + pos + "-" + (count) + " of " : "";
        logger.debug(Hints.getLogPrefix(hints) + "Zero-copy " + formatted + "[" + resource + "]");
      }
      return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
    }
    catch (IOException ex) {
      // should not happen
    }
  }
  return Optional.empty();
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
    try {
      ZeroCopyHttpOutputMessage zeroCopyResponse = (ZeroCopyHttpOutputMessage) response;
      Resource logo = new ClassPathResource("spring.png", ZeroCopyIntegrationTests.class);
      File logoFile = logo.getFile();
      zeroCopyResponse.getHeaders().setContentType(MediaType.IMAGE_PNG);
      zeroCopyResponse.getHeaders().setContentLength(logoFile.length());
      return zeroCopyResponse.writeWith(logoFile, 0, logoFile.length());
    }
    catch (Throwable ex) {
      return Mono.error(ex);
    }
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

/**
 * Use the given {@link File} to write the body of the message to the underlying
 * HTTP layer.
 * @param file the file to transfer
 * @param position the position within the file from which the transfer is to begin
 * @param count the number of bytes to be transferred
 * @return a publisher that indicates completion or error.
 */
default Mono<Void> writeWith(File file, long position, long count) {
  return writeWith(file.toPath(), position, count);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-web

private static Optional<Mono<Void>> zeroCopy(Resource resource, @Nullable ResourceRegion region,
    ReactiveHttpOutputMessage message, Map<String, Object> hints) {
  if (message instanceof ZeroCopyHttpOutputMessage && resource.isFile()) {
    try {
      File file = resource.getFile();
      long pos = region != null ? region.getPosition() : 0;
      long count = region != null ? region.getCount() : file.length();
      if (logger.isDebugEnabled()) {
        String formatted = region != null ? "region " + pos + "-" + (count) + " of " : "";
        logger.debug(Hints.getLogPrefix(hints) + "Zero-copy " + formatted + "[" + resource + "]");
      }
      return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
    }
    catch (IOException ex) {
      // should not happen
    }
  }
  return Optional.empty();
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com