All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dongliu.cute.http.body.FileBody Maven / Gradle / Ivy

The newest version!
package net.dongliu.cute.http.body;

import net.dongliu.cute.http.ContentType;

import java.io.FileNotFoundException;
import java.io.UncheckedIOException;
import java.net.http.HttpRequest.BodyPublisher;
import java.net.http.HttpRequest.BodyPublishers;
import java.nio.file.Path;

/**
 * Request body contains a file
 *
 * @author Liu Dong
 */
class FileBody extends AbstractBody {

    FileBody(Path body, ContentType contentType) {
        super(body, contentType);
    }

    @Override
    public BodyPublisher asBodyPublisher() {
        try {
            return BodyPublishers.ofFile(body());
        } catch (FileNotFoundException e) {
            throw new UncheckedIOException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy