Example usage for org.apache.commons.io FileUtils moveFileToDirectory

List of usage examples for org.apache.commons.io FileUtils moveFileToDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils moveFileToDirectory.

Prototype

public static void moveFileToDirectory(File srcFile, File destDir, boolean createDestDir) throws IOException 

Source Link

Document

Moves a file to a directory.

Usage

From source file:it.drwolf.ridire.session.async.Mapper.java

@SuppressWarnings("unchecked")
private StringWithEncoding transformPDF2HTML(File resourceFile, EntityManager entityManager)
        throws IOException, InterruptedException {
    String workingDirName = System.getProperty("java.io.tmpdir");
    String userDir = System.getProperty("user.dir");
    byte[] buf = new byte[Mapper.BUFLENGTH];
    int count = 0;
    GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(resourceFile));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    while ((count = gzis.read(buf)) != -1) {
        baos.write(buf, 0, count);/*from  w  ww . j  a  va  2 s  . com*/
    }
    gzis.close();
    baos.close();
    byte[] byteArray = baos.toByteArray();
    String uuid = UUID.randomUUID().toString();
    String pdfFileName = uuid + ".pdf";
    String htmlFileName = uuid + ".html";
    File tmpDir = new File(workingDirName);
    String htmlFileNameCompletePath = workingDirName + JobMapperMonitor.FILE_SEPARATOR + htmlFileName;
    File fileToConvert = new File(tmpDir, pdfFileName);
    FileUtils.writeByteArrayToFile(fileToConvert, byteArray);
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);
    CommandParameter cp = entityManager.find(CommandParameter.class, CommandParameter.PDFTOHTML_EXECUTABLE_KEY);
    CommandLine commandLine = CommandLine.parse(cp.getCommandValue());
    commandLine.addArgument("-c");
    commandLine.addArgument("-i");
    commandLine.addArgument(fileToConvert.getAbsolutePath());
    commandLine.addArgument(htmlFileNameCompletePath);
    executor.setExitValue(0);
    executor.execute(commandLine);
    try {
        FileUtils.moveFileToDirectory(
                new File(userDir + JobMapperMonitor.FILE_SEPARATOR + uuid + "-outline.html"), tmpDir, false);
    } catch (IOException e) {
    }
    cp = entityManager.find(CommandParameter.class, CommandParameter.PDFCLEANER_EXECUTABLE_KEY);
    commandLine = CommandLine
            .parse("java -Xmx128m -jar -Djava.io.tmpdir=" + this.tempDir + " " + cp.getCommandValue());
    commandLine.addArgument(htmlFileNameCompletePath);
    commandLine.addArgument("39");
    commandLine.addArgument("6");
    commandLine.addArgument("5");
    executor = new DefaultExecutor();
    executor.setExitValue(0);
    ExecuteWatchdog watchdog = new ExecuteWatchdog(Mapper.PDFCLEANER_TIMEOUT);
    executor.setWatchdog(watchdog);
    ByteArrayOutputStream baosStdOut = new ByteArrayOutputStream(1024);
    ExecuteStreamHandler executeStreamHandler = new PumpStreamHandler(baosStdOut, null, null);
    executor.setStreamHandler(executeStreamHandler);
    int exitValue = executor.execute(commandLine);
    String htmlString = null;
    if (exitValue == 0) {
        htmlString = baosStdOut.toString();
    }
    FileUtils.deleteQuietly(new File(htmlFileNameCompletePath));
    PrefixFileFilter pff = new PrefixFileFilter(uuid);
    for (File f : FileUtils.listFiles(tmpDir, pff, null)) {
        FileUtils.deleteQuietly(f);
    }
    if (htmlString != null) {
        htmlString = htmlString.replaceAll(" ", " ");
        htmlString = htmlString.replaceAll("<br.*?>", " ");
        CharsetDetector charsetDetector = new CharsetDetector();
        charsetDetector.setText(htmlString.getBytes());
        String encoding = charsetDetector.detect().getName();
        return new StringWithEncoding(htmlString, encoding);
    }
    return null;
}

From source file:net.sf.zekr.common.config.ApplicationConfig.java

