in.close();
}
}
private InputStream openStream(URI link, IProgressMonitor monitor, int timeout, boolean setAcceptLanguage, boolean isLocalized, String authToken) throws ConnectionException {
IProtocolHandler handler = Owl.getConnectionService().getHandler(link);
Map<Object, Object> properties = new HashMap<Object, Object>();
properties.put(IConnectionPropertyConstants.CON_TIMEOUT, timeout);
/* Set Authorization Header if required */
if (StringUtils.isSet(authToken)) {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Authorization", SyncUtils.getGoogleAuthorizationHeader(authToken)); //$NON-NLS-1$
properties.put(IConnectionPropertyConstants.HEADERS, headers);
}
/* Set the Accept-Language Header */
if (setAcceptLanguage) {
StringBuilder languageHeader = new StringBuilder();
String clientLanguage = Locale.getDefault().getLanguage();
/* Set Both English and Client Locale */
if (!isLocalized) {
languageHeader.append(DEFAULT_LANGUAGE);
if (StringUtils.isSet(clientLanguage) && !DEFAULT_LANGUAGE.equals(clientLanguage))
languageHeader.append(",").append(clientLanguage); //$NON-NLS-1$
}
/* Only set Client Locale */
else {
if (StringUtils.isSet(clientLanguage))
languageHeader.append(clientLanguage);
else
languageHeader.append(DEFAULT_LANGUAGE);
}
properties.put(IConnectionPropertyConstants.ACCEPT_LANGUAGE, languageHeader.toString());
}
return handler.openStream(link, monitor, properties);
}