private static StoragePath extractToStoragePathChild(StoragePath fromStoragePath, StoragePath fromStoragePathChild, StoragePath toStoragePath) throws RequestNotValidException { List<String> fromChildRelativePath = fromStoragePathChild.asList().subList(fromStoragePath.asList().size(), fromStoragePathChild.asList().size()); List<String> toChildAbsolutePath = new ArrayList<>(toStoragePath.asList()); toChildAbsolutePath.addAll(fromChildRelativePath); return DefaultStoragePath.parse(toChildAbsolutePath); }
public static DefaultStoragePath parse(StoragePath base, String... resourceNames) throws RequestNotValidException { List<String> pathPartials = new ArrayList<>(base.asList()); for (String resourceName : resourceNames) { pathPartials.add(resourceName); } return parse(pathPartials); }
/** * Get path * * @param basePath * base path * @param storagePath * storage path, related to base path, that one wants to resolve */ public static Path getEntityPath(Path basePath, StoragePath storagePath) { Path resourcePath = basePath; for (String pathPartial : storagePath.asList()) { resourcePath = resourcePath.resolve(encodePathPartial(pathPartial)); } return resourcePath; }
public static Path getEntityPath(Path basePath, StoragePath storagePath, String version) throws RequestNotValidException { if (version.indexOf(VERSION_SEP) >= 0) { throw new RequestNotValidException("Cannot use '" + VERSION_SEP + "' in version " + version); } Path resourcePath = basePath; for (Iterator<String> iterator = storagePath.asList().iterator(); iterator.hasNext();) { String pathPartial = iterator.next(); if (!iterator.hasNext()) { pathPartial += VERSION_SEP + version; } resourcePath = resourcePath.resolve(encodePathPartial(pathPartial)); } return resourcePath; }
@Override public void consumeOutputStream(OutputStream out) throws IOException { try (BufferedOutputStream bos = new BufferedOutputStream(out); ZipOutputStream zos = new ZipOutputStream(bos); CloseableIterable<Resource> resources = storage.listResourcesUnderDirectory(storagePath, true);) { int basePathSize = storagePath.asList().size(); for (Resource r : resources) { List<String> pathAsList = r.getStoragePath().asList(); List<String> relativePathAsList = pathAsList.subList(basePathSize, pathAsList.size()); String entryPath = relativePathAsList.stream().collect(Collectors.joining(ZIP_PATH_DELIMITER)); if (r.isDirectory()) { // adding a directory entryPath += ZIP_PATH_DELIMITER; zos.putNextEntry(new ZipEntry(entryPath)); zos.closeEntry(); } else { // adding a file ZipEntry entry = new ZipEntry(entryPath); zos.putNextEntry(entry); Binary binary = storage.getBinary(r.getStoragePath()); try (InputStream inputStream = binary.getContent().createInputStream()) { IOUtils.copy(inputStream, zos); } zos.closeEntry(); } } } catch (GenericException | RequestNotValidException | NotFoundException | AuthorizationDeniedException e) { throw new IOException(e); } }
List<String> pathList = new ArrayList<>(oldStoragePath.asList());