当前位置: 首页>>代码示例>>Java>>正文


Java UploadedFile类代码示例

本文整理汇总了Java中org.primefaces.model.UploadedFile的典型用法代码示例。如果您正苦于以下问题:Java UploadedFile类的具体用法?Java UploadedFile怎么用?Java UploadedFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UploadedFile类属于org.primefaces.model包,在下文中一共展示了UploadedFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleFileUpload

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
public void handleFileUpload(FileUploadEvent event) {
	UploadedFile uploadedFile = event.getFile();
	String uploadedFileName = uploadedFile.getFileName();
	StringBuilder tmpFileNameBuilder = new StringBuilder();

	tmpFileNameBuilder.append(System.currentTimeMillis());
	tmpFileNameBuilder.append(".");
	tmpFileNameBuilder.append(FilenameUtils.getExtension(uploadedFileName));
	tmpFileName = tmpFileNameBuilder.toString();
	String tmpFilePath = getTmpFilePath();

	try {
		uploadedFile.write(tmpFilePath);
		cropImage = true;
		editing = false;
		editingSku = false;
	} catch (Exception e) {
		// logger.error("Erro ao salvar a imagem", e);
		addMessage("admin.produtos.erro_upload", FacesMessage.SEVERITY_ERROR);
	}
}
 
开发者ID:raphaelazzolini,项目名称:mercurius,代码行数:22,代码来源:ProductsAdminMBean.java

示例2: handleParametersZipFile

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
/**
 * 
 * @param parameterZipFile
 * @param infoMessages
 * @param errorMessages
 * @param availableParameters
 */
public void handleParametersZipFile(UploadedFile parameterZipFile, Messages infoMessages, 
		Messages errorMessages, BeanSettingsContainer beanSettingsContainer) {
	//check user input
	if(parameterZipFile == null) {
		errorMessages.setMessage("uploadParametersError", "Error: Uploading ZIP file failed");
		System.err.println("Error: Uploading file failed (event is null)");
		return;
	}
	//create upload folder
	File uploadFolder = this.fileStorer.prepareFolder(beanSettingsContainer.getRootSessionFolder() + Constants.OS_SPECIFIC_FILE_SEPARATOR + "uploads", errorMessages);
	if(uploadFolder == null) return;
	//store the file
	java.util.zip.ZipFile zipFile = null;
	java.io.File[] contentFiles = null; 
	try {
		zipFile = new java.util.zip.ZipFile(this.fileStorer.saveUploadedFile(parameterZipFile, uploadFolder));
		contentFiles = this.fileStorer.decompressZipFile(zipFile, uploadFolder);
	} catch(Exception e) {
		errorMessages.setMessage("uploadParametersError", "Error: ZIP file could not be saved");
		System.out.println("Error: ZIP file could not be saved");
		return;
	}
	//write parameter data to the settings object of the backing bean
	beanSettingsContainer = new BeanSettingsContainer(beanSettingsContainer.getRootSessionFolder());
	//check and init all settings
	beanSettingsContainer.readUploadedSettings(contentFiles, infoMessages, errorMessages, beanSettingsContainer.getAvailableParameters(), beanSettingsContainer.getRootSessionFolder());
}
 
开发者ID:c-ruttkies,项目名称:MetFragRelaunched,代码行数:35,代码来源:UserInputDataHandler.java

示例3: convertUploadedFileToPhoto

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
/**
 * Converts uploaded file into photo model.
 *
 * @param uploadedFile      Newly uploaded photo to convert.
 * @return                  Photo model representation.
 */
