private ZipInputStream getZipInputStream() throws IOException { FileItem fileItem = version == null ? delegate.read(zipPath) : delegate.readHistory(zipPath, version); return new ZipInputStream(fileItem.getStream()); }
/** * Returns a zipped project. * * @param name a project name * @param version a project version * @return a zipped project */ @GET @Path("project/{name}/{version}") @Produces("application/zip") public Response getProject(@PathParam("name") String name, @PathParam("version") String version) throws WorkspaceException { try { if (!isGranted(Privileges.VIEW_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have VIEW privilege").build(); } FileItem fileItem = getRepository().readHistory(getFileName(name), version); if (fileItem == null) { throw new FileNotFoundException("File '" + name + "' not found."); } String zipFileName = String.format("%s-%s.zip", name, version); return Response.ok(fileItem.getStream()) .header("Content-Disposition", "attachment;filename=\"" + zipFileName + "\"") .build(); } catch (IOException ex) { return Response.status(Status.NOT_FOUND).entity(ex.getMessage()).build(); } }
/** * Returns a zipped project. * * @param name a project name * @param version a project version * @return a zipped project */ @GET @Path("project/{name}/{version}") @Produces("application/zip") public Response getProject(@PathParam("name") String name, @PathParam("version") String version) throws WorkspaceException { try { if (!isGranted(Privileges.VIEW_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have VIEW privilege").build(); } FileItem fileItem = getRepository().readHistory(getFileName(name), version); if (fileItem == null) { throw new FileNotFoundException("File '" + name + "' not found."); } String zipFileName = String.format("%s-%s.zip", name, version); return Response.ok(fileItem.getStream()) .header("Content-Disposition", "attachment;filename=\"" + zipFileName + "\"") .build(); } catch (IOException ex) { return Response.status(Status.NOT_FOUND).entity(ex.getMessage()).build(); } }
/** * Returns the latest zipped project. * * @param name a project name * @return a zipped project */ @GET @Path("project/{name}") @Produces("application/zip") public Response getLastProject(@PathParam("name") String name) throws WorkspaceException { try { if (!isGranted(Privileges.VIEW_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have VIEW privilege").build(); } FileItem fileItem = getRepository().read(getFileName(name)); if (fileItem == null) { throw new FileNotFoundException("File '" + name + "' not found."); } String zipFileName = String.format("%s-%s.zip", name, fileItem.getData().getVersion()); return Response.ok(fileItem.getStream()) .header("Content-Disposition", "attachment;filename=\"" + zipFileName + "\"") .build(); } catch (IOException ex) { return Response.status(Status.NOT_FOUND).entity(ex.getMessage()).build(); } }
/** * Returns the latest zipped project. * * @param name a project name * @return a zipped project */ @GET @Path("project/{name}") @Produces("application/zip") public Response getLastProject(@PathParam("name") String name) throws WorkspaceException { try { if (!isGranted(Privileges.VIEW_PROJECTS)) { return Response.status(Status.FORBIDDEN).entity("Doesn't have VIEW privilege").build(); } FileItem fileItem = getRepository().read(getFileName(name)); if (fileItem == null) { throw new FileNotFoundException("File '" + name + "' not found."); } String zipFileName = String.format("%s-%s.zip", name, fileItem.getData().getVersion()); return Response.ok(fileItem.getStream()) .header("Content-Disposition", "attachment;filename=\"" + zipFileName + "\"") .build(); } catch (IOException ex) { return Response.status(Status.NOT_FOUND).entity(ex.getMessage()).build(); } }
@Override public FileChange next() { FileData file = files.get(fileIndex++); String srcFileName = file.getName(); String fileTo = deploymentPath + srcFileName.substring(rulesPath.length()); FileItem fileItem; try { fileItem = designRepo.readHistory(file.getName(), file.getVersion()); IOUtils.closeQuietly(openedStream); openedStream = fileItem.getStream(); return new FileChange(fileTo, openedStream); } catch (Exception e) { log.error(e.getMessage(), e); return null; } }
private void archiveAndSave(FolderRepository designRepo, String projectPath, String version, Repository deployRepo, FileData dest) throws ProjectException { ByteArrayOutputStream out = new ByteArrayOutputStream(); ZipOutputStream zipOutputStream = null; try { zipOutputStream = new ZipOutputStream(out); List<FileData> files = designRepo.listFiles(projectPath, version); for (FileData file : files) { String internalPath = file.getName().substring(projectPath.length()); zipOutputStream.putNextEntry(new ZipEntry(internalPath)); FileItem fileItem = designRepo.readHistory(file.getName(), file.getVersion()); try (InputStream content = fileItem.getStream()) { IOUtils.copy(content, zipOutputStream); } zipOutputStream.closeEntry(); } zipOutputStream.finish(); dest.setSize(out.size()); deployRepo.save(dest, new ByteArrayInputStream(out.toByteArray())); } catch (IOException e) { throw new ProjectException(e.getMessage(), e); } finally { IOUtils.closeQuietly(zipOutputStream); } }
private Iterator<FileChange> getProjectIterator(String projectName, String version) { try { if (designRepo instanceof FolderRepository) { // Project in design repository is stored as a folder String srcProjectPath = rulesPath + projectName + "/"; return new FolderIterator(((FolderRepository) designRepo).listFiles(srcProjectPath, version)); } else { // Project in design repository is stored as a zip file FileItem srcPrj = designRepo.readHistory(rulesPath + projectName, version); if (srcPrj == null) { throw new FileNotFoundException("File '" + rulesPath + projectName + "' for version " + version + " is not found"); } IOUtils.closeQuietly(openedStream); ZipInputStream stream = new ZipInputStream(srcPrj.getStream()); openedStream = stream; return new FileChangesFromZip(stream, deploymentPath + projectName).iterator(); } } catch (Exception e) { log.error(e.getMessage(), e); return null; } }
public InputStream getContent() throws ProjectException { try { if (isHistoric()) { return getRepository().readHistory(getFileData().getName(), getFileData().getVersion()).getStream(); } else { return getRepository().read(getFileData().getName()).getStream(); } } catch (IOException ex) { throw new ProjectException(ex.getMessage(), ex); } }
FileItem fileItem = readHistory(fileFrom, data.getVersion()); String fileTo = destData.getName() + fileFrom.substring(srcName.length()); files.add(new FileChange(fileTo, fileItem.getStream())); return save(destData, fileItem.getStream()); } finally { if (fileItem != null) { IOUtils.closeQuietly(fileItem.getStream());
@Override public FileData copyHistory(String srcName, FileData destData, String version) throws IOException { FileItem fileItem = null; try { fileItem = readHistory(srcName, version); FileData copy = new FileData(); copy.setName(destData.getName()); copy.setComment(destData.getComment()); copy.setAuthor(destData.getAuthor()); copy.setSize(fileItem.getData().getSize()); return save(copy, fileItem.getStream()); } finally { if (fileItem != null) { IOUtils.closeQuietly(fileItem.getStream()); } } }
@Override public FileData copyHistory(String srcName, FileData destData, String version) throws IOException { FileItem fileItem = null; try { fileItem = readHistory(srcName, version); FileData copy = new FileData(); copy.setName(destData.getName()); copy.setComment(destData.getComment()); copy.setAuthor(destData.getAuthor()); copy.setSize(fileItem.getData().getSize()); return save(copy, fileItem.getStream()); } finally { if (fileItem != null) { IOUtils.closeQuietly(fileItem.getStream()); } } }
return internalArtefacts; ZipInputStream zipInputStream = new ZipInputStream(fileItem.getStream()); try { ZipEntry entry;
IOUtils.copyAndClose(fileItem.getStream(), fileOutputStream);
String projectName = pd.getProjectName(); FileItem srcPrj = designRepo.readHistory("DESIGN/rules/" + projectName, version); stream = srcPrj.getStream(); FileData dest = new FileData(); dest.setName(deploymentPath + "/" + projectName);
private void unpack(AProject projectFrom, Repository repositoryTo, String folderTo, CommonUser user) throws ProjectException { ZipInputStream stream = null; try { FileItem fileItem; if (projectFrom.isHistoric()) { fileItem = projectFrom.getRepository() .readHistory(projectFrom.getFolderPath(), projectFrom.getFileData().getVersion()); } else { fileItem = projectFrom.getRepository().read(projectFrom.getFolderPath()); } if (fileItem == null) { return; } stream = new ZipInputStream(fileItem.getStream()); FileData fileData = getFileData(); fileData.setAuthor(user == null ? null : user.getUserName()); ((FolderRepository) repositoryTo).save(fileData, new FileChangesFromZip(stream, folderTo)); } catch (IOException e) { throw new ProjectException("Can't update: " + e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } }
} else { FileItem srcPrj = designRepo.readHistory(rulesPath + projectName, version); stream = srcPrj.getStream(); dest.setSize(srcPrj.getData().getSize()); deployRepo.save(dest, stream);
stream = fileItem.getStream(); fileData.setAuthor(user == null ? null : user.getUserName()); setFileData(repositoryTo.save(fileData, stream));