use of cn.taketoday.http.ZeroCopyHttpOutputMessage in project today-infrastructure by TAKETODAY.
the class ResourceHttpMessageWriter method zeroCopy.
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 size = file.length();
long pos = region != null ? region.getPosition() : 0;
long count = region != null ? region.getCount() : size;
if (logger.isDebugEnabled()) {
String formatted = region != null ? "region " + pos + "-" + (count) + " of " : "";
logger.debug("{}Zero-copy {}[{}]", Hints.getLogPrefix(hints), formatted, resource);
}
return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
} catch (IOException ex) {
// should not happen
}
}
return Optional.empty();
}
use of cn.taketoday.http.ZeroCopyHttpOutputMessage in project today-framework by TAKETODAY.
the class ResourceHttpMessageWriter method zeroCopy.
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 size = file.length();
long pos = region != null ? region.getPosition() : 0;
long count = region != null ? region.getCount() : size;
if (logger.isDebugEnabled()) {
String formatted = region != null ? "region " + pos + "-" + (count) + " of " : "";
logger.debug("{}Zero-copy {}[{}]", Hints.getLogPrefix(hints), formatted, resource);
}
return Optional.of(((ZeroCopyHttpOutputMessage) message).writeWith(file, pos, count));
} catch (IOException ex) {
// should not happen
}
}
return Optional.empty();
}
Aggregations