private Photo convertUploadedFileToPhoto(final UploadedFile uploadedFile) {

	if (uploadedFile == null) {
		log.error("Event fired without file content!");
		return null;
	}

	log.info("Uploaded file name " + uploadedFile.getFileName() + " " + uploadedFile.getContentType() + " " + uploadedFile.getSize());

	Photo photo = new Photo();
	photo.setPhotoContent(getContents(uploadedFile));

	if (photo.getPhotoContent() == null || photo.getPhotoContent().length == 0) {
		return null;
	}

	photo.setUserId(webUserSession.getWebUser().getId());
	photo.setUserName(webUserSession.getWebUser().getUserName());
	photo.setPhotoName(derivePhotoName(uploadedFile.getFileName()));
	photo.setOriginalFileName(uploadedFile.getFileName());
	photo.setPhotoType(uploadedFile.getContentType());
	photo.setSize(uploadedFile.getSize());
	photo.setUploaded(new Date());

	return photo;
}
 
开发者ID:heather92115,项目名称:photosOpen,代码行数:33,代码来源:PhotoListBean.java

示例4: UploadedFileIterator

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
public UploadedFileIterator(UploadedFile item, String... extension) throws IOException {
    super();
    this.extension = extension;
    isZip = item.getFileName().toLowerCase().endsWith(".zip");
    itemInputStream = item.getInputstream();
    if (isZip) {
        try {
            in = new MyInputStream(
                    new ArchiveStreamFactory().createArchiveInputStream("zip", itemInputStream));
            // moveNext();
        } catch (ArchiveException e) {
            throw new IOException(e);
        }
    } else if (isValid(item.getFileName())) {
        next = new FileInputStreamWrapper(item.getFileName(), itemInputStream);
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:18,代码来源:UploadedFileIterator.java

示例5: restore

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
public boolean restore(UploadedFile file) {
  List<String> command = new ArrayList<String>();
  command.add("mysql");
  command.add("-u" + USERNAME);
  command.add("-p" + PASSWORD);
  command.add(DATABASE);
  try {
    InputStream inputStream = file.getInputstream();
    Process process = new ProcessBuilder(command).start();
    byte[] bytes = new byte[1024];
    int read;
    while ((read = inputStream.read(bytes)) != -1) {
      process.getOutputStream().write(bytes, 0, read);
    }
    inputStream.close();
    process.getOutputStream().flush();
    process.getOutputStream().close();
    process.waitFor();
    if (process.exitValue() == 0) {
      return true;
    }
    return false;
  } catch (Exception ex) {
    logger.log(Level.SEVERE, null, ex);
    return false;
  }
}
 
开发者ID:hopshadoop,项目名称:hopsworks,代码行数:28,代码来源:MySQLAccess.java

示例6: getContents

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
/**
 * Pulls photo contents in the form of a byte array form uploaded file.
 *
 * @param uploadedFile      PF uploaded file.
 * @return                  Photo in the form or a byte array.
 */
public byte[] getContents(final UploadedFile uploadedFile) {

	try {
		if (uploadedFile.getContents() != null && uploadedFile.getContents().length > 0) {
			return uploadedFile.getContents();
		}

		if (uploadedFile.getSize() > 0) {

			byte[] bytes = IOUtils.toByteArray(uploadedFile.getInputstream());

			if (bytes != null && bytes.length > 0) {
				return bytes;
			}
			else {
				log.error("Failed to read input stream for file named " + uploadedFile.getFileName());
			}
		}
		else
		{
			log.error("Failed to load photo, no content found.");
		}
	}
	catch (IOException e) {
		log.error("Failed to read file stream.", e);
		getAuditLogService().recordEvent(webUserSession.getWebUser(), e, WebEvent.EVENT_ERROR_OCCURRED);
	}

	return null;
}
 
开发者ID:heather92115,项目名称:photosOpen,代码行数:37,代码来源:PhotoListBean.java

示例7: handleFileUpload

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
public void handleFileUpload(FileUploadEvent event) {
    FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
    FacesMessage messageError = new FacesMessage("Error", "Não foi possível carregar o arquivo. Contate o administrador");

    UploadedFile uploadedFile = event.getFile();

    try {

        FileUtils.copyFile(uploadedFile, Propriedades.MAP_PASTAS.get("PASTA_WEB"));
        uploadedFile.getInputstream().close();
        FacesContext.getCurrentInstance().addMessage(null, message);

        System.out.println(Thread.currentThread().getId() + ": Arquivo <" + event.getFile().getFileName() + "> carregado com sucesso");

    } catch (IOException ex) {
        Logger.getLogger(FileUploadView.class.getName()).log(Level.SEVERE, null, ex);
        FacesContext.getCurrentInstance().addMessage(null, messageError);
    }
}
 
开发者ID:blastin,项目名称:Service,代码行数:20,代码来源:FileUploadView.java

示例8: handleFileUpload

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
/**
 * Handles file upload events.
 */
public void handleFileUpload(FileUploadEvent event) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ResourceBundle bundle = ResourceBundle.getBundle("messages",
            facesContext.getViewRoot().getLocale());

    UploadedFile file = event.getFile();
    if (file == null) {
        facesContext.addMessage(null, new FacesMessage(FacesMessage
            .SEVERITY_FATAL, bundle.getString("common.error"),
            bundle.getString("courses.create.uploadFail")));
        return;
    }

    files.add(file);
    logFileUploaded(file);
}
 
开发者ID:stefanoberdoerfer,项目名称:exmatrikulator,代码行数:20,代码来源:TmeController.java

示例9: uploadFiles

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
/**
 * Uploads all files to the temporary folder.
 *
 * @return List of successfully uploaded files.
 * @throws IOException If uploading an individual file failed.
 */
private List<File> uploadFiles() throws IOException {
    List<File> uploadedFiles = new ArrayList<>();
    for (UploadedFile file : files) {
        Path fp = Files.createTempFile("exmatrikulator", file.getFileName());
        Files.copy(file.getInputstream(), fp,
                StandardCopyOption.REPLACE_EXISTING);
        File savedFile = fp.toFile();
        uploadedFiles.add(savedFile);
        logFileSaved(savedFile);
    }

    return uploadedFiles;
}
 
开发者ID:stefanoberdoerfer,项目名称:exmatrikulator,代码行数:20,代码来源:TmeController.java

示例10: storeFilesOnServer

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
private List<File> storeFilesOnServer() {
    log.debug("storeFilesOnServer called");
    List<File> storedFiles = new ArrayList<>();
    for (UploadedFile f : files) {
        String filename = FilenameUtils.getBaseName(f.getFileName());
        String extension = FilenameUtils.getExtension(f.getFileName());
        try {
            Path fileP = Files.createTempFile(tempFileFolder, filename + "-", "." + extension);
            Files.copy(f.getInputstream(), fileP, StandardCopyOption.REPLACE_EXISTING);
            log.debug("Successfully saved File: " + filename + "." + extension);
            storedFiles.add(fileP.toFile());
        } catch (IOException ex) {
            log.error(ex);
            log.debug("Failed to save File: " + filename + "." + extension);
            FacesContext facesContext = FacesContext.getCurrentInstance();
            ResourceBundle bundle = ResourceBundle.getBundle("messages",
                    facesContext.getViewRoot().getLocale());
            facesContext.addMessage(null, new FacesMessage(FacesMessage
                    .SEVERITY_ERROR, bundle.getString("common.error"),
                    bundle.getString("courses.create.storeError")));
        }
    }
    return storedFiles;
}
 
开发者ID:stefanoberdoerfer,项目名称:exmatrikulator,代码行数:25,代码来源:StudentImportController.java

示例11: upload

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
public void upload(FileUploadEvent event) {
    final UploadedFile file = event.getFile();
    if (file == null) return;

    FacesMessage message;
    try {
        linksInspector.from(file.getInputstream());

        message = new FacesMessage("Leídas con éxito " + linksInspector.getLinks().size() + " URLs del fichero: " + file.getFileName(), "");

    } catch (IOException e) {
        message = new FacesMessage(SEVERITY_ERROR, "No se puede leer el fichero: " + file.getFileName(), e.getLocalizedMessage());
        e.printStackTrace();
    }

    FacesContext.getCurrentInstance().addMessage(null, message);
}
 
开发者ID:autentia,项目名称:urmiche,代码行数:18,代码来源:InspectUrlsView.java

示例12: handleFileUpload

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
@TsLoggedIn
public void handleFileUpload(FileUploadEvent event) throws Exception {
    UploadedFile item = event.getFile();
    if (item != null) {
        try {
            UploadedFileIterator uploadedFileIterator = new UploadedFileIterator(item, "csv", "txt", "xml");
            StringBuilder sb = new StringBuilder();
            int count = 0;
            FileInputStreamWrapper w = uploadedFileIterator.getNext();
            while (w != null) {
                createDataFile(w.getFileName(), w.getInputStream());
                if (sb.length() != 0) {
                    sb.append(", ");
                }
                sb.append(w.getFileName());
                w = uploadedFileIterator.getNext();
                count++;
            }

            if (sb.length() == 0) {
                messages.warn("The uploaded archive, '" + item.getFileName()
                        + "' file did not have any valid files.");
            } else {
                messages.info("Added " + count + " files.");
            }
        } catch (Exception e) {
            LOG.error("Error extracting zip file: " + e.toString());
            messages.error("Error extracting zip file: " + e.toString());
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(item.getInputstream());
        }
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:35,代码来源:FileUploadBean.java

示例13: save

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
/**
 * Saves the script in the database.
 */
public String save() {
    UploadedFile item = getFile();
    try {
        String fileName = item.getFileName();
        fileName = FilenameUtils.getBaseName(fileName) + "-" + UUID.randomUUID().toString() + "."
                + FilenameUtils.getExtension(fileName);
        File parent = new File("uploads");
        parent.mkdirs();
        File f = new File(parent, fileName);
        LOG.info("Writing file to " + f.getAbsolutePath());
        FileUtils.writeByteArrayToFile(f, item.getContents());
        messages.info("Wrote file to " + f.getAbsolutePath());
    } catch (Exception e) {
        messages.error(e.getMessage());
    }
    return null;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:21,代码来源:TestUploadBean.java

示例14: handleFileUpload

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
@TsLoggedIn
public void handleFileUpload(FileUploadEvent event) throws Exception {
    UploadedFile item = event.getFile();

    if (item != null) {
        try {
            UploadedFileIterator uploadedFileIterator = new UploadedFileIterator(item, "xml");
            StringBuilder sb = new StringBuilder();
            FileInputStreamWrapper w = uploadedFileIterator.getNext();
            while (w != null) {
                processScript(w.getInputStream(), w.getFileName());
                if (sb.length() != 0) {
                    sb.append(", ");
                }
                sb.append(w.getFileName());
                w = uploadedFileIterator.getNext();

            }
        } catch (Exception e) {
            LOG.error("Error extracting zip file: " + e.toString());
            messages.error("Error extracting zip file: " + e.toString());
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(item.getInputstream());
        }
    }
}
 
开发者ID:intuit,项目名称:Tank,代码行数:28,代码来源:TankXmlUploadBean.java

示例15: testGetFile_1

import org.primefaces.model.UploadedFile; //导入依赖的package包/类
/**
 * Run the UploadedFile getFile() method test.
 *
 * @throws Exception
 *
 * @generatedBy CodePro at 12/15/14 3:53 PM
 */
@Test
public void testGetFile_1()
    throws Exception {
    TestUploadBean fixture = new TestUploadBean();
    fixture.setFile(new DefaultUploadedFile());

    UploadedFile result = fixture.getFile();

    // An unexpected exception was thrown in user code while executing this test:
    //    java.lang.NoClassDefFoundError: com_cenqua_clover/CoverageRecorder
    //       at com.intuit.tank.script.TestUploadBean.setFile(TestUploadBean.java:42)
    assertNotNull(result);
}
 
开发者ID:intuit,项目名称:Tank,代码行数:21,代码来源:TestUploadBeanTest.java


注:本文中的org.primefaces.model.UploadedFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。