List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:ddf.security.pdp.realm.xacml.processor.BalanaClientTest.java
@Test public void testBalanaWrapperpoliciesdirectorypolicyadded() throws Exception { LOGGER.debug("\n\n\n##### testBalanaWrapper_policies_directory_policy_added"); File policyDir = folder.newFolder("tempDir"); BalanaClient.defaultPollingIntervalInSeconds = 1; // Perform Test BalanaClient pdp = new BalanaClient(policyDir.getCanonicalPath(), new XmlParser()); File srcFile = new File( projectHome + File.separator + RELATIVE_POLICIES_DIR + File.separator + POLICY_FILE); FileUtils.copyFileToDirectory(srcFile, policyDir); Thread.sleep(2000);/*from w ww . j a v a 2s . c o m*/ RequestType xacmlRequestType = new RequestType(); xacmlRequestType.setCombinedDecision(false); xacmlRequestType.setReturnPolicyIdList(false); AttributesType actionAttributes = new AttributesType(); actionAttributes.setCategory(ACTION_CATEGORY); AttributeType actionAttribute = new AttributeType(); actionAttribute.setAttributeId(ACTION_ID); actionAttribute.setIncludeInResult(false); AttributeValueType actionValue = new AttributeValueType(); actionValue.setDataType(STRING_DATA_TYPE); actionValue.getContent().add(QUERY_ACTION); actionAttribute.getAttributeValue().add(actionValue); actionAttributes.getAttribute().add(actionAttribute); AttributesType subjectAttributes = new AttributesType(); subjectAttributes.setCategory(SUBJECT_CATEGORY); AttributeType subjectAttribute = new AttributeType(); subjectAttribute.setAttributeId(SUBJECT_ID); subjectAttribute.setIncludeInResult(false); AttributeValueType subjectValue = new AttributeValueType(); subjectValue.setDataType(STRING_DATA_TYPE); subjectValue.getContent().add(TEST_USER_1); subjectAttribute.getAttributeValue().add(subjectValue); subjectAttributes.getAttribute().add(subjectAttribute); AttributeType roleAttribute = new AttributeType(); roleAttribute.setAttributeId(ROLE_CLAIM); roleAttribute.setIncludeInResult(false); AttributeValueType roleValue = new AttributeValueType(); roleValue.setDataType(STRING_DATA_TYPE); roleValue.getContent().add(ROLE); roleAttribute.getAttributeValue().add(roleValue); subjectAttributes.getAttribute().add(roleAttribute); AttributesType categoryAttributes = new AttributesType(); categoryAttributes.setCategory(PERMISSIONS_CATEGORY); AttributeType citizenshipAttribute = new AttributeType(); citizenshipAttribute.setAttributeId(CITIZENSHIP_ATTRIBUTE); citizenshipAttribute.setIncludeInResult(false); AttributeValueType citizenshipValue = new AttributeValueType(); citizenshipValue.setDataType(STRING_DATA_TYPE); citizenshipValue.getContent().add(US_COUNTRY); citizenshipAttribute.getAttributeValue().add(citizenshipValue); categoryAttributes.getAttribute().add(citizenshipAttribute); xacmlRequestType.getAttributes().add(actionAttributes); xacmlRequestType.getAttributes().add(subjectAttributes); xacmlRequestType.getAttributes().add(categoryAttributes); // Perform Test ResponseType xacmlResponse = pdp.evaluate(xacmlRequestType); // Verify - The policy was loaded to allow a permit decision JAXBContext jaxbContext = JAXBContext.newInstance(ResponseType.class); Marshaller marshaller = jaxbContext.createMarshaller(); ObjectFactory objectFactory = new ObjectFactory(); Writer writer = new StringWriter(); marshaller.marshal(objectFactory.createResponse(xacmlResponse), writer); LOGGER.debug("\nXACML 3.0 Response:\n{}", writer.toString()); assertEquals(xacmlResponse.getResult().get(0).getDecision(), DecisionType.PERMIT); FileUtils.deleteDirectory(policyDir); }
From source file:com.aliyun.odps.local.common.WareHouse.java
/** * copy table schema and partition data from warehouse to target directory , * if partition not exists will download the partition data and table schema * from remote server/*www .j av a2s. com*/ * * @param projectName * @param tableName * @param partSpec * if null will copy all partitions * @param readCols * if null will copy all columns * @param destDir * @return * @throws IOException * @throws OdpsException */ public boolean copyTable(String projectName, String tableName, PartitionSpec partSpec, String[] readCols, File destDir, int limitDownloadRecordCount, char inputColumnSeperator) { if (StringUtils.isBlank(projectName) || StringUtils.isBlank(tableName) || destDir == null) { return false; } TableInfo tableInfo = TableInfo.builder().projectName(projectName).tableName(tableName).partSpec(partSpec) .build(); LOG.info("Start to copy table: " + tableInfo + "-->" + destDir.getAbsolutePath()); boolean hasPartition = false; if (partSpec != null && !partSpec.isEmpty()) { hasPartition = true; } // if not exist table, then download from odps server if (hasPartition && !existsPartition(projectName, tableName, partSpec)) { DownloadUtils.downloadTableSchemeAndData(getOdps(), tableInfo, limitDownloadRecordCount, inputColumnSeperator); } else if (!existsTable(projectName, tableName)) { DownloadUtils.downloadTableSchemeAndData(getOdps(), tableInfo, limitDownloadRecordCount, inputColumnSeperator); } File whTableDir = getTableDir(projectName, tableName); // copy schema file File schemaFile = new File(whTableDir, Constants.SCHEMA_FILE); if (!schemaFile.exists()) { throw new RuntimeException( "Schema file of table " + projectName + "." + tableName + " not exists in warehouse."); } if (!destDir.exists()) { destDir.mkdirs(); } // copy table schema file try { FileUtils.copyFileToDirectory(schemaFile, destDir); } catch (IOException e) { throw new RuntimeException("Copy schema file of table " + tableInfo + " failed!" + e.getMessage()); } // copy partition data files TableMeta tableMeta = getTableMeta(projectName, tableName); List<Integer> indexes = LocalRunUtils.genReadColsIndexes(tableMeta, readCols); if (hasPartition) { final Collection<File> dataFiles = FileUtils.listFiles(whTableDir, HiddenFileFilter.VISIBLE, HiddenFileFilter.VISIBLE); for (File dataFile : dataFiles) { if (dataFile.getName().equals(Constants.SCHEMA_FILE)) { continue; } String parentDir = dataFile.getParentFile().getAbsolutePath(); String partPath = parentDir.substring(whTableDir.getAbsolutePath().length(), parentDir.length()); PartitionSpec ps = PartitionUtils.convert(partPath); if (PartitionUtils.isEqual(ps, partSpec)) { File destPartitionDir = new File(destDir, PartitionUtils.toString(ps)); destPartitionDir.mkdirs(); try { copyDataFiles(dataFile.getParentFile(), indexes, destPartitionDir, inputColumnSeperator); } catch (IOException e) { throw new RuntimeException( "Copy data file of table " + tableInfo + " failed!" + e.getMessage()); } } } } else { try { copyDataFiles(whTableDir, indexes, destDir, inputColumnSeperator); } catch (IOException e) { throw new RuntimeException("Copy data file of table " + tableInfo + " failed!" + e.getMessage()); } } LOG.info("Finished copy table: " + tableInfo + "-->" + destDir.getAbsolutePath()); return true; }
From source file:com.boundlessgeo.geoserver.bundle.BundleExporter.java
void copyFilesTo(File dataFile, File dir, DataStoreInfo store) throws IOException { List<File> filesToCopy = new ArrayList<>(); if (dataFile.isDirectory()) { // grab all files for feature types in the store for (String featureType : nativeFeatureTypeNames(store)) { filesToCopy.addAll(filesWithBasename(dataFile, featureType)); }/* ww w. j a va 2 s.c o m*/ } else { // round up all files that have the same base name filesToCopy = filesWithBasename(dataFile, FilenameUtils.getBaseName(dataFile.getName())); } for (File f : filesToCopy) { FileUtils.copyFileToDirectory(f, dir); } }
From source file:de.tilman.synctool.SyncTool.java
/** * Conducts the specified operation for the file. * //from w ww . j ava 2 s . com * @param file the file to be processed * @param directory the target directory * @param operation the operation to be executed */ private void syncFileToDirectory(File file, File directory, Operation operation) { try { if (operation == Operation.NONE) { if (!silent) log.info("No operation for " + file); return; } else if (operation == Operation.COPY) { if (file.isDirectory()) { log.info("Copying directory " + file); if (!dryRun) FileUtils.copyDirectoryToDirectory(file, directory); dirsCopied++; } else { log.info("Copying file " + file); if (!dryRun) FileUtils.copyFileToDirectory(file, directory); filesCopied++; } return; } else if (operation == Operation.DELETE) { if (file.isDirectory()) { log.info("Deleting directory " + file); if (!dryRun) FileUtils.deleteDirectory(file); dirsDeleted++; } else { log.info("Deleting file " + file); if (!dryRun) file.delete(); filesDeleted++; } return; } } catch (IOException ioe) { log.fatal(ioe.getMessage(), ioe); System.exit(-8); } }
From source file:com.legstar.cixs.gen.AbstractTestTemplate.java
/** * Check a result against a reference.//from w ww . j a va 2s . c om * <p/> * Here result is a folder as well as a reference. In check mode, all files * are compared. In creation mode, all reference files are created as copies * from the results. * * @param refFolder the reference folder (containing reference files) * @param resultFolder the result folder (containing generated files) * @param extension the files extension to process * @throws Exception if something fails */ @SuppressWarnings("unchecked") public void check(final File refFolder, final File resultFolder, final String extension) throws Exception { if (isCreateReferences()) { Collection<File> resultFiles = FileUtils.listFiles(resultFolder, new String[] { extension }, false); for (File resultFile : resultFiles) { FileUtils.copyFileToDirectory(resultFile, refFolder); } } else { Collection<File> referenceFiles = FileUtils.listFiles(refFolder, new String[] { extension }, false); for (File referenceFile : referenceFiles) { File resultFile = new File(resultFolder, FilenameUtils.getName(referenceFile.getPath())); check(referenceFile, resultFile); } } }
From source file:com.taobao.android.builder.tasks.library.AwbGenerator.java
/** * AWB/*from ww w . j a v a2s . co m*/ */ public void generateAwbArtifict(final Zip bundleTask, LibVariantOutputData libVariantOutputData) { Project project = bundleTask.getProject(); bundleTask.setExtension("awb"); bundleTask.setArchiveName(FilenameUtils.getBaseName(bundleTask.getArchiveName()) + ".awb"); bundleTask.setDestinationDir(new File(bundleTask.getDestinationDir().getParentFile(), "awb")); bundleTask.doFirst(new Action<Task>() { @Override public void execute(Task task) { File bundleBaseInfoFile = project.file("bundleBaseInfoFile.json"); if (bundleBaseInfoFile.exists()) { project.getLogger().warn("copy " + bundleBaseInfoFile.getAbsolutePath() + " to awb"); File destDir = libVariantOutputData.getScope().getVariantScope().getBaseBundleDir(); try { FileUtils.copyFileToDirectory(bundleBaseInfoFile, destDir); } catch (IOException e) { throw new GradleException(e.getMessage(), e); } } } }); bundleTask.doLast(new Action<Task>() { @Override public void execute(Task task) { File outputFile = new File(bundleTask.getDestinationDir(), bundleTask.getArchiveName()); if (!outputFile.exists()) { return; } //??aar if (atlasExtension.getBundleConfig().isAwbBundle()) { try { FileUtils.copyFile(outputFile, new File(new File(bundleTask.getDestinationDir().getParentFile(), "aar"), FilenameUtils.getBaseName(bundleTask.getArchiveName()) + ".aar")); } catch (IOException e) { e.printStackTrace(); } } } }); }
From source file:io.druid.cli.PullDependencies.java
/** * Download the extension given its maven coordinate * * @param versionedArtifact The maven artifact of the extension * @param toLocation The location where this extension will be downloaded to *//*from www . ja va 2 s. c o m*/ private void downloadExtension(Artifact versionedArtifact, File toLocation) { final CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(versionedArtifact, JavaScopes.RUNTIME)); final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils .andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), new DependencyFilter() { @Override public boolean accept(DependencyNode node, List<DependencyNode> parents) { String scope = node.getDependency().getScope(); if (scope != null) { scope = scope.toLowerCase(); if (scope.equals("provided")) { return false; } if (scope.equals("test")) { return false; } if (scope.equals("system")) { return false; } } if (accept(node.getArtifact())) { return false; } for (DependencyNode parent : parents) { if (accept(parent.getArtifact())) { return false; } } return true; } private boolean accept(final Artifact artifact) { return exclusions.contains(artifact.getGroupId()); } })); try { log.info("Start downloading extension [%s]", versionedArtifact); final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest); for (Artifact artifact : artifacts) { if (!exclusions.contains(artifact.getGroupId())) { log.info("Adding file [%s] at [%s]", artifact.getFile().getName(), toLocation.getAbsolutePath()); FileUtils.copyFileToDirectory(artifact.getFile(), toLocation); } else { log.debug("Skipped Artifact[%s]", artifact); } } } catch (Exception e) { log.error(e, "Unable to resolve artifacts for [%s].", dependencyRequest); throw Throwables.propagate(e); } log.info("Finish downloading extension [%s]", versionedArtifact); }
From source file:eu.asterics.ape.packaging.Packager.java
/** * Copyies the given srcURI to the given targetDir directory. * @param srcURI/*from w w w . ja v a 2 s .c o m*/ * @param targetDir * @param resolveTargetSubDirs: true: Resolves subdirs of bin/ARE to appropriate subdirs in a target directory. * @throws URISyntaxException * @throws IOException */ public void copyURI(URI srcURI, File targetDir, boolean resolveAREBaseURISubDirs) throws URISyntaxException, IOException { try { File targetSubDir = targetDir; File src = ResourceRegistry.toFile(srcURI); //If we should resolve against ARE subfolders if (resolveAREBaseURISubDirs) { //Only works if the URI contains the currently active ARE.baseURI. //Determine relative src dir which will then be resolved against the base target dir. File relativeSrc = ResourceRegistry.toFile(ResourceRegistry.getInstance().toRelative(srcURI)); //Determine parent folder of relativeSrc File targetSubDir = src.isDirectory() ? relativeSrc : relativeSrc.getParentFile(); if (targetSubDir != null) { //Resolve targetSubDir against targetDir targetSubDir = ResourceRegistry.resolveRelativeFilePath(targetDir, targetSubDir.getPath()); } else { targetSubDir = targetDir; } } //Actually copy file Notifier.debug("Copying " + src + " -> " + targetSubDir, null); if (src.isDirectory()) { FileUtils.copyDirectory(src, targetSubDir); } else { FileUtils.copyFileToDirectory(src, targetSubDir); } } catch (MalformedURLException e) { //else try if it is a URL that can be fetched from anywhere else. Notifier.warning("URL resources not supported so far", e); } }
From source file:com.athena.meerkat.controller.web.provisioning.AbstractProvisioningService.java
/** * <pre>//from w ww . j a v a2s .c om * ant commands file (cmd.xml & default.xml) ? jobDir ? copy . * </pre> * * @param cmdFileName * @param jobDir * @throws IOException */ protected void copyCmds(String cmdFileName, File jobDir) throws IOException { String cmdsPath = getCmdsPath(); FileUtils.copyFileToDirectory(new File(cmdsPath + "default.xml"), jobDir); FileUtils.copyFile(new File(cmdsPath + cmdFileName), new File(jobDir.getAbsolutePath() + File.separator + "cmd.xml")); }
From source file:es.bsc.servicess.ide.editors.deployers.LocalhostDeployer.java
private void deployOrchestration(IJavaProject project, String serverLocation, String ceLocation, String packName, IProgressMonitor monitor) throws Exception { File ceDir = new File(serverLocation + File.separator + "webapps"); if (ceDir.isDirectory()) { IFolder outFolder = project.getProject().getFolder(ProjectMetadata.OUTPUT_FOLDER) .getFolder(ProjectMetadata.PACKAGES_FOLDER); IFile properties = outFolder.getFile("it.properties"); if (properties != null && properties.exists()) { properties.delete(true, monitor); }/*from ww w. ja va 2s .c o m*/ properties.create(new ByteArrayInputStream(new String("").getBytes()), true, monitor); createPropertiesForLocalhost(properties.getLocation().toFile(), project); // properties.refreshLocal(0, monitor); IFile war = outFolder.getFile(packName + ".war"); if (war.exists()) { PackagingUtils.addRuntimeConfigTojar(war, properties.getLocation().toFile(), outFolder, PackagingUtils.WAR_CLASSES_PATH, monitor); // outFolder.refreshLocal(1, monitor); monitor.beginTask("deploying dependencies", 2); File srcFile = war.getLocation().toFile(); File f = new File(ceDir.getAbsolutePath() + File.separator + packName + ".war"); File dir = new File(ceDir.getAbsolutePath() + File.separator + packName); if (f.exists()) { f.delete(); } if (dir.exists()) { PackagingUtils.deleteDirectory(dir); } FileUtils.copyFileToDirectory(srcFile, ceDir); } IFile deps = outFolder.getFile(project.getProject().getName() + "_deps.zip"); if (deps != null && deps.exists()) PackagingUtils.extractZip(deps.getLocation().toFile(), ceLocation, outFolder, monitor); monitor.worked(1); ProjectMetadata pr_meta = new ProjectMetadata(getEditor().getMetadataFile().getRawLocation().toFile()); deployZipDeps(pr_meta.getDependencies(pr_meta.getElementsInPackage(packName)), ceLocation, outFolder, monitor); deployWarDeps(pr_meta.getDependencies(pr_meta.getElementsInPackage(packName)), packName, outFolder, ceDir, monitor); properties.delete(true, monitor); monitor.worked(1); monitor.done(); } else throw (new Exception("Folder " + serverLocation + File.separator + "webapps not found")); }