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

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

Introduction

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

Prototype

public static void copyFileToDirectory(File srcFile, File destDir) throws IOException 

Source Link

Document

Copies a file to a directory preserving the file date.

Usage

From source file:org.eurocarbdb.action.hplc.UploadAction.java

public String execute() throws Exception {

    if (submitAction.equals("Upload")) {
        //     String location = file.getAbsolutePath();

        //going to move the file uploaded to /tmp an label with profile id
        File targetDir = new File(System.getProperty("java.io.tmpdir"));
        File tar = new File("/tmp/undigested" + profile_id + ".txt");

        FileUtils.copyFileToDirectory(file, targetDir);
        FileUtils.copyFile(file, tar);/*from w w w  .j  av a 2  s.  c  om*/

        logger.info("check the profile id:" + profile_id);

        //HttpServletRequest request;
        //HttpServletResponse response;
        //HttpSession session = request.getSession(true);
        //String id = session.getId();
        //logger.info("my session" + session);
        //logger.info("my id" + id);
        return SUCCESS;
    }

    else {
        return INPUT;
    }
}

From source file:org.fao.geonet.guiservices.versioning.VersioningTest.java

/**
 * Creates metadata in a repository exactly as geonetwork would do it.
 *//*  w w  w.  j a  v  a2 s  .  c om*/
private void create(SVNClientManager ourClientManager, int id) throws IOException, SVNException {
    File dir = new File(workingFolder.getRoot().getPath() + "/" + id + "/");
    FileUtils.forceMkdir(dir);
    // add directory
    ourClientManager.getWCClient().doAdd(dir, false, false, true, SVNDepth.FILES, false, true, true);
    final String dirMsg = "GeoNetwork service: metadata.create GeoNetwork User 1 (Username: admin Name: admin admin) Executed from IP address 0:0:0:0:0:0:0:1 adding directory for metadata "
            + id;
    // commit directory
    ourClientManager.getCommitClient().doCommit(new File[] { dir }, false, dirMsg, null, null, true, true,
            SVNDepth.INFINITY);
    //put files in working copy
    final String pfn = "privileges.xml";
    File privileges = new File(resources, pfn);
    final String mfn = "metadata.xml";
    File metadata = new File(resources, mfn);
    final String cfn = "categories.xml";
    File categories = new File(resources, cfn);
    final String ofn = "owner.xml";
    File owner = new File(resources, ofn);
    FileUtils.copyFileToDirectory(privileges, dir);
    FileUtils.copyFileToDirectory(metadata, dir);
    FileUtils.copyFileToDirectory(categories, dir);
    FileUtils.copyFileToDirectory(owner, dir);
    final String dp = dir.getPath();
    File[] files = { new File(dp + "/" + pfn), new File(dp + "/" + mfn), new File(dp + "/" + cfn),
            new File(dp + "/" + ofn) };
    // add files
    ourClientManager.getWCClient().doAdd(files, false, false, true, SVNDepth.FILES, false, true, false);
    final String fileMsg = "GeoNetwork service: metadata.create GeoNetwork User 1 (Username: admin Name: admin admin) Executed from IP address 0:0:0:0:0:0:0:1 adding initial version of metadata "
            + id;
    // commit files
    ourClientManager.getCommitClient().doCommit(files, false, fileMsg, null, null, true, true,
            SVNDepth.INFINITY);
}

From source file:org.fastcatsearch.ir.document.PrimaryKeyIndexesWriter.java

public PrimaryKeyIndexesWriter(Schema schema, File dir, RevisionInfo revisionInfo, IndexConfig indexConfig)
        throws IOException, IRException {
    String segmentId = dir.getName();
    boolean isAppend = revisionInfo.isAppend();
    File revisionDir = IndexFileNames.getRevisionDir(dir, revisionInfo.getId());

    primaryKeySetting = schema.schemaSetting().getPrimaryKeySetting();

    if (primaryKeySetting != null && primaryKeySetting.getFieldList() != null) {
        List<RefSetting> refList = primaryKeySetting.getFieldList();

        if (refList != null && refList.size() > 0) {
            primaryKeyFieldIdList = new int[refList.size()];

            int sequence = 0;
            for (RefSetting refSetting : refList) {
                String fieldId = refSetting.getRef();
                primaryKeyFieldIdList[sequence] = schema.getFieldSequence(fieldId);
                logger.debug("pk field [{}]{} >> {}", sequence, fieldId, primaryKeyFieldIdList[sequence]);
                sequence++;//from  w w  w . ja  va  2  s  .c  om
            }

            hasPrimaryKey = true;
        } else {
            //pk ?.
            return;
        }
    }
    //
    // ?? , pk ?  ??  ?? ??  ?.
    //
    if (isAppend) {
        indexWriter = new LargePrimaryKeyIndexWriter(revisionDir,
                IndexFileNames.getTempFileName(IndexFileNames.primaryKeyMap), indexConfig.getPkTermInterval(),
                indexConfig.getPkBucketSize());
    } else {
        // ??  ??   ?? ,  pk map? ?.
        indexWriter = new LargePrimaryKeyIndexWriter(revisionDir, IndexFileNames.primaryKeyMap,
                indexConfig.getPkTermInterval(), indexConfig.getPkBucketSize());
    }

    pkbaos = new BytesDataOutput(1024); // 1kb .

    String docDeleteSetName = IndexFileNames.getSuffixFileName(IndexFileNames.docDeleteSet, segmentId);
    if (isAppend) {
        File prevRevisionDir = IndexFileNames.getRevisionDir(dir, revisionInfo.getRef());
        // copy prev revision's delete.set
        // ??? append? ? ? revision? deleteSet?  .
        // DocumentWriter.close() ? rev  rev? ?  delete.
        File prevDelete = new File(prevRevisionDir, docDeleteSetName);
        //? ? delete.set?   dir  ??? .
        FileUtils.copyFileToDirectory(prevDelete, revisionDir);
        deleteSet = new BitSet(revisionDir, docDeleteSetName);
    } else {
        deleteSet = new BitSet(revisionDir, docDeleteSetName, true);
    }
}

From source file:org.forgerock.doc.maven.FilteredRecursiveFileCopier.java

/**
 * Copy a file to the directory if the filter matches, adding the parent
 * subdirectory./* ww w  . j av a  2 s  .  c  o m*/
 *
 * @param directory
 *            Directory to which to copy the file
 * @param depth
 *            Not used
 * @param results
 *            List of directories to which files have been copied
 * @return True on success
 * @throws IOException
 *             Something went wrong copying the file.
 */
@Override
protected final boolean handleDirectory(final File directory, final int depth, final Collection<File> results)
        throws IOException {
    String[] matches = directory.list(ffFilterToMatch);
    if (matches.length > 0) {
        File parent = new File(directory, sParentToAdd);
        if (parent.mkdir()) {
            FileUtils.copyFileToDirectory(fFileToCopy, parent);
            results.add(directory);
        }
    }

    return true;
}

From source file:org.forgerock.doc.maven.HTMLUtils.java

/**
 * Add a <code>.htaccess</code> file to the base directory, for publication
 * on an Apache HTTPD server./*from  w  ww  .  j  a  va 2  s .co m*/
 * <p>
 * According to Apache documentation on <a
 * href="http://httpd.apache.org/docs/2.4/howto/htaccess.html#how">How
 * directives are applied</a>, "The configuration directives found in a
 * .htaccess file are applied to the directory in which the .htaccess file
 * is found, and to all subdirectories thereof." So there is no need to copy
 * the file recursively to all directories.
 *
 * @param baseDir
 *            Base directory under which to add the file
 * @param htaccess
 *            <code>.htaccess</code> file to copy
 * @throws IOException
 *             Something went wrong during copy procedure.
 */
public static void addHtaccess(final String baseDir, final File htaccess) throws IOException {
    FileUtils.copyFileToDirectory(htaccess, new File(baseDir));
}

From source file:org.geoserver.catalog.ResourcePoolTest.java

@Override
protected void onSetUp(SystemTestData testData) throws Exception {
    super.onSetUp(testData);

    testData.addStyle("relative", "se_relativepath.sld", ResourcePoolTest.class, getCatalog());
    StyleInfo style = getCatalog().getStyleByName("relative");
    style.setSLDVersion(new Version("1.1.0"));
    getCatalog().save(style);/*from w  w  w .  ja v a  2  s. c o m*/
    File images = new File(testData.getDataDirectoryRoot(), "styles/images");
    assertTrue(images.mkdir());
    File image = new File("./src/test/resources/org/geoserver/catalog/rockFillSymbol.png");
    assertTrue(image.exists());
    FileUtils.copyFileToDirectory(image, images);
    rockFillSymbolFile = new File(images, image.getName()).getCanonicalFile();

    testData.addRasterLayer(TIMERANGES, "timeranges.zip", null, null, SystemTestData.class, getCatalog());
}

From source file:org.geoserver.config.GeoServerDataDirectory.java

/**
 * Copies a file into a security configuration directory.
 * <p>/* w w w  .  j a  va2 s .com*/
 * If the security configuration directory does exist it will be created.
 * </p>
 */
public void copyToSecurityDir(File f) throws IOException {
    FileUtils.copyFileToDirectory(f, securityRoot(true));
}

From source file:org.geoserver.config.GeoServerDataDirectory.java

/**
 * Copies a file into a workspace configuration directory.
 * <p>// w  w  w.  j av  a 2 s. co m
 * If the workspace configuration directory does exist it will be created.
 * </p>
 */
public void copyToWorkspaceDir(WorkspaceInfo ws, File f) throws IOException {
    FileUtils.copyFileToDirectory(f, workspaceDir(true, ws));
}

From source file:org.geoserver.config.GeoServerDataDirectory.java

/**
 * Copies a file into a store configuration directory.
 * <p>/*from   w w  w.ja v a 2 s .  com*/
 * If the store configuration directory does exist it will be created
 * </p>
 */
public void copyToStoreDir(StoreInfo s, File f) throws IOException {
    FileUtils.copyFileToDirectory(f, storeDir(true, s));
}

From source file:org.geoserver.config.GeoServerDataDirectory.java

/**
 * Copies a file into a feature type configuration directory.
 * <p>//from  w w w .jav  a2 s.c  o  m
 * If the resource directory does exist it will be created
 * </p>
 */
public void copyToResourceDir(ResourceInfo r, File f) throws IOException {
    FileUtils.copyFileToDirectory(f, resourceDir(true, r));
}