private ZipInputStream getZipInputStream() throws IOException { FileItem fileItem = version == null ? delegate.read(zipPath) : delegate.readHistory(zipPath, version); return new ZipInputStream(fileItem.getStream()); }
/** * 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(); } }
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); } }
/** * 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(); } }
fileItem = project.getRepository().readHistory(project.getFolderPath(), project.getFileData().getVersion()); } else { fileItem = project.getRepository().read(project.getFolderPath());
fileItem = repository.readHistory(folderPath, getFileData().getVersion()); } else { fileItem = repository.read(folderPath);
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); } }
.readHistory(projectFrom.getFolderPath(), projectFrom.getFileData().getVersion()); } else { fileItem = projectFrom.getRepository().read(projectFrom.getFolderPath());