Search in sources :

Example 36 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class AbstractFetcher method getExistingFile.

/**
 * Wrap the existing file in the required Collection<LocalFile>
 *
 * @param existingFile existing file
 * @param seekFile     seek file
 * @return collection of local files
 */
protected Collection<LocalFile> getExistingFile(File existingFile, String seekFile) {
    Collection<LocalFile> fallback = new HashSet<>();
    LocalFile lf = LocalFile.Factory.newInstance();
    try {
        lf.setLocalURL(existingFile.toURI().toURL());
        lf.setRemoteURL((new File(seekFile)).toURI().toURL());
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    lf.setSize(existingFile.length());
    fallback.add(lf);
    return fallback;
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) MalformedURLException(java.net.MalformedURLException) File(java.io.File) LocalFile(ubic.gemma.model.common.description.LocalFile) HashSet(java.util.HashSet)

Example 37 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class FtpArchiveFetcher method doTask.

@Override
protected Collection<LocalFile> doTask(FutureTask<Boolean> future, long expectedSize, String seekFileName, String outputFileName) {
    Executors.newSingleThreadExecutor().execute(future);
    try {
        File outputFile = new File(outputFileName);
        boolean ok = this.waitForDownload(future, expectedSize, outputFile);
        if (!ok) {
            // probably cancelled.
            return null;
        } else if (future.get()) {
            AbstractFetcher.log.info("Unpacking " + outputFile);
            this.unPack(outputFile);
            this.cleanUp(outputFile);
            if (outputFile.isDirectory())
                return this.listFiles(seekFileName, outputFile, null);
            return this.listFiles(seekFileName, outputFile.getParentFile(), null);
        }
    } catch (ExecutionException e) {
        future.cancel(true);
        throw new RuntimeException("Couldn't fetch " + seekFileName + " from " + this.getNetDataSourceUtil().getHost(), e);
    } catch (InterruptedException e) {
        future.cancel(true);
        throw new RuntimeException("Interrupted: Couldn't fetch " + seekFileName + " from " + this.getNetDataSourceUtil().getHost(), e);
    } catch (IOException e) {
        future.cancel(true);
        throw new RuntimeException("IOException: Couldn't fetch " + seekFileName + " from " + this.getNetDataSourceUtil().getHost(), e);
    }
    future.cancel(true);
    throw new RuntimeException("Couldn't fetch " + seekFileName + " from " + this.getNetDataSourceUtil().getHost());
}
Also used : IOException(java.io.IOException) File(java.io.File) LocalFile(ubic.gemma.model.common.description.LocalFile)

Example 38 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class HttpFetcher method fetch.

public Collection<LocalFile> fetch(String url, String outputFileName) {
    AbstractFetcher.log.info("Seeking " + url);
    this.localBasePath = Settings.getDownloadPath();
    try {
        String host = (new URL(url)).getHost();
        String filePath;
        if (StringUtils.isBlank(host)) {
            throw new IllegalArgumentException(url + " was not parsed into a valid URL");
        }
        filePath = url.replace(host, "");
        filePath = filePath.replace("http://", "");
        filePath = filePath.replace('?', '_');
        filePath = filePath.replace('=', '_');
        filePath = filePath.replace('&', '_');
        filePath = filePath.replace('/', '_');
        filePath = filePath.replaceFirst("^_", "");
        File newDir = this.mkdir(host);
        final String output;
        if (outputFileName == null) {
            output = this.formLocalFilePath(filePath, newDir);
        } else {
            output = outputFileName;
        }
        FutureTask<Boolean> future = this.defineTask(output, url);
        return this.doTask(future, url, output);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) URL(java.net.URL)

Example 39 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class LocalFileServiceImpl method findByPath.

@Override
public LocalFile findByPath(String path) {
    File f = new File(path);
    LocalFile seek = LocalFile.Factory.newInstance();
    try {
        seek.setLocalURL(f.toURI().toURL());
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    }
    return this.localFileDao.find(seek);
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) MalformedURLException(java.net.MalformedURLException) LocalFile(ubic.gemma.model.common.description.LocalFile)

Example 40 with LocalFile

use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.

the class LocalFileServiceImpl method copyFile.

/**
 * @see LocalFileService#copyFile(LocalFile, LocalFile)
 */
@Override
public LocalFile copyFile(LocalFile sourceFile, LocalFile targetFile) throws IOException {
    File src = sourceFile.asFile();
    if (src == null)
        throw new IOException("Could not convert LocalFile into java.io.File");
    File dst = targetFile.asFile();
    if (dst == null)
        throw new IOException("Could not convert LocalFile into java.io.File");
    try (InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dst)) {
        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        long size = 0;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
            size += len;
        }
        in.close();
        out.close();
        targetFile.setSize(size);
        this.localFileDao.create(targetFile);
        return targetFile;
    }
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile)

Aggregations

LocalFile (ubic.gemma.model.common.description.LocalFile)40 File (java.io.File)17 IOException (java.io.IOException)11 MalformedURLException (java.net.MalformedURLException)4 HashSet (java.util.HashSet)4 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)4 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)4 URL (java.net.URL)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)3 Taxon (ubic.gemma.model.genome.Taxon)3 StopWatch (org.apache.commons.lang3.time.StopWatch)2 AffyPowerToolsProbesetSummarize (ubic.gemma.core.loader.expression.AffyPowerToolsProbesetSummarize)2 RawDataFetcher (ubic.gemma.core.loader.expression.geo.fetcher.RawDataFetcher)2 HttpFetcher (ubic.gemma.core.loader.util.fetcher.HttpFetcher)2 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1