001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.http;
018
019import java.io.File;
020import java.nio.file.Path;
021
022import reactor.core.publisher.Mono;
023
024/**
025 * Sub-interface of {@code ReactiveOutputMessage} that has support for "zero-copy"
026 * file transfers.
027 *
028 * @author Arjen Poutsma
029 * @author Juergen Hoeller
030 * @since 5.0
031 * @see <a href="https://en.wikipedia.org/wiki/Zero-copy">Zero-copy</a>
032 */
033public interface ZeroCopyHttpOutputMessage extends ReactiveHttpOutputMessage {
034
035        /**
036         * Use the given {@link File} to write the body of the message to the underlying
037         * HTTP layer.
038         * @param file the file to transfer
039         * @param position the position within the file from which the transfer is to begin
040         * @param count the number of bytes to be transferred
041         * @return a publisher that indicates completion or error.
042         */
043        default Mono<Void> writeWith(File file, long position, long count) {
044                return writeWith(file.toPath(), position, count);
045        }
046
047        /**
048         * Use the given {@link Path} to write the body of the message to the underlying
049         * HTTP layer.
050         * @param file the file to transfer
051         * @param position the position within the file from which the transfer is to begin
052         * @param count the number of bytes to be transferred
053         * @return a publisher that indicates completion or error.
054         * @since 5.1
055         */
056        Mono<Void> writeWith(Path file, long position, long count);
057
058}