String rev,
String ext)
{
String urlString = resolveArtifactString(org, module, artifact, rev, ext);
TempFileInode inode = _tempFileManager.createInode();
try {
String sha1 = loadChecksum(urlString, "sha1");
String md5 = null;
if (sha1 == null)
md5 = loadChecksum(urlString, "md5");
URL url = null;
try {
url = new URL(urlString);
} catch (MalformedURLException e) {
throw new ConfigException(L.l("'{0}' is an invalid URL", urlString));
}
URLConnection conn = url.openConnection();
if (conn == null)
return null;
InputStream is = null;
try {
conn.connect();
int length = conn.getContentLength();
is = conn.getInputStream();
OutputStream out = inode.openOutputStream();
TempBuffer tempBuffer = TempBuffer.allocate();
byte []buffer = tempBuffer.getBuffer();
int readLength = 0;
int len;
log.info("ModuleRepository[] loading " + urlString);
while ((len = is.read(buffer, 0, buffer.length)) > 0) {
out.write(buffer, 0, len);
readLength += len;
}
out.close();
TempBuffer.free(tempBuffer);
InodeDataSource dataSource
= new InodeDataSource(urlString, inode);
if (md5 != null)
validateSignature(dataSource, md5, "MD5");
if (sha1 != null)
validateSignature(dataSource, sha1, "SHA1");
inode = null;
return dataSource;
} finally {
if (is != null)
is.close();
}
} catch (SecurityException e) {
throw new ModuleNotFoundException(L.l("{0} failed signature validation",
urlString, e));
} catch (MalformedURLException e) {
throw new ModuleNotFoundException(e);
} catch (IOException e) {
throw new ModuleNotFoundException(L.l("{0} is an unknown module",
urlString),
e);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (inode != null)
inode.free();
}
}