I'm trying to use avatars from http://avatars.adorable.io/ in my application. However, when trying to download for instance the following png: http://api.adorable.io/avatars/285/bla.png my HttpUrlConnection says it sees a content length of 0.
When I fiddle around in the browser I think I found the site uses some script to generate the avatar, and I think it might be on the client end. However, I'm not very knowledgeable about this and could not easily find an answer.
Would it be possible to download one of these avatars in a Java application using the following code?
private Pixmap syncDownloadPixmapFromURL(URL url)
{
URLConnection conn;
try
{
conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(false);
conn.setUseCaches(true);
conn.connect();
int length = conn.getContentLength();
if(length<=0)
{
System.out.log("content length = 0!");
return null;
}
InputStream is = conn.getInputStream();
conn.setConnectTimeout(5000);
DataInputStream dis = new DataInputStream(is);
byte[] data = new byte[length];
dis.readFully(data);
dis.close();
Pixmap pixmap = new Pixmap(data, 0, data.length);
return pixmap;
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}