public static String path(String... parts) { return concat(parts); }
/** Create a file from the list of path elements. */ public static File file(String... pathElems) { return new File(path(pathElems)); }
/** * {@inheritDoc} * * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getCollectionURI(java.lang.String, * java.lang.String) */ @Override public URI getCollectionURI(String collectionID, String fileName) { try { return new URI(getBaseUri() + COLLECTION_PATH_PREFIX + collectionID + "/" + PathSupport.toSafeName(fileName)); } catch (URISyntaxException e) { throw new IllegalStateException("Unable to create valid uri from " + collectionID + " and " + fileName); } }
/** * Concatenates the path elements with respect to leading and trailing slashes. * * @param parts * the parts to concat * @return the concatenated path */ public static String concat(String[] parts) { if (parts == null) throw new IllegalArgumentException("Argument parts is null"); if (parts.length == 0) throw new IllegalArgumentException("Array parts is empty"); String path = removeDoubleSeparator(adjustSeparator(parts[0])); for (int i = 1; i < parts.length; i++) { path = concat(path, removeDoubleSeparator(adjustSeparator(parts[i]))); } return path; }
/** * Concatenates the two urls with respect to leading and trailing slashes. * * @return the concatenated url of the two arguments */ public static String concat(String prefix, String suffix) { if (prefix == null) throw new IllegalArgumentException("Argument prefix is null"); if (suffix == null) throw new IllegalArgumentException("Argument suffix is null"); prefix = adjustSeparator(prefix); suffix = adjustSeparator(suffix); prefix = removeDoubleSeparator(prefix); suffix = removeDoubleSeparator(suffix); if (!prefix.endsWith(File.separator) && !suffix.startsWith(File.separator)) prefix += File.separator; if (prefix.endsWith(File.separator) && suffix.startsWith(File.separator)) suffix = suffix.substring(1); prefix += suffix; return prefix; }
/** * Transforms a URI into a workspace File. If the file comes from the working file repository, the path in the * workspace mirrors that of the repository. If the file comes from another source, directories are created for each * segment of the URL. Sub-directories may be created as needed. * * @param uri * the uri * @return the local file representation */ File toWorkspaceFile(URI uri) { // MH-11497: Fix for compatibility with stream security: the query parameters are deleted. // TODO Refactor this class to use the URI class and methods instead of String for handling URIs String uriString = UriBuilder.fromUri(uri).replaceQuery(null).build().toString(); String wfrPrefix = wfr.getBaseUri().toString(); String serverPath = FilenameUtils.getPath(uriString); if (uriString.startsWith(wfrPrefix)) { serverPath = serverPath.substring(wfrPrefix.length()); } else { serverPath = serverPath.replaceAll(":/*", "_"); } String wsDirectoryPath = PathSupport.concat(wsRoot, serverPath); File wsDirectory = new File(wsDirectoryPath); wsDirectory.mkdirs(); String safeFileName = PathSupport.toSafeName(FilenameUtils.getName(uriString)); if (StringUtils.isBlank(safeFileName)) safeFileName = UNKNOWN_FILENAME; return new File(wsDirectory, safeFileName); }
if (directory == null) { directory = new File(PathSupport.concat(new String[] { rootDirectory, COLLECTION_PATH_PREFIX, collectionId })); throw new NotFoundException(directory.getAbsolutePath()); File sourceFile = new File(directory, PathSupport.toSafeName(fileName)); File md5File = getMd5File(sourceFile); if (!sourceFile.exists())
private File getElementDirectory(String mediaPackageID, String mediaPackageElementID) { return new File(PathSupport.concat(new String[]{rootDirectory, MEDIAPACKAGE_PATH_PREFIX, mediaPackageID, mediaPackageElementID})); }
checkPathSafe(collectionId); checkPathSafe(fileName); File f = new File(PathSupport.concat(new String[]{rootDirectory, COLLECTION_PATH_PREFIX, collectionId, PathSupport.toSafeName(fileName)})); logger.debug("Attempting to write a file to {}", f.getAbsolutePath()); FileOutputStream out = null;
uri = UrlSupport.concat(uri, PathSupport.toSafeName(fileName)); uri = UrlSupport.concat(uri, PathSupport.toSafeName(fileName));
/** Return a file object pointing into the workspace. */ private File workspaceFile(String... path) { return new File(path(cons(String.class, wsRoot, path))); }
File f = new File(dir, PathSupport.toSafeName(filename)); File md5File = getMd5File(f);
/** Return a file object pointing into the working file repository. */ private File workingFileRepositoryFile(String... path) { return new File(path(cons(String.class, pathMappable.getPathPrefix(), path))); }
PathSupport.concat(new String[]{rootDirectory, COLLECTION_PATH_PREFIX, collectionId})); if (!collectionDir.exists()) { if (!create)
/** * {@inheritDoc} * * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getCollectionContents(java.lang.String) */ @Override public URI[] getCollectionContents(String collectionId) throws NotFoundException { File collectionDir = null; try { collectionDir = getCollectionDirectory(collectionId, false); if (collectionDir == null) throw new NotFoundException(collectionId); } catch (IOException e) { // We are not asking for the collection to be created, so this exception is never thrown } File[] files = collectionDir.listFiles(MD5_FINAME_FILTER); URI[] uris = new URI[files.length]; for (int i = 0; i < files.length; i++) { try { uris[i] = new URI(getBaseUri() + COLLECTION_PATH_PREFIX + collectionId + "/" + PathSupport.toSafeName(getSourceFile(files[i]).getName())); } catch (URISyntaxException e) { throw new IllegalStateException("Invalid URI for " + files[i]); } } return uris; }
String settings = null; File configFile = new File(PathSupport.concat(new String[] { indexSettingsPath, index, "settings.json" })); if (configFile.isFile()) { try (FileInputStream fis = new FileInputStream(configFile)) { .concat(new String[] { "/elasticsearch/", index, "settings.json" }); try (InputStream is = this.getClass().getResourceAsStream(resourcePath)) { if (is != null) {
destFile = new File(destDir, PathSupport.toSafeName(toFileName)); FileSupport.link(source, destFile); createMd5(destFile);
String mapping = null; File configFile = new File(PathSupport.concat(new String[] { indexSettingsPath, index, documentType + "-mapping.json" })); if (configFile.isFile()) { .concat(new String[] { "/elasticsearch/", index, documentType + "-mapping.json" }); try (InputStream is = this.getClass().getResourceAsStream(resourcePath)) { if (is != null) {
delete(toMediaPackage, toMediaPackageElement); } catch (NotFoundException e) { dest = new File(getElementDirectory(toMediaPackage, toMediaPackageElement), PathSupport.toSafeName(toFileName));