uk.co.autotrader.traverson.conversion.StringResourceConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of traverson4j-core Show documentation
Show all versions of traverson4j-core Show documentation
The kernel of traverson4j. This provides the main API for a client to traverse a Hypermedia REST service
The newest version!
package uk.co.autotrader.traverson.conversion;
import uk.co.autotrader.traverson.exception.ConversionException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
class StringResourceConverter implements ResourceConverter {
@Override
public Class getDestinationType() {
return String.class;
}
@Override
public String convert(InputStream resource, Class extends String> returnType) {
try (InputStream streamToProcess = resource) {
return new String(streamToProcess.readAllBytes(), StandardCharsets.UTF_8);
} catch (IOException e) {
throw new ConversionException("Failed to convert the input stream to a string", null, e);
}
}
}