com.inversoft.rest.TextResponseHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of restify Show documentation
Show all versions of restify Show documentation
The Java 8 REST Client used in our commercial REST Client libraries such as Passport Java Client and our Java 8 Chef Client called Barista
/*
* Copyright (c) 2016, Inversoft Inc., All Rights Reserved
*/
package com.inversoft.rest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Response handler that reads the entire body and converts it to a UTF-8 String.
*
* @author Brian Pontarelli
*/
public class TextResponseHandler implements RESTClient.ResponseHandler {
@Override
public String apply(InputStream is) throws IOException {
if (is == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int read;
while ((read = is.read(buf)) != -1) {
baos.write(buf, 0, read);
}
return baos.toString("UTF-8");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy