Java Code Examples for org.apache.wicket.markup.html.form.upload.FileUpload#closeStreams()

The following examples show how to use org.apache.wicket.markup.html.form.upload.FileUpload#closeStreams() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UploadableImagePanel.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
public void process(Optional<AjaxRequestTarget> target) {
	FileUpload fu = fileUploadField.getFileUpload();
	if (fu != null) {
		File temp = null;
		try {
			temp = fu.writeToTempFile();
			StoredFile sf = new StoredFile(fu.getClientFileName(), temp);
			if (sf.isImage()) {
				processImage(sf, temp);
			}
		} catch (Exception e) {
			log.error("Error", e);
		} finally {
			if (temp != null && temp.exists()) {
				log.debug("Temp file was deleted ? {}", temp.delete());
			}
			fu.closeStreams();
			fu.delete();
		}
	}
	update(target);
}
 
Example 2
Source File: TeamCalImportPage.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
protected void importEvents()
{
  checkAccess();
  final FileUpload fileUpload = form.fileUploadField.getFileUpload();
  if (fileUpload != null) {
    try {
      final InputStream is = fileUpload.getInputStream();
      actionLog.reset();
      final String clientFilename = fileUpload.getClientFileName();
      final CalendarBuilder builder = new CalendarBuilder();
      final Calendar calendar = builder.build(is);
      final ImportStorage<TeamEventDO> storage = teamCalImportDao.importEvents(calendar, clientFilename, actionLog);
      setStorage(storage);
    } catch (final Exception ex) {
      log.error(ex.getMessage(), ex);
      error("An error occurred (see log files for details): " + ex.getMessage());
      clear();
    } finally {
      fileUpload.closeStreams();
    }
  }
}
 
Example 3
Source File: UploadDialog.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
private void convertAll() {
	List<FileUpload> ful = uploadField.getFileUploads();
	final BaseFileItem parent = roomFiles.getLastSelected();
	boolean clean = cleanWb.getModelObject();
	final long totalSize = ful.stream().mapToLong(FileUpload::getSize).sum();
	long currentSize = 0;
	for (FileUpload fu : ful) {
		long size = fu.getSize();
		try {
			FileItem f = new FileItem();
			f.setSize(size);
			f.setName(fu.getClientFileName());
			if (parent == null || !(parent instanceof FileItem)) {
				f.setOwnerId(getUserId());
			} else {
				f.setRoomId(parent.getRoomId());
				f.setOwnerId(parent.getOwnerId());
				f.setGroupId(parent.getGroupId());
				if (parent.getId() != null) {
					f.setParentId(BaseFileItem.Type.FOLDER == parent.getType() ? parent.getId() : parent.getParentId());
				}
			}
			f.setInsertedBy(getUserId());

			ProcessResultList logs = processor.processFile(f, fu.getInputStream()
					, Optional.<DoubleConsumer>of(part -> progress += (int)(100 * part * size / totalSize)));
			for (ProcessResult res : logs.getJobs()) {
				fileLogDao.add(res.getProcess(), f, res);
			}
			if (logs.hasError()) {
				form.error(getString("convert.errors.file"));
			} else {
				if (toWb.getModelObject()) {
					room.getWb().sendFileToWb(f, clean);
					clean = false;
				}
			}
		} catch (Exception e) {
			log.error("Unexpected error while processing uploaded file", e);
			form.error(e.getMessage() == null ? "Unexpected error" : e.getMessage());
		} finally {
			fu.closeStreams();
			fu.delete();
		}
		currentSize += size;
		progress = (int)(100 * currentSize / totalSize);
	}
	progress = 100;
}