List of usage examples for org.apache.wicket.util.file Files writeTo
public static int writeTo(final java.io.File file, final InputStream input) throws IOException
From source file:com.marc.lastweek.business.services.images.impl.ImageServiceImpl.java
License:Open Source License
public void saveAllImages(Folder temporalFolder) { Folder folder = createSaveFolder(temporalFolder); List<File> files = Arrays.asList(temporalFolder.listFiles()); if (files != null) { for (File file : files) { // Create a new file File newFile = new File(folder, file.getName()); // Check new file, delete if it allready existed checkFileExists(newFile);/*ww w. j ava 2s. co m*/ try { //TODO check if creation succed Files.writeTo(newFile, new FileInputStream(file)); Files.remove(file); } catch (Exception e) { throw new IllegalStateException("Unable to write file"); } } temporalFolder.delete(); } }
From source file:org.sakaiproject.scorm.ui.reporting.pages.ResultsListPage.java
License:Educational Community License
public ResultsListPage(PageParameters pageParams) { super(pageParams); final long contentPackageId = pageParams.getLong("contentPackageId"); final ContentPackage contentPackage = contentService.getContentPackage(contentPackageId); // SCO-94 - deny users who do not have scorm.view.results permission String context = lms.currentContext(); boolean canViewResults = lms.canViewResults(context); Label heading = new Label("heading", new ResourceModel("page.heading.notAllowed")); add(heading);//from www .j a v a 2 s.c o m final AttemptDataProvider dataProvider = new AttemptDataProvider(contentPackageId); dataProvider.setFilterConfigurerVisible(true); dataProvider.setTableTitle(getLocalizer().getString("table.title", this)); // SCO-127 buildExportHeaders(); AbstractReadOnlyModel<File> fileModel = new AbstractReadOnlyModel<File>() { @Override public File getObject() { File tempFile = null; try { tempFile = File.createTempFile(contentPackage.getTitle() + "_results", ".csv"); InputStream data = new ByteArrayInputStream(generateExportCSV(dataProvider).getBytes()); Files.writeTo(tempFile, data); } catch (IOException ex) { LOG.error("Could not generate results export: ", ex); } return tempFile; } }; DownloadLink btnExport = new DownloadLink("btnExport", fileModel, contentPackage.getTitle() + "_results.csv"); btnExport.setDeleteAfterDownload(true); add(btnExport); if (!canViewResults) { btnExport.setVisibilityAllowed(false); heading.setVisibilityAllowed(true); add(new WebMarkupContainer("attemptPresenter")); add(new WebMarkupContainer("details")); } else { // SCO-94 heading.setVisibilityAllowed(false); addBreadcrumb(new Model(contentPackage.getTitle()), ResultsListPage.class, new PageParameters(), false); EnhancedDataPresenter presenter = new EnhancedDataPresenter("attemptPresenter", getColumns(), dataProvider); add(presenter); add(new ContentPackageDetailPanel("details", contentPackage)); } }
From source file:org.wicketstuff.pageserializer.common.analyze.report.io.DirectoryBasedReportOutput.java
License:Apache License
protected void write(IReportKeyGenerator keyGenerator, ISerializedObjectTree tree, IReportRenderer renderer) { String report = renderer.render(tree); File output = new File(_directory, keyGenerator.keyOf(tree)); try {//from ww w.j a va2s.c o m Files.writeTo(output, new ByteArrayInputStream(report.getBytes(Charset.forName("UTF-8")))); } catch (IOException e) { throw new RuntimeException("write report to " + output, e); } }