List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:org.broadleafcommerce.vendor.amazon.s3.S3FileServiceProvider.java
protected String getSiteSpecificResourceName(String resourceName) { BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext(); if (brc != null) { Site site = brc.getNonPersistentSite(); if (site != null) { String siteDirectory = getSiteDirectory(site); if (resourceName.startsWith("/")) { resourceName = resourceName.substring(1); }//from w w w.j av a2 s . com return FilenameUtils.concat(siteDirectory, resourceName); } } return resourceName; }
From source file:org.cleverbus.core.common.file.DefaultFileRepository.java
@Override public void commitFile(String fileId, String fileName, FileContentTypeExtEnum contentType, List<String> subFolders) { Assert.hasText(fileId, "fileId must not be empty"); Assert.hasText(fileName, "fileName must not be empty"); Assert.notNull(subFolders, "subFolders must not be null"); File tmpFile = new File(tempDir, fileId); // check file existence if (!tmpFile.exists() || !tmpFile.canRead()) { String msg = "temp file " + tmpFile + " doesn't exist or can't be read"; Log.error(msg);/*from w ww . j a v a 2 s . co m*/ throw new IntegrationException(InternalErrorEnum.E115, msg); } // move file to target directory String targetDirName = FilenameUtils.concat(fileRepoDir.getAbsolutePath(), StringUtils.join(subFolders, File.separator)); targetDirName = FilenameUtils.normalize(targetDirName); File targetDir = new File(targetDirName); try { FileUtils.moveFileToDirectory(tmpFile, targetDir, true); Log.debug("File (" + tmpFile + ") was successfully moved to directory - " + targetDir); } catch (IOException e) { String msg = "error occurred during moving temp file " + tmpFile + " to target directory - " + targetDirName; Log.error(msg); throw new IntegrationException(InternalErrorEnum.E115, msg); } // rename file File targetTmpFile = new File(targetDir, fileId); String targetFileName = FilenameUtils.concat(targetDir.getAbsolutePath(), getFileName(fileName, contentType)); targetFileName = FilenameUtils.normalize(targetFileName); try { FileUtils.moveFile(targetTmpFile, new File(targetFileName)); Log.debug("File (" + tmpFile + ") was successfully committed. New path: " + targetFileName); } catch (IOException e) { String msg = "error occurred during renaming temp file " + tmpFile + " to target directory - " + targetDirName; Log.error(msg); throw new IntegrationException(InternalErrorEnum.E115, msg); } }
From source file:org.codice.alliance.test.itests.VideoTest.java
@Test @ConditionalIgnore(condition = SkipUnstableTest.class) // CAL-300 public void testStreamingVideo() throws Exception { getServiceManager().startFeature(true, "sample-mpegts-streamgenerator"); final String videoFilePath = FilenameUtils.concat(temporaryFolder.getRoot().getCanonicalPath(), NIGHTFLIGHT);//from w ww. j av a 2 s . c o m final File videoFile = new File(videoFilePath); copyResourceToFile(NIGHTFLIGHT, videoFile); final String streamTitle = "UDP Stream Test"; final String udpStreamAddress = String.format("udp://%s:%d", LOCALHOST, udpPortNum); final Map<String, Object> streamMonitorProperties = new HashMap<>(); streamMonitorProperties.put(UdpStreamMonitor.METATYPE_TITLE, streamTitle); streamMonitorProperties.put(UdpStreamMonitor.METATYPE_MONITORED_ADDRESS, udpStreamAddress); streamMonitorProperties.put(UdpStreamMonitor.METATYPE_METACARD_UPDATE_INITIAL_DELAY, 0); streamMonitorProperties.put(UdpStreamMonitor.METATYPE_BYTE_COUNT_ROLLOVER_CONDITION, 5); streamMonitorProperties.put("startImmediately", true); startUdpStreamMonitor(streamMonitorProperties); waitForUdpStreamMonitorStart(); MpegTsUdpClient.broadcastVideo(videoFilePath, LOCALHOST, udpPortNum, NIGHTFLIGHT_DURATION_MS, MpegTsUdpClient.PACKET_SIZE, MpegTsUdpClient.PACKET_SIZE, false, null); Thread.sleep(2000); expect("The parent and child metacards to be created").within(15, TimeUnit.SECONDS) .checkEvery(1, TimeUnit.SECONDS).until(() -> executeOpenSearch("xml", "q=*").extract().xmlPath() .getList("metacards.metacard").size() == 3); final ValidatableResponse parentMetacardResponse = executeOpenSearch("xml", "q=" + streamTitle).log().all() .assertThat().body(hasXPath(METACARD_COUNT_XPATH, is("1"))) .body(hasXPath("/metacards/metacard/string[@name='title']/value", is(streamTitle))) .body(hasXPath("/metacards/metacard/string[@name='resource-uri']/value", is(udpStreamAddress))) .body(hasXPath( "/metacards/metacard/geometry[@name='media.frame-center']/value/*[local-name()='LineString']/*[local-name()='pos'][2]", is("-110.058257 54.791167"))) .body(hasXPath( "/metacards/metacard/geometry[@name='location']/value/*[local-name()='MultiPoint']/*[local-name()='pointMember'][2]/*[local-name()='Point']/*[local-name()='pos']", is("-110.058257 54.791167"))); final String parentMetacardId = parentMetacardResponse.extract().xmlPath().getString(METACARD_ID_XMLPATH); expect("The child metacards to be linked to the parent").within(3, TimeUnit.SECONDS) .until(() -> executeOpenSearch("xml", "q=mpegts-stream*").extract().xmlPath().getInt( "metacards.metacard.string.findAll { it.@name == 'metacard.associations.derived' }.size()") == 2); final String chunkDividerDate = "2009-06-19T07:26:30Z"; verifyChunkMetacard("dtend=" + chunkDividerDate, 1212.82825971, "-110.058257 54.791167", parentMetacardId); verifyChunkMetacard("dtstart=" + chunkDividerDate, 1206.75516899, "-110.058421 54.791636", parentMetacardId); getServiceManager().stopFeature(true, "sample-mpegts-streamgenerator"); }
From source file:org.codice.ddf.catalog.content.plugin.video.VideoThumbnailPluginTest.java
@Before public void setUp() throws IOException, MimeTypeParseException, URISyntaxException { System.setProperty("ddf.home", SystemUtils.USER_DIR); binaryPath = FilenameUtils.concat(System.getProperty("ddf.home"), "bin_third_party"); videoThumbnailPlugin = new VideoThumbnailPlugin(createMockBundleContext()); tmpContentPaths = new HashMap<>(); }
From source file:org.coinspark.wallet.CSMessageDatabase.java
public CSMessageDatabase(String FilePrefix, CSLogger CSLog, Wallet ParentWallet) { dirName = FilePrefix + MESSAGE_DIR_SUFFIX + File.separator; fileName = dirName + MESSAGE_DATABASE_FILENAME + ((CSMessageDatabase.testnet3) ? TESTNET3_FILENAME_SUFFIX : ""); // H2 will add .mv.db extension itself csLog = CSLog;//w w w . ja va2 s. c o m wallet = ParentWallet; String folder = FilenameUtils.getFullPath(FilePrefix); String name = MESSAGE_BLOB_KEYSTORE_FILENAME + ((CSMessageDatabase.testnet3) ? TESTNET3_FILENAME_SUFFIX : "") + MESSAGE_MVSTORE_FILE_EXTENSION; String blobPath = FilenameUtils.concat(folder, name); boolean b = CSMessageDatabase.initBlobMap(blobPath); if (!b) { log.error("Message DB: Could not create BLOB storage map at: " + blobPath); return; } File dir = new File(dirName); if (!dir.exists()) { // Files.createDirectory(Paths.get(dirName)); try { dir.mkdir(); } catch (SecurityException ex) { log.error("Message DB: Cannot create files directory" + ex.getClass().getName() + " " + ex.getMessage()); return; } } String kvStoreFileName = dirName + MESSAGE_META_KEYSTORE_FILENAME + ((CSMessageDatabase.testnet3) ? TESTNET3_FILENAME_SUFFIX : "") + MESSAGE_MVSTORE_FILE_EXTENSION; kvStore = MVStore.open(kvStoreFileName); if (kvStore != null) { defMap = kvStore.openMap(MESSAGE_TXID_TO_META_MAP_NAME); errorMap = kvStore.openMap(MESSAGE_TXID_TO_ERROR_MAP_NAME); } // TODO?: This database URL could be passed in via constructor String databaseUrl = "jdbc:h2:file:" + fileName + ";USER=sa;PASSWORD=sa;AUTO_SERVER=TRUE"; try { connectionSource = new JdbcConnectionSource(databaseUrl); messageDao = DaoManager.createDao(connectionSource, CSMessage.class); TableUtils.createTableIfNotExists(connectionSource, CSMessage.class); messagePartDao = DaoManager.createDao(connectionSource, CSMessagePart.class); TableUtils.createTableIfNotExists(connectionSource, CSMessagePart.class); } catch (SQLException e) { e.printStackTrace(); } }
From source file:org.craftercms.deployer.impl.processors.GitPullProcessor.java
protected void addClonedFilesToChangeSet(File parent, String parentPath, ChangeSet changeSet) { String[] filenames = parent.list(HiddenFileFilter.VISIBLE); if (filenames != null) { for (String filename : filenames) { File file = new File(parent, filename); String path = FilenameUtils.concat(parentPath, filename); if (file.isDirectory()) { addClonedFilesToChangeSet(file, path, changeSet); } else { logger.debug("New file: {}", path); changeSet.getCreatedFiles().add(path); }/*from ww w .j a va2 s . c o m*/ } } }
From source file:org.cryptable.zap.mavenplugin.ProcessMojo.java
/** * * Execute the whole shabang/*from w w w. j a v a 2s . c om*/ * @throws MojoExecutionException Throws exception when ZAProxy fails */ public void execute() throws MojoExecutionException { System.setProperty("java.net.debug", "all"); try { zapClientAPI = new ClientApi(zapProxyHost, zapProxyPort); proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(zapProxyHost, zapProxyPort)); if (spiderURL) { getLog().info("Spider the site [" + targetURL + "]"); spiderURL(targetURL); } else { getLog().info("skip spidering the site [" + targetURL + "]"); } if (scanURL) { getLog().info("Scan the site [" + targetURL + "]"); scanURL(targetURL); } else { getLog().info("skip scanning the site [" + targetURL + "]"); } // filename to share between the session file and the report file String fileName = ""; if (saveSession) { fileName = createTempFilename("ZAP", ""); zapClientAPI.core.saveSession(fileName, "true", ""); } else { getLog().info("skip saveSession"); } if (reportAlerts) { // reuse fileName of the session file if ((reportsFilenameNoExtension == null) || reportsFilenameNoExtension.isEmpty()) { if ((fileName == null) || (fileName.length() == 0)) { fileName = createTempFilename("ZAP", ""); } } else { fileName = reportsFilenameNoExtension; } String fileName_no_extension = FilenameUtils.concat(reportsDirectory, fileName); try { String alerts = getAllAlerts(getAllAlertsFormat(format)); String fullFileName = fileName_no_extension + "." + getAllAlertsFormat(format); FileUtils.writeStringToFile(new File(fullFileName), (jsonp ? "var zaproxy_jsonpData = " : "") + alerts); getLog().info("File save in format in [" + getAllAlertsFormat(format) + "]"); if (format.equals("json")) { Utils.copyResourcesRecursively(getClass().getResource("/zap-reports/"), new File(reportsDirectory)); } } catch (Exception e) { getLog().error(e.toString()); e.printStackTrace(); } } if ((propertyFile != null) && !propertyFile.isEmpty()) { restoreProperties(); } } catch (Exception e) { getLog().error(e.toString()); throw new MojoExecutionException("Processing with ZAP failed"); } finally { if (shutdownZAP && (zapClientAPI != null)) { try { getLog().info("Shutdown ZAProxy"); zapClientAPI.core.shutdown(apiKEY); } catch (Exception e) { getLog().error(e.toString()); e.printStackTrace(); } } else { getLog().info("No shutdown of ZAP"); } } }
From source file:org.culturegraph.mf.stream.sink.TripleObjectWriter.java
@Override public void process(final Triple triple) { final String file = FilenameUtils.concat(FilenameUtils.concat(baseDir, triple.getSubject()), triple.getPredicate());/*from ww w .j a va2 s .com*/ ensurePathExists(file); try { final Writer writer = new OutputStreamWriter(new FileOutputStream(file), encoding); IOUtils.write(triple.getObject(), writer); writer.close(); } catch (IOException e) { throw new MetafactureException(e); } }
From source file:org.datavec.api.records.reader.impl.LineReaderTest.java
@Test public void testLineReader() throws Exception { String tempDir = System.getProperty("java.io.tmpdir"); File tmpdir = new File(tempDir, "tmpdir-testLineReader"); if (tmpdir.exists()) tmpdir.delete();//from w w w .ja va 2 s . c om tmpdir.mkdir(); File tmp1 = new File(FilenameUtils.concat(tmpdir.getPath(), "tmp1.txt")); File tmp2 = new File(FilenameUtils.concat(tmpdir.getPath(), "tmp2.txt")); File tmp3 = new File(FilenameUtils.concat(tmpdir.getPath(), "tmp3.txt")); FileUtils.writeLines(tmp1, Arrays.asList("1", "2", "3")); FileUtils.writeLines(tmp2, Arrays.asList("4", "5", "6")); FileUtils.writeLines(tmp3, Arrays.asList("7", "8", "9")); InputSplit split = new FileSplit(tmpdir); RecordReader reader = new LineRecordReader(); reader.initialize(split); int count = 0; List<List<Writable>> list = new ArrayList<>(); while (reader.hasNext()) { List<Writable> l = reader.next(); assertEquals(1, l.size()); list.add(l); count++; } assertEquals(9, count); try { FileUtils.deleteDirectory(tmpdir); } catch (Exception e) { e.printStackTrace(); } }