use of com.github.ljtfreitas.julian.http.MediaType in project julian-http-client by ljtfreitas.
the class MapMultipartFormHTTPRequestWriter method write.
@Override
public HTTPRequestBody write(Map<String, ?> map, Charset encoding) {
String boundary = boundaryGen.run();
MediaType mediaType = MediaType.MULTIPART_FORM_DATA.parameter("boundary", boundary);
return new DefaultHTTPRequestBody(mediaType, () -> serialize(map, encoding, "----" + boundary));
}
use of com.github.ljtfreitas.julian.http.MediaType in project julian-http-client by ljtfreitas.
the class ByteArraySerializer method write.
@Override
public void write(String boundary, MultipartFormField<byte[]> field, Charset charset, OutputStream output) {
ContentDisposition contentDisposition = new ContentDisposition(field.name);
MediaType mediaType = field.contentType.orElse(MEDIA_TYPE_OCTET_STREAM);
new MultipartFormFieldWriter(output, boundary, contentDisposition, mediaType).write(o -> output.write(field.value)).prop(e -> new HTTPRequestWriterException(Message.format("Cannot write multipart/form-data field {0}", field.name), e));
}
use of com.github.ljtfreitas.julian.http.MediaType in project julian-http-client by ljtfreitas.
the class ByteBufferSerializer method write.
@Override
public void write(String boundary, MultipartFormField<ByteBuffer> field, Charset charset, OutputStream output) {
ContentDisposition contentDisposition = new ContentDisposition(field.name);
MediaType mediaType = field.contentType.orElse(MEDIA_TYPE_OCTET_STREAM);
new MultipartFormFieldWriter(output, boundary, contentDisposition, mediaType).write(o -> output.write(field.value.array())).prop(e -> new HTTPRequestWriterException(Message.format("Cannot write multipart/form-data field {0}", field.name), e));
}
use of com.github.ljtfreitas.julian.http.MediaType in project julian-http-client by ljtfreitas.
the class FileSerializer method write.
@Override
public void write(String boundary, MultipartFormField<File> field, Charset charset, OutputStream output) {
File file = field.value;
ContentDisposition contentDisposition = new ContentDisposition(field.name, file.getName());
MediaType mediaType = field.contentType.orElseGet(() -> Except.run(() -> Files.probeContentType(file.toPath())).map(MediaType::valueOf).recover(() -> MEDIA_TYPE_OCTET_STREAM));
new MultipartFormFieldWriter(output, boundary, contentDisposition, mediaType).write(o -> Files.copy(file.toPath(), output)).prop(e -> new HTTPRequestWriterException(Message.format("Cannot write multipart/form-data field {0}", field.name), e));
}
use of com.github.ljtfreitas.julian.http.MediaType in project julian-http-client by ljtfreitas.
the class InputStreamSerializer method write.
@Override
public void write(String boundary, MultipartFormField<InputStream> field, Charset charset, OutputStream output) {
ContentDisposition contentDisposition = new ContentDisposition(field.name);
MediaType mediaType = field.contentType.orElse(MEDIA_TYPE_OCTET_STREAM);
new MultipartFormFieldWriter(output, boundary, contentDisposition, mediaType).write(o -> field.value.transferTo(output)).prop(e -> new HTTPRequestWriterException(Message.format("Cannot write multipart/form-data field {0}", field.name), e));
}
Aggregations