morristech
5/8/2018 - 12:27 PM

Retrofit StringTypedOutput, it can be used for deserializing XML or just pulling a string

Retrofit StringTypedOutput, it can be used for deserializing XML or just pulling a string

import java.io.IOException;
import java.io.OutputStream;

import retrofit.mime.TypedOutput;

public class StringTypedOutput implements TypedOutput {

	private final byte[] xmlBytes;

	StringTypedOutput(byte[] xmlBytes) {
        this.xmlBytes = xmlBytes;
    }

    @Override
    public String fileName() {
        return null;
    }

    @Override
    public String mimeType() {
        return "application/xml; charset=UTF-8";
    }

    @Override
    public long length() {
        return xmlBytes.length;
    }

    @Override
    public void writeTo(OutputStream out) throws IOException {
        out.write(xmlBytes);
    }
}