@SuppressWarnings("unchecked")
public AudioData loadAudioData(File audioFile, boolean convertOldFormat)
        throws FileNotFoundException, UnsupportedEncodingException, ConfigurationException, IOException {
    PropertiesConfiguration pc = ConfigUtils.loadConfig(audioFile, "UTF-8");

    AudioData audioData;//  w w w  .j  a v  a 2 s. co m
    audioData = new AudioData();
    audioData.id = pc.getString("audio.id");
    audioData.file = audioFile;
    // note that audio.version should be made up of digits and dots only, so 0.7.5beta1 is invalid.
    audioData.version = pc.getString("audio.version");
    if (StringUtils.isBlank(audioData.version)) { // old format
        logger.warn("Not a valid recitation file. No version specified: " + audioFile);
        if (convertOldFormat) {
            logger.info("Will try to convert recitation file: " + audioFile);
            audioData = RecitationPackConverter.convert(audioFile);
            if (audioData == null) {
                logger.info("Conversion failed for " + audioFile);
                return null;
            }
            File destDir = new File(
                    FilenameUtils.getFullPath(audioFile.getAbsolutePath()) + "old-recitation-files");
            logger.info(String.format("Move %s to %s.", audioFile, destDir));
            FileUtils.moveFileToDirectory(audioFile, destDir, true);

            Writer w = new FileWriter(audioFile);
            StringWriter sw = new StringWriter();
            audioData.save(sw);
            w.write(sw.toString());
            IOUtils.closeQuietly(w);
            return audioData;
        } else {
            return null;
        }
    } else if (CommonUtils.compareVersions(audioData.version, AudioData.BASE_VALID_VERSION) < 0) {
        logger.warn(String.format(
                "Version is not supported anymore: %s. Zekr supports a recitation file of version %s or newer.",
                audioData.version, AudioData.BASE_VALID_VERSION));
        return null;
    }
    audioData.lastUpdate = pc.getString("audio.lastUpdate");
    audioData.quality = pc.getString("audio.quality", "?");

    // audioData.name = pc.getString("audio.name");
    audioData.license = pc.getString("audio.license");
    audioData.locale = new Locale(pc.getString("audio.language"), pc.getString("audio.country"));
    audioData.type = pc.getString("audio.type", "online");

    audioData.setLanguage(audioData.locale.getDisplayLanguage());//this will make it accessible from LocateResource super class.
    audioData.loadLocalizedNames(pc, "audio.reciter");

    Iterator<String> keys = pc.getKeys("audio.reciter");
    while (keys.hasNext()) {
        String key = keys.next();
        if (key.equals("audio.reciter")) {
            continue;
        }
        String lang = key.substring("audio.reciter".length() + 1);
        audioData.localizedNameMap.put(lang, pc.getString(key));
    }

    audioData.offlineUrl = pc.getString("audio.offlineUrl");
    audioData.onlineUrl = pc.getString("audio.onlineUrl");

    audioData.onlineAudhubillah = pc.getString("audio.onlineAudhubillah");
    // keep backward compatibility for old typo in files (bismillam instead of bismillah)
    audioData.onlineBismillah = pc.getString("audio.onlineBismillah", pc.getString("audio.onlineBismillam"));
    // keep backward compatibility for old typo in files (saghaghallah instead of sadaghallah)
    audioData.onlineSadaghallah = pc.getString("audio.onlineSadaghallah",
            pc.getString("audio.onlineSaghaghallah"));

    audioData.offlineAudhubillah = pc.getString("audio.offlineAudhubillah");
    // keep backward compatibility for old typo in files (bismillam instead of bismillah)
    audioData.offlineBismillah = pc.getString("audio.offlineBismillah", pc.getString("audio.offlineBismillam"));
    // keep backward compatibility for old typo in files (saghaghallah instead of sadaghallah)
    audioData.offlineSadaghallah = pc.getString("audio.offlineSadaghallah",
            pc.getString("audio.offlineSaghaghallah"));
    return audioData;
}

From source file:com.aerohive.nms.web.config.lbs.services.HmFolderServiceImpl.java

