List of usage examples for com.google.common.io ByteSource read
public byte[] read() throws IOException
From source file:com.epam.reportportal.service.ReportPortalErrorHandler.java
private void handleError(Response<ByteSource> rs) throws RestEndpointIOException { try {/* w w w. j a va2s .c om*/ ByteSource errorBody = rs.getBody(); int statusCode = rs.getStatus(); String statusMessage = rs.getReason(); //read the body final byte[] body = errorBody.read(); //try to deserialize an error ErrorRS errorRS = deserializeError(body); if (null != errorRS) { //ok, it's known ReportPortal error throw new ReportPortalException(statusCode, statusMessage, errorRS); } else { if (isNotJson(rs)) { throw new InternalReportPortalClientException( "Report portal is not functioning correctly. Response is not json"); } else { //there is some unknown error since we cannot de-serialize it into default error object throw new GeneralReportPortalException(statusCode, statusMessage, new String(body, Charsets.UTF_8)); } } } catch (IOException e) { //cannot read the body. just throw the general error throw new GeneralReportPortalException(rs.getStatus(), rs.getReason(), "Cannot read the response"); } }
From source file:org.jasig.cas.extension.clearpass.EncryptedMapDecorator.java
/** * Read the contents of the source into a byte array. * @param source the byte array source/*from w ww . j a v a2 s .c o m*/ * @return the byte[] read from the source or null */ private byte[] consumeByteSourceOrNull(final ByteSource source) { try { if (source == null || source.isEmpty()) { return null; } return source.read(); } catch (final IOException e) { logger.warn("Could not consume the byte array source", e); return null; } }