Search in sources :

Example 1 with URIx

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;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URIx(maspack.fileutil.uri.URIx) IOException(java.io.IOException)

Example 2 with URIx

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);
}
Also used : URIx(maspack.fileutil.uri.URIx) File(java.io.File)

Example 3 with URIx

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);
    }
}
Also used : URIx(maspack.fileutil.uri.URIx) File(java.io.File)

Example 4 with URIx

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);
}
Also used : URIx(maspack.fileutil.uri.URIx) File(java.io.File)

Example 5 with URIx

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);
}
Also used : URIx(maspack.fileutil.uri.URIx) File(java.io.File)

Aggregations

URIx (maspack.fileutil.uri.URIx)17 File (java.io.File)11 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 IOException (java.io.IOException)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 FileObject (org.apache.commons.vfs2.FileObject)2 JSchException (com.jcraft.jsch.JSchException)1 FileNotFoundException (java.io.FileNotFoundException)1 FileCacher (maspack.fileutil.FileCacher)1 URIxMatcher (maspack.fileutil.uri.URIxMatcher)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 WavefrontReader (maspack.geometry.io.WavefrontReader)1 AxisAngle (maspack.matrix.AxisAngle)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 Vector3d (maspack.matrix.Vector3d)1 AllFileSelector (org.apache.commons.vfs2.AllFileSelector)1