public static String extractDirNameFromAbsolutePath(String path) { // default is unix so try with '/' // otherwise force File.separator if (path.endsWith("/") || path.endsWith("\\")) { path = path.substring(0, path.length() - 1); } return FileUtil.stripPath(path); }
@Override protected boolean isMatched(GenericFile<FTPFile> file, String doneFileName, List<FTPFile> files) { String onlyName = FileUtil.stripPath(doneFileName); for (FTPFile f : files) { if (f.getName().equals(onlyName)) { return true; } } log.trace("Done file: {} does not exist", doneFileName); return false; }
@Override protected boolean isMatched(GenericFile<SftpRemoteFile> file, String doneFileName, List<SftpRemoteFile> files) { String onlyName = FileUtil.stripPath(doneFileName); for (SftpRemoteFile f : files) { if (f.getFilename().equals(onlyName)) { return true; } } log.trace("Done file: {} does not exist", doneFileName); return false; }
private Map<String, List<CamelNodeDetails>> groupAnonymousRoutesByClassName(List<CamelNodeDetails> anonymousRouteTrees) { Map<String, List<CamelNodeDetails>> answer = new LinkedHashMap<>(); for (CamelNodeDetails t : anonymousRouteTrees) { String fileName = asRelativeFile(t.getFileName()); String className = FileUtil.stripExt(FileUtil.stripPath(fileName)); List<CamelNodeDetails> list = answer.computeIfAbsent(className, k -> new ArrayList<>()); list.add(t); } return answer; }
@Override public Enumeration<URL> loadAllResourcesAsURL(String uri) { ObjectHelper.notEmpty(uri, "uri"); Vector<URL> answer = new Vector<>(); try { String resolvedName = resolveUriPath(uri); Enumeration<URL> e = bundleContext.getBundle().getResources(resolvedName); while (e != null && e.hasMoreElements()) { answer.add(e.nextElement()); } String path = FileUtil.onlyPath(uri); String name = FileUtil.stripPath(uri); if (path != null && name != null) { for (Bundle bundle : bundleContext.getBundles()) { LOG.trace("Finding all entries in path: {} with pattern: {}", path, name); e = bundle.findEntries(path, name, false); while (e != null && e.hasMoreElements()) { answer.add(e.nextElement()); } } } } catch (IOException e) { throw new RuntimeException("Cannot load resource: " + uri, e); } return answer.elements(); }
} else { String disposition = part.getDisposition(); String fileName = FileUtil.stripPath(part.getFileName());
@Override protected void doStart() throws Exception { super.doStart(); // use file watch service if we read from file if (endpoint.isFileWatcher()) { String dir = new File(endpoint.getFileName()).getParent(); fileWatcher = new FileWatcherStrategy(dir, (file) -> { String onlyName = file.getName(); String target = FileUtil.stripPath(endpoint.getFileName()); LOG.trace("File changed: {}", onlyName); if (onlyName.equals(target)) { // file is changed watchFileChanged = true; } }); fileWatcher.setCamelContext(getEndpoint().getCamelContext()); } ServiceHelper.startService(fileWatcher); // if we scan the stream we are lenient and can wait for the stream to be available later if (!endpoint.isScanStream()) { initializeStream(); } executor = endpoint.getCamelContext().getExecutorServiceManager().newSingleThreadExecutor(this, endpoint.getEndpointUri()); executor.execute(this); if (endpoint.getGroupLines() < 0) { throw new IllegalArgumentException("Option groupLines must be 0 or positive number, was " + endpoint.getGroupLines()); } }
String onlyName = FileUtil.stripPath(fileName); dummy.getIn().setHeader(Exchange.FILE_NAME, fileName); dummy.getIn().setHeader(Exchange.FILE_NAME_ONLY, onlyName);
remoteName = FileUtil.stripPath(name);
public boolean deleteFile(String name) throws GenericFileOperationFailedException { log.debug("Deleting file: {}", name); boolean result; String target = name; String currentDir = null; try { if (endpoint.getConfiguration().isStepwise()) { // remember current directory currentDir = getCurrentDirectory(); target = FileUtil.stripPath(name); try { changeCurrentDirectory(FileUtil.onlyPath(name)); } catch (GenericFileOperationFailedException e) { // we could not change directory, try to change back before changeCurrentDirectory(currentDir); throw e; } } // delete the file log.trace("Client deleteFile: {}", target); result = client.deleteFile(target); // change back to previous directory if (currentDir != null) { changeCurrentDirectory(currentDir); } } catch (IOException e) { throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e); } return result; }
remoteName = FileUtil.stripPath(name);
remoteName = FileUtil.stripPath(name);
public synchronized boolean storeFile(String name, Exchange exchange, long size) throws GenericFileOperationFailedException { // must normalize name first name = endpoint.getConfiguration().normalizePath(name); LOG.trace("storeFile({})", name); boolean answer = false; String currentDir = null; String path = FileUtil.onlyPath(name); String targetName = name; try { if (path != null && endpoint.getConfiguration().isStepwise()) { // must remember current dir so we stay in that directory after // the write currentDir = getCurrentDirectory(); // change to path of name changeCurrentDirectory(path); // the target name should be without path, as we have changed // directory targetName = FileUtil.stripPath(name); } // store the file answer = doStoreFile(name, targetName, exchange); } finally { // change back to current directory if we changed directory if (currentDir != null) { changeCurrentDirectory(currentDir); } } return answer; }
String onlyName = FileUtil.stripPath(fileName); dummy.getIn().setHeader(Exchange.FILE_NAME, fileName); dummy.getIn().setHeader(Exchange.FILE_NAME_ONLY, onlyName);
remoteName = FileUtil.stripPath(name);
targetName = FileUtil.stripPath(name);