use of maspack.fileutil.uri.URIx in project artisynth_core by artisynth.
the class FileManager method getRemoteHash.
/**
* Fetches a hash file from a remote location. The hash file is assumed to
* have the form <uri>.sha1
*
* @param uri
* the URI of the file to obtain the hash
* @return the hex-encoded hash value string
*/
public String getRemoteHash(URIx uri) throws FileTransferException {
uri = getAbsoluteURI(uri);
// construct a uri for the remote sha1 hash
URIx hashURI = mergeExtension(uri, ".sha1");
// create input stream and download hash
InputStream in = null;
String sha1 = null;
try {
cacher.initialize();
} catch (FileSystemException e) {
cacher.release();
throw new FileTransferException("Failed to initialize FileCacher", e);
}
try {
in = cacher.getInputStream(hashURI);
byte[] hash = new byte[40];
in.read(hash, 0, hash.length);
sha1 = new String(hash);
} catch (FileSystemException e) {
String msg = decodeVFSMessage(e);
throw new FileTransferException("Cannot obtain remote hash: " + uncap(msg), e);
} catch (IOException e) {
throw new FileTransferException("Cannot read hash from input stream: " + uncap(e.getMessage()), e);
} finally {
closeQuietly(in);
cacher.release();
}
return sha1;
}
use of maspack.fileutil.uri.URIx in project artisynth_core by artisynth.
the class FileManager method getInputStream.
public InputStream getInputStream(String localCopy, String sourceName, int options) throws FileTransferException {
URIx source = new URIx(sourceName);
File local = null;
if (localCopy != null) {
local = new File(localCopy);
}
return getInputStream(local, source, options);
}
use of maspack.fileutil.uri.URIx in project artisynth_core by artisynth.
the class NativeLibraryManager method grabFile.
void grabFile(File libFile, LibDesc desc, boolean checkHash) {
FileManager Manager = new FileManager();
Manager.setVerbosityLevel(LogLevel.ALL);
if ((myFlags & VERBOSE) != 0) {
FileTransferListener listener = myTransferListener;
if (listener == null) {
listener = new DefaultConsoleFileTransferListener();
}
Manager.addTransferListener(listener);
// 100ms
Manager.getTransferMonitor().setPollSleep(100);
}
String localLibFile = libFile.toString();
String remoteLibFile = myRemoteHost + "/" + getNativeDirectoryName() + "/" + getFileName(desc);
boolean grab = true;
if (checkHash) {
grab = !Manager.equalsHash(new File(localLibFile), new URIx(remoteLibFile));
}
if (grab) {
Manager.getRemote(localLibFile, remoteLibFile);
}
}
use of maspack.fileutil.uri.URIx in project artisynth_core by artisynth.
the class FileManager method equalsHash.
public boolean equalsHash(String local, String remote) throws FileTransferException {
File localFile = getAbsoluteFile(local);
URIx localURI = getAbsoluteURI(remote);
return equalsHash(localFile, localURI);
}
use of maspack.fileutil.uri.URIx in project artisynth_core by artisynth.
the class FileManager method get.
/**
* Converts the supplied destination path and source URI to a File and URI
* object, respectively, and downloads the remote file according to the
* supplied options.
*
* @param destName destination path
* @param sourceName source URI (as a string)
* @return File handle to local file
* @throws URIxSyntaxException if the sourceName is malformed
* @throws FileTransferException if download fails.
* @see #get(File, URIx, int)
*/
public File get(String destName, String sourceName, int options) throws URIxSyntaxException, FileTransferException {
// try to make URI from sourceName
URIx source = new URIx(sourceName);
File dest = null;
if (destName != null) {
dest = new File(destName);
}
return get(dest, source, options);
}
Aggregations