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

com.cloudconvert.processor.response.DefaultResponseProcessor Maven / Gradle / Ivy

Go to download

CloudConvert is an online file converter API - more than 200 different audio, video, document, ebook, archive, image, spreadsheet and presentation formats supported.

There is a newer version: 1.2.1
Show newest version
package com.cloudconvert.processor.response;

import com.cloudconvert.dto.result.Result;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.base.Charsets;
import com.google.common.io.ByteSource;
import org.apache.http.Header;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.stream.Collectors;

public class DefaultResponseProcessor implements ResponseProcessor {

    @Override
    public  Result process(
        final int status, final Header[] headers, final InputStream inputStream, final TypeReference typeReference
    ) throws IOException {
        final ByteSource byteSource = new ByteSource() {
            @Override
            public InputStream openStream() throws IOException {
                return inputStream;
            }
        };

        return Result.builder().status(status).headers(Arrays.stream(headers).collect(Collectors.toMap(Header::getName, Header::getValue)))
            .message(byteSource.asCharSource(Charsets.UTF_8).read()).build();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy