Using the Runtime SDK there appears to only be one way to ascertain the size of a portal item for download (in this case I am downloading a TPK or GeoTIFF file for use in our application). So essentially this forces you to cycle through the InputStream twice. Once to get the size of the file and then a second time to download. Obviously this is a waste of time and resources. Anyone know of a way to access portal items and get content-length as you might do with an httpconnection? I guess the complication is that if you go outside of the runtime sdk it is using Rest and you would have to provide credentials a second time, even though you are already doing this via the SDK. It would be a lot nicer if you could just use the "item" to ascertain the file size. Anybody out there have any ideas?
PortalItem item = PortalItem.fetchItem(portal, itemID);
InputStream inputStream = item.fetchData();
long fileLength;
byte[] buf = new byte[16384];
int len, size = 0;
while ((len = inputStream.read(buf)) != -1) {
size += len;
}
inputStream.close();
fileLength = size;