Search in sources :

Example 1 with ArtifactCallbackStream

use of org.eclipse.ceylon.cmr.api.ArtifactCallbackStream in project ceylon by eclipse.

the class VerifiedDownload method fetch.

/**
 * Perform the download to a temporary file and verify it
 * @throws IOException
 */
public void fetch(ArtifactCallback callback, InputStream stream, long length) throws IOException {
    log.debug("  FETCH: saving " + node + " to " + tempFile);
    final File file;
    try {
        if (callback != null) {
            callback.start(NodeUtils.getFullPath(node), length != -1 ? length : node.getSize(), node.getStoreDisplayString());
            stream = new ArtifactCallbackStream(callback, stream);
        }
        log.debug("  Saving content of " + node + " to " + fileContentStore.getFile(tempNode));
        // stream should be closed closer to API call
        fileContentStore.putContent(tempNode, stream, context);
        // re-get
        file = fileContentStore.getFile(tempNode);
        assert (file.getPath().equals(tempFile.getPath()));
        if (callback != null) {
            callback.done(file);
        }
    } catch (Throwable t) {
        if (callback != null) {
            callback.error(fileContentStore.getFile(node), t);
        }
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        } else {
            throw IOUtils.toIOException(t);
        }
    }
    if (context.isIgnoreSHA() == false && node instanceof OpenNode) {
        verify((OpenNode) node);
    } else {
        log.debug("  Not validating checksum: " + tempNode);
    }
}
Also used : ArtifactCallbackStream(org.eclipse.ceylon.cmr.api.ArtifactCallbackStream) File(java.io.File) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Aggregations

File (java.io.File)1 ArtifactCallbackStream (org.eclipse.ceylon.cmr.api.ArtifactCallbackStream)1 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)1