private File makeXMLBgImages2Tar(final String file_prefix, Long ownerId, Set<String> imageNames,
        HmFileUploadResponsedVo responseVo) throws AhCarrierException, InternalServerException {
    if (!(null == imageNames || imageNames.isEmpty())) {
        final String ext_tar = ".tar";
        final String ext_xml = ".xml";

        String tarFilePath = getTarFolderPath(file_prefix, ownerId);
        File tarFolder = new File(tarFilePath);
        if (!tarFolder.exists()) {
            tarFolder.mkdirs();/* w  w  w  . j  av a  2 s. co  m*/
        }

        // copy the background images to subfolder 'bgImages' under tar
        // folder
        String srcPath = getFolderBgImagePath(file_prefix, ownerId);
        String srcFileName = "";
        for (String imageName : imageNames) {
            srcFileName = srcPath + imageName;
            File file = new File(srcFileName);
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            } else {
                file.getParentFile().delete();
            }

            try (FileOutputStream stream = new FileOutputStream(file)) {
                //move image file
                stream.write(imageService.getImage(ownerId, imageName));
                stream.flush();
                stream.close();
                FileUtils.moveFileToDirectory(file, new File(tarFolder, "bgImages"), true);

                //remove image directory
                File imageDirectory = new File(srcPath);
                if (imageDirectory.exists() && imageDirectory.isDirectory()
                        && imageDirectory.list().length == 0) {
                    imageDirectory.delete();
                }

                //move xml file
                srcFileName = getFolderDataFilePath(file_prefix, ownerId) + file_prefix + ext_xml;
                final File xmlFile = new File(srcFileName);
                FileUtils.moveFileToDirectory(xmlFile, tarFolder, true);
                if (xmlFile.getParentFile().exists() && xmlFile.getParentFile().isDirectory()
                        && xmlFile.getParentFile().list().length == 0) {
                    xmlFile.getParentFile().delete();
                }

                final String destTarFilePath = getFolderFileBasePath(file_prefix, ownerId) + file_prefix
                        + ext_tar;
                if (new TarArchive().createTarZip(tarFilePath, destTarFilePath)) {
                    // copy tar file to maps folder
                    final File tarFile = new File(destTarFilePath);

                    // delete files and tar directory under /tmp/maps
                    FileUtils.deleteQuietly(tarFolder);
                    FileUtils.deleteQuietly(tarFile);
                    final File gzFile = new File(destTarFilePath + TarArchive.SUFFIX_ZIP);
                    return gzFile;
                }
            } catch (Exception e) {
                logger.error(String.format("Error to download background-image file %s: %s", imageName,
                        e.getMessage()));
                throw new AhCarrierException(e, ErrorCodes.fileDownloadFailed,
                        new Object[][] { { "fileName", imageName }, });
            }

        }
    }
    return null;
}

From source file:com.datatorrent.stram.cli.ApexCli.java

private List<AppInfo> getAppsFromPackageAndConfig(AppPackage ap, ConfigPackage cp, String configApps) {
    if (cp == null || configApps == null
            || !(configApps.equals(CONFIG_INCLUSIVE) || configApps.equals(CONFIG_EXCLUSIVE))) {
        return ap.getApplications();
    }//from  ww  w .  java 2  s . c o m

    File src = new File(cp.tempDirectory(), "app");
    File dest = new File(ap.tempDirectory(), "app");

    if (!src.exists()) {
        return ap.getApplications();
    }

    if (configApps.equals(CONFIG_EXCLUSIVE)) {

        for (File file : dest.listFiles()) {

            if (file.getName().endsWith(".json")) {
                FileUtils.deleteQuietly(new File(dest, file.getName()));
            }
        }
    } else {
        for (File file : src.listFiles()) {
            FileUtils.deleteQuietly(new File(dest, file.getName()));
        }
    }

    for (File file : src.listFiles()) {
        try {
            FileUtils.moveFileToDirectory(file, dest, true);
        } catch (IOException e) {
            LOG.warn("Application from the config file {} failed while processing.", file.getName());
        }
    }

    try {
        FileUtils.deleteDirectory(src);
    } catch (IOException e) {
        LOG.warn("Failed to delete the Config Apps folder");
    }

    ap.processAppDirectory(configApps.equals(CONFIG_EXCLUSIVE));

    return ap.getApplications();
}

From source file:nl.mpi.oai.harvester.control.FileSynchronization.java

/**
 *   Move file  of temporary directory//from www. j  a v a2 s . c o m
 */
