Revised get avatar helper method
This commit is contained in:
parent
8dc8f1d2a7
commit
35459bec6b
|
@ -274,21 +274,24 @@ public class OpenIdConnectRESTHelper {
|
||||||
logger.debug("Adding authorization header as: {}", authorization);
|
logger.debug("Adding authorization header as: {}", authorization);
|
||||||
conn.setRequestProperty("Authorization", authorization);
|
conn.setRequestProperty("Authorization", authorization);
|
||||||
}
|
}
|
||||||
String contentType = conn.getContentType();
|
if (conn.getResponseCode() == 200) {
|
||||||
int contentLength = conn.getContentLength();
|
String contentType = conn.getContentType();
|
||||||
|
|
||||||
logger.debug("Getting the stream to a {} bytes lenght resource with MIME: {}", contentLength, contentType);
|
logger.debug("Getting the stream to the avatar resource with MIME: {}", contentType);
|
||||||
|
|
||||||
InputStream is = conn.getInputStream();
|
InputStream is = conn.getInputStream();
|
||||||
buffer = new ByteArrayOutputStream();
|
buffer = new ByteArrayOutputStream();
|
||||||
int nRead;
|
int nRead;
|
||||||
byte[] data = new byte[1024];
|
byte[] data = new byte[1024];
|
||||||
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
||||||
buffer.write(data, 0, nRead);
|
buffer.write(data, 0, nRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.flush();
|
||||||
|
return buffer.toByteArray();
|
||||||
|
} else {
|
||||||
|
logger.debug("Something wrong on the avatar server. Response code: {}", conn.getResponseCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.flush();
|
|
||||||
return buffer.toByteArray();
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
logger.debug("User's avatar not found");
|
logger.debug("User's avatar not found");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in New Issue