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);
|
||||
conn.setRequestProperty("Authorization", authorization);
|
||||
}
|
||||
String contentType = conn.getContentType();
|
||||
int contentLength = conn.getContentLength();
|
||||
|
||||
logger.debug("Getting the stream to a {} bytes lenght resource with MIME: {}", contentLength, contentType);
|
||||
|
||||
InputStream is = conn.getInputStream();
|
||||
buffer = new ByteArrayOutputStream();
|
||||
int nRead;
|
||||
byte[] data = new byte[1024];
|
||||
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
if (conn.getResponseCode() == 200) {
|
||||
String contentType = conn.getContentType();
|
||||
|
||||
logger.debug("Getting the stream to the avatar resource with MIME: {}", contentType);
|
||||
|
||||
InputStream is = conn.getInputStream();
|
||||
buffer = new ByteArrayOutputStream();
|
||||
int nRead;
|
||||
byte[] data = new byte[1024];
|
||||
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
||||
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) {
|
||||
logger.debug("User's avatar not found");
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in New Issue