private static void move(final File file, final String dir) {
    Stream<String> fileStream = getAsStream(file);

    if (fileStream != null) {
        fileStream.forEach(l -> {
            try {
                FileUtils.moveFileToDirectory(FileUtils.getFile(dir + "/" + l),
                        FileUtils.getFile(dir + "_new/"), true);
            } catch (IOException e) {
                logger.error("Error while moving " + l + " file: ", e);
            }
        });
    }
}

From source file:nl.mpi.tla.lat2fox.Main.java

public static void main(String[] args) {
    File rfile = null;/*from w  ww. j ava2s  . c o  m*/
    String dir = ".";
    String fdir = null;
    String idir = null;
    String bdir = null;
    String xdir = null;
    String pdir = null;
    String mdir = null;
    String cext = "cmdi";
    String cfile = null;
    String dfile = null;
    String mfile = null;
    String oxp = null;
    String axp = null;
    String server = null;
    XdmNode collsDoc = null;
    boolean validateFOX = false;
    boolean laxResourceCheck = false;
    boolean createCMDObject = true;
    boolean relationCheck = true;
    int ndir = 0;
    // check command line
    OptionParser parser = new OptionParser("zhlve:r:f:i:x:p:q:n:c:d:m:o:a:s:b:?*");
    OptionSet options = parser.parse(args);
    if (options.has("l"))
        laxResourceCheck = true;
    if (options.has("v"))
        validateFOX = true;
    if (options.has("h"))
        createCMDObject = false;
    if (options.has("z"))
        relationCheck = false;
    if (options.has("e"))
        cext = (String) options.valueOf("e");
    if (options.has("r"))
        rfile = new File((String) options.valueOf("r"));
    if (options.has("f"))
        fdir = (String) options.valueOf("f");
    if (options.has("i"))
        idir = (String) options.valueOf("i");
    if (options.has("x"))
        xdir = (String) options.valueOf("x");
    if (options.has("p"))
        pdir = (String) options.valueOf("p");
    if (options.has("q"))
        mdir = (String) options.valueOf("q");
    if (options.has("b"))
        bdir = (String) options.valueOf("b");
    if (options.has("c")) {
        cfile = (String) options.valueOf("c");
        File c = new File(cfile);
        if (!c.isFile()) {
            System.err.println("FTL: -c expects a <FILE> argument!");
            showHelp();
            System.exit(1);
        }
        if (!c.canRead()) {
            System.err.println("FTL: -c <FILE> argument isn't readable!");
            showHelp();
            System.exit(1);
        }
        try {
            collsDoc = SaxonUtils.buildDocument(new StreamSource(cfile));
        } catch (Exception ex) {
            System.err.println("FTL: can't read collection <FILE>[" + cfile + "]: " + ex);
            ex.printStackTrace(System.err);
        }
    }
    if (options.has("d")) {
        dfile = (String) options.valueOf("d");
        File d = new File(dfile);
        if (!d.isFile()) {
            System.err.println("FTL: -d expects a <FILE> argument!");
            showHelp();
            System.exit(1);
        }
        if (!d.canRead()) {
            System.err.println("FTL: -d <FILE> argument isn't readable!");
            showHelp();
            System.exit(1);
        }
    }
    if (options.has("m")) {
        mfile = (String) options.valueOf("m");
        File m = new File(mfile);
        if (!m.isFile()) {
            System.err.println("FTL: -m expects a <FILE> argument!");
            showHelp();
            System.exit(1);
        }
        if (!m.canRead()) {
            System.err.println("FTL: -m <FILE> argument isn't readable!");
            showHelp();
            System.exit(1);
        }
    }
    if (options.has("n")) {
        try {
            ndir = Integer.parseInt((String) options.valueOf("n"));
        } catch (NumberFormatException e) {
            System.err.println("FTL: -n expects a numeric argument!");
            showHelp();
            System.exit(1);
        }
    }
    if (options.has("o")) {
        oxp = (String) options.valueOf("o");
    }
    if (options.has("a")) {
        axp = (String) options.valueOf("a");
    }
    if (options.has("s")) {
        server = (String) options.valueOf("s");
    }
    if (options.has("?")) {
        showHelp();
        System.exit(0);
    }

    List arg = options.nonOptionArguments();
    if (arg.size() > 1) {
        System.err.println("FTL: only one source <DIR> argument is allowed!");
        showHelp();
        System.exit(1);
    }
    if (arg.size() == 1)
        dir = (String) arg.get(0);

    try {
        SaxonExtensionFunctions.registerAll(SaxonUtils.getProcessor().getUnderlyingConfiguration());
    } catch (Exception e) {
        System.err.println("ERR: couldn't register the Saxon extension functions: " + e);
        e.printStackTrace();
    }
    try {
        if (fdir == null)
            fdir = dir + "/fox";
        if (xdir == null)
            xdir = dir + "/fox-error";
        if (pdir == null)
            pdir = dir + "/policies";
        if (mdir == null)
            mdir = dir + "/management";
        XdmNode relsDoc = null;
        if (rfile != null && rfile.exists()) {
            relsDoc = SaxonUtils.buildDocument(new StreamSource(rfile));
            System.err.println("DBG: loaded[" + rfile.getAbsolutePath() + "]");
        } else {
            // create lookup document for relations
            XsltTransformer rels = SaxonUtils.buildTransformer(Main.class.getResource("/cmd2rels.xsl")).load();
            rels.setParameter(new QName("ext"), new XdmAtomicValue(cext));
            rels.setParameter(new QName("dir"), new XdmAtomicValue("file:" + dir));
            rels.setSource(new StreamSource(Main.class.getResource("/null.xml").toString()));
            XdmDestination dest = new XdmDestination();
            rels.setDestination(dest);
            rels.transform();
            relsDoc = dest.getXdmNode();
            if (rfile != null) {
                TransformerFactory.newInstance().newTransformer().transform(relsDoc.asSource(),
                        new StreamResult(rfile));
                System.err.println("DBG: saved[" + rfile.getAbsolutePath() + "]");
            }
        }
        if (relationCheck) {
            // Check the relations
            XsltTransformer rcheck = SaxonUtils.buildTransformer(Main.class.getResource("/checkRels.xsl"))
                    .load();
            rcheck.setParameter(new QName("rels-doc"), relsDoc);
            rcheck.setSource(new StreamSource(Main.class.getResource("/null.xml").toString()));
            XdmDestination dest = new XdmDestination();
            rcheck.setDestination(dest);
            rcheck.transform();
        }
        //System.exit(0);
        // CMDI 2 FOX
        // create the fox dirs
        FileUtils.forceMkdir(new File(fdir));
        FileUtils.forceMkdir(new File(xdir));
        Collection<File> inputs = FileUtils.listFiles(new File(dir), new String[] { cext }, true);
        // if there is a CMD 2 DC or 2 other XSLT include it
        XsltExecutable cmd2fox = null;
        if (dfile != null || mfile != null) {
            XsltTransformer inclCMD2DC = SaxonUtils
                    .buildTransformer(Main.class.getResource("/inclCMD2DCother.xsl")).load();
            inclCMD2DC.setSource(new StreamSource(Main.class.getResource("/cmd2fox.xsl").toString()));
            if (dfile != null)
                inclCMD2DC.setParameter(new QName("cmd2dc"),
                        new XdmAtomicValue("file://" + (new File(dfile)).getAbsolutePath()));
            if (mfile != null)
                inclCMD2DC.setParameter(new QName("cmd2other"),
                        new XdmAtomicValue("file://" + (new File(mfile)).getAbsolutePath()));
            XdmDestination destination = new XdmDestination();
            inclCMD2DC.setDestination(destination);
            inclCMD2DC.transform();
            cmd2fox = SaxonUtils.buildTransformer(destination.getXdmNode());
        } else
            cmd2fox = SaxonUtils.buildTransformer(Main.class.getResource("/cmd2fox.xsl"));
        int err = 0;
        int i = 0;
        int s = inputs.size();
        for (File input : inputs) {
            i++;
            if (!input.isHidden() && !input.getAbsolutePath().matches(".*/(corpman|sessions)/.*")) {
                try {
                    XsltTransformer fox = cmd2fox.load();
                    //fox.setParameter(new QName("rels-uri"), new XdmAtomicValue("file:"+map.getAbsolutePath()));
                    fox.setParameter(new QName("rels-doc"), relsDoc);
                    fox.setParameter(new QName("conversion-base"), new XdmAtomicValue(dir));
                    if (idir != null)
                        fox.setParameter(new QName("import-base"), new XdmAtomicValue(idir));
                    fox.setParameter(new QName("fox-base"), new XdmAtomicValue(fdir));
                    fox.setParameter(new QName("lax-resource-check"), new XdmAtomicValue(laxResourceCheck));
                    if (collsDoc != null)
                        fox.setParameter(new QName("collections-map"), collsDoc);
                    if (server != null)
                        fox.setParameter(new QName("repository"), new XdmAtomicValue(server));
                    if (oxp != null)
                        fox.setParameter(new QName("oai-include-eval"), new XdmAtomicValue(oxp));
                    if (axp != null) {
                        fox.setParameter(new QName("always-collection-eval"), new XdmAtomicValue(axp));
                        fox.setParameter(new QName("always-compound-eval"), new XdmAtomicValue(axp));
                    }
                    if (bdir != null)
                        fox.setParameter(new QName("icon-base"), new XdmAtomicValue(bdir));
                    if (pdir != null)
                        fox.setParameter(new QName("policies-dir"), new XdmAtomicValue(pdir));
                    if (mdir != null)
                        fox.setParameter(new QName("management-dir"), new XdmAtomicValue(mdir));
                    fox.setParameter(new QName("create-cmd-object"), new XdmAtomicValue(createCMDObject));
                    fox.setSource(new StreamSource(input));
                    XdmDestination destination = new XdmDestination();
                    fox.setDestination(destination);
                    fox.transform();
                    String fid = SaxonUtils.evaluateXPath(destination.getXdmNode(), "/*/@PID").evaluateSingle()
                            .getStringValue();
                    File out = new File(fdir + "/" + fid.replaceAll("[^a-zA-Z0-9]", "_") + "_CMD.xml");
                    if (out.exists()) {
                        System.err.println(
                                "ERR:" + i + "/" + s + ": FOX[" + out.getAbsolutePath() + "] already exists!");
                        out = new File(xdir + "/lat-error-" + (++err) + ".xml");
                        System.err.println("WRN:" + i + "/" + s + ": saved to FOX[" + out.getAbsolutePath()
                                + "] instead!");
                    }
                    TransformerFactory.newInstance().newTransformer()
                            .transform(destination.getXdmNode().asSource(), new StreamResult(out));
                    System.err.println("DBG:" + i + "/" + s + ": created[" + out.getAbsolutePath() + "]");
                } catch (Exception e) {
                    System.err.println("ERR:" + i + "/" + s + ": " + e);
                    System.err
                            .println("WRN:" + i + "/" + s + ": skipping file[" + input.getAbsolutePath() + "]");
                }
            }
        }
        if (ndir > 0) {
            int n = 0;
            int d = 0;
            inputs = FileUtils.listFiles(new File(fdir), new String[] { "xml" }, true);
            i = 0;
            s = inputs.size();
            for (File input : inputs) {
                i++;
                if (n == ndir)
                    n = 0;
                n++;
                FileUtils.moveFileToDirectory(input, new File(fdir + "/" + (n == 1 ? ++d : d)), true);
                if (n == 1)
                    System.err.println("DBG:" + i + "/" + s + ": moved to dir[" + fdir + "/" + d + "]");
            }
        }
        if (validateFOX) {
            SchemAnon tron = new SchemAnon(Main.class.getResource("/foxml1-1.xsd"), "ingest");
            inputs = FileUtils.listFiles(new File(fdir), new String[] { "xml" }, true);
            i = 0;
            s = inputs.size();
            for (File input : inputs) {
                i++;
                // validate FOX
                if (!tron.validate(input)) {
                    System.err
                            .println("ERR:" + i + "/" + s + ": invalid file[" + input.getAbsolutePath() + "]");
                    for (Message msg : tron.getMessages()) {
                        System.out.println("" + (msg.isError() ? "ERR: " : "WRN: ") + i + "/" + s + ": "
                                + (msg.getLocation() != null ? "at " + msg.getLocation() : ""));
                        System.out.println(
                                "" + (msg.isError() ? "ERR: " : "WRN: ") + i + "/" + s + ": " + msg.getText());
                    }
                } else
                    System.err.println("DBG:" + i + "/" + s + ": valid file[" + input.getAbsolutePath() + "]");
            }
        }
    } catch (Exception ex) {
        System.err.println("FTL: " + ex);
        ex.printStackTrace(System.err);
    }
}

