@Test public void shouldReturnPictureURL() { String pictureURL = "https: String picture = listener.computePicture(pictureURL.getBytes()); assertEquals(pictureURL, picture); }
public String computePicture(final byte[] pictureData) { String pictureContent = new String(pictureData); if(pictureContent.toUpperCase().startsWith("HTTP")) { return pictureContent; } try { String contentType = URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(pictureData)); if(contentType != null) { StringBuilder sb = new StringBuilder(); sb.append("data:"); sb.append(contentType); sb.append(";base64,"); sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(pictureData, false))); return sb.toString(); } else { LOGGER.warn("Unable to compute the user picture from URL."); } } catch (IOException e) { LOGGER.warn("Problem while parsing picture", e); } return null; }
AuthenticationSuccessListener implements ApplicationListener<AuthenticationSuccessEvent> { public String computePicture(final byte[] pictureData) { String pictureContent = new String(pictureData); if(pictureContent.toUpperCase().startsWith("HTTP")) { return pictureContent; } try { String contentType = URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(pictureData)); if(contentType != null) { StringBuilder sb = new StringBuilder(); sb.append("data:"); sb.append(contentType); sb.append(";base64,"); sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(pictureData, false))); return sb.toString(); } else { LOGGER.warn("Unable to compute the user picture from URL."); } } catch (IOException e) { LOGGER.warn("Problem while parsing picture", e); } return null; } }
AuthenticationSuccessListener implements ApplicationListener<AuthenticationSuccessEvent> { public String computePicture(final byte[] pictureData) { String pictureContent = new String(pictureData); if(pictureContent.toUpperCase().startsWith("HTTP")) { return pictureContent; } try { String contentType = URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(pictureData)); if(contentType != null) { StringBuilder sb = new StringBuilder(); sb.append("data:"); sb.append(contentType); sb.append(";base64,"); sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(pictureData, false))); return sb.toString(); } else { LOGGER.warn("Unable to compute the user picture from URL."); } } catch (IOException e) { LOGGER.warn("Problem while parsing picture", e); } return null; }  }
AuthenticationSuccessListener implements ApplicationListener<AuthenticationSuccessEvent> { public String computePicture(final byte[] pictureData) { String pictureContent = new String(pictureData); if(pictureContent.toUpperCase().startsWith("HTTP")) { return pictureContent; } try { String contentType = URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(pictureData)); if(contentType != null) { StringBuilder sb = new StringBuilder(); sb.append("data:"); sb.append(contentType); sb.append(";base64,"); sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(pictureData, false))); return sb.toString(); } else { LOGGER.warn("Unable to compute the user picture from URL."); } } catch (IOException e) { LOGGER.warn("Problem while parsing picture", e); } return null; }  @Override void onApplicationEvent(AuthenticationSuccessEvent event); String computePicture(final byte[] pictureData); }
AuthenticationSuccessListener implements ApplicationListener<AuthenticationSuccessEvent> { public String computePicture(final byte[] pictureData) { String pictureContent = new String(pictureData); if(pictureContent.toUpperCase().startsWith("HTTP")) { return pictureContent; } try { String contentType = URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(pictureData)); if(contentType != null) { StringBuilder sb = new StringBuilder(); sb.append("data:"); sb.append(contentType); sb.append(";base64,"); sb.append(StringUtils.newStringUtf8(Base64.encodeBase64(pictureData, false))); return sb.toString(); } else { LOGGER.warn("Unable to compute the user picture from URL."); } } catch (IOException e) { LOGGER.warn("Problem while parsing picture", e); } return null; }  @Override void onApplicationEvent(AuthenticationSuccessEvent event); String computePicture(final byte[] pictureData);  }