From source file:ObjectLabEnterpriseSoftware.FileManager.java

public boolean rejectFile(String FileName) {
    try {/* w  ww  . j  a  v  a2 s. c  om*/
        FileUtils.moveFileToDirectory(new File(submission + FileName), new File(rejected), true);
    } catch (IOException ex) {
        Logger.getLogger(FileManager.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
    return true;
}

From source file:org.ado.picasa.Main.java

private static void downloadAlbum(FirefoxDriver driver, String album, File outputDir) {
    try {//from w  w w .j av  a2 s .c  o m
        final String albumName = getAlbumName(album);
        System.out.println(String.format("> album name: %s  url: %s", albumName, album));
        driver.navigate().to(album);

        final List<String> photoHrefLinks = driver.findElements(By.xpath("//div[@class='goog-icon-list']//a"))
                .stream().filter(a -> MediaType.PHOTO.equals(getMediaType(a))).map(a -> a.getAttribute("href"))
                .collect(Collectors.toList());

        for (String href : photoHrefLinks) {
            downloadPhoto(driver, href);
        }

        driver.navigate().to(album);

        final List<String> videoHrefLinks = driver.findElements(By.xpath("//div[@class='goog-icon-list']//a"))
                .stream().filter(a -> MediaType.VIDEO.equals(getMediaType(a))).map(a -> a.getAttribute("href"))
                .collect(Collectors.toList());

        int index = 1;
        final FileDownloader fileDownloader = new FileDownloader(driver, outputDir.getAbsolutePath());
        for (String videoUrl : getVideoUrls(driver, videoHrefLinks, album)) {
            try {
                new FileHandler(fileDownloader.downloader(videoUrl, albumName + index++ + ".m4v"));
            } catch (Exception e) {
                System.err.println(String.format("Cannot download video '%s'.", videoUrl));
                e.printStackTrace();
            }
        }

        TimeUnit.SECONDS.sleep(10);
        System.out.println(String.format("moving photos to directory: %s", albumName));
        final File albumDirectory = new File(outputDir, albumName);
        for (File file : FileUtils.listFiles(outputDir, null, false)) {
            try {
                FileUtils.moveFileToDirectory(file, albumDirectory, true);
            } catch (IOException e) {
                FileUtils.moveFile(file,
                        new File(albumDirectory, file.getName() + "-" + System.currentTimeMillis()));
            }
        }
    } catch (Exception e) {
        System.err.println(String.format("Cannot download album '%s'", album));
        e.printStackTrace();
    }
}

From source file:org.ambraproject.admin.service.impl.DocumentManagementServiceImpl.java

/**
 * Move the file to the ingested directory and generate cross-ref.
 *
 * @param file the file to move/*from www . j ava 2  s.  co  m*/
 * @param doi  the associated article
 * @throws java.io.IOException on an error
 */
public void generateIngestedData(File file, String doi) throws IOException {
    // Delete the previously ingested article if it exist.
    FileUtils.deleteQuietly(new File(ingestedDocumentDirectory, file.getName()));
    FileUtils.moveFileToDirectory(file, new File(ingestedDocumentDirectory), true);
    log.info("Relocated: " + file + ":" + doi);
}

From source file:org.apache.apex.malhar.contrib.avro.AvroFileToPojoModuleTest.java

private void writeAvroFile(File outputFile) {
    DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<>(new Schema.Parser().parse(AVRO_SCHEMA));
    try (DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<>(datumWriter)) {
        dataFileWriter.create(new Schema.Parser().parse(AVRO_SCHEMA), outputFile);

        for (GenericRecord record : recordList) {
            dataFileWriter.append(record);
        }/*from  ww  w  .  jav  a 2  s.c  o  m*/
        FileUtils.moveFileToDirectory(new File(outputFile.getAbsolutePath()), new File(testMeta.dir), true);
    } catch (IOException e) {
        e.printStackTrace();
    }
}