本文整理汇总了Java中org.richfaces.model.UploadedFile.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java UploadedFile.getInputStream方法的具体用法?Java UploadedFile.getInputStream怎么用?Java UploadedFile.getInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.richfaces.model.UploadedFile
的用法示例。
在下文中一共展示了UploadedFile.getInputStream方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyUploadedFile
import org.richfaces.model.UploadedFile; //导入方法依赖的package包/类
/**
* Copy uploaded file to byte array.
*
* @param uploadedFile
* @return byte array
* @throws IOException
*/
public static byte[] copyUploadedFile(UploadedFile uploadedFile) throws IOException {
InputStream in = uploadedFile.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
} finally {
out.close();
in.close();
}
return out.toByteArray();
}
示例2: updateCert
import org.richfaces.model.UploadedFile; //导入方法依赖的package包/类
private void updateCert(UploadedFile item) {
InputStream is = null;
OutputStream os = null;
try {
is = item.getInputStream();
os = new FileOutputStream(getTempCertDir() + this.uploadMarker);
BufferedOutputStream bos = new BufferedOutputStream(os);
IOUtils.copy(is, bos);
bos.flush();
} catch (IOException ex) {
log.error("Failed to upload certicicate", ex);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
示例3: updateTrsutStoreCert
import org.richfaces.model.UploadedFile; //导入方法依赖的package包/类
private void updateTrsutStoreCert(UploadedFile item) {
InputStream is = null;
try {
is = item.getInputStream();
String certificate = IOUtils.toString(is);
this.trustStoreCertificateUploadMarker.setCertificate(certificate);
this.trustStoreCertificateUploadMarker.setAddedAt(new Date());
this.trustStoreCertificateUploadMarker.setAddedBy(currentPerson.getDn());
} catch (IOException ex) {
log.error("Failed to upload key", ex);
} finally {
IOUtils.closeQuietly(is);
}
}
示例4: updateKey
import org.richfaces.model.UploadedFile; //导入方法依赖的package包/类
private void updateKey(UploadedFile item) {
InputStream is = null;
OutputStream os = null;
try {
is = item.getInputStream();
os = new FileOutputStream(getTempCertDir() + this.uploadMarker.replace("crt", "key"));
BufferedOutputStream bos = new BufferedOutputStream(os);
IOUtils.copy(is, bos);
bos.flush();
} catch (IOException ex) {
log.error("Failed to upload key", ex);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
示例5: copyUploadedFile
import org.richfaces.model.UploadedFile; //导入方法依赖的package包/类
/**
* Copy uploaded file to byte array.
*
* @param uploadedFile
* @return byte array
* @throws IOException
*/
public byte[] copyUploadedFile(UploadedFile uploadedFile) throws IOException {
InputStream in = uploadedFile.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
} finally {
out.close();
in.close();
}
return out.toByteArray();
}
示例6: saveFile
import org.richfaces.model.UploadedFile; //导入方法依赖的package包/类
public String saveFile( UploadedFile file ) throws IOException
{
String name = file.getName().replace(" ", "_");
//ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
File result = new File( cm.getImportPath() + "//" + name );
FileOutputStream output = new FileOutputStream(result);
InputStream input = file.getInputStream();
IOUtils.copy( input, output );
input.close( );
output.close( );
return name;
}
示例7: listener
import org.richfaces.model.UploadedFile; //导入方法依赖的package包/类
public void listener(FileUploadEvent event) throws Exception {
final UploadedFile uploadedFile = event.getUploadedFile();
if (uploadedFile.getFileExtension().compareToIgnoreCase("zip")!=0 ) {
error("Only files ended with '.zip' are accepted");
return;
}
final Path folder = Paths.get(ConstantesAplicacao.DIR_BASE_JNLP);
String filename = FilenameUtils.getBaseName(uploadedFile.getName());
String extension = FilenameUtils.getExtension(uploadedFile.getName());
Path tempPath = Files.createTempFile(folder, filename, "." + extension);
try (InputStream input = uploadedFile.getInputStream()) {
Files.copy(input, tempPath, StandardCopyOption.REPLACE_EXISTING);
}
if(FileUtils.extractZip(tempPath.toFile(), tempPath.toFile().getParentFile())){
String currentVersion = uploadedFile.getName().substring(0, uploadedFile.getName().length()-4);
StringBuilder sb = new StringBuilder();
if(archiveInfo.existsFile()){
// pegando as duas primeiras linhas do arquivo
String infoUltimo = archiveInfo.readLine();
sb.append("Último upload");
sb.append(infoUltimo.substring(infoUltimo.indexOf(":")));
sb.append("\n");
infoUltimo = archiveInfo.readLine();
sb.append("Última versão");
sb.append(infoUltimo.substring(infoUltimo.indexOf(":")));
sb.append("\n");
archiveInfo.closeFileReader();
archiveInfo.deleteFile();
}else{
sb.append("Último upload: Nunca\n");
sb.append("Última versão: Nenhuma\n");
}
archiveInfo.openAppendAndClose("Upload atual em: "+new Date());
archiveInfo.openAppendAndClose("Versão atual: "+currentVersion);
archiveInfo.openAppendAndClose("-----------------------------------");
archiveInfo.openAppendAndClose(sb.toString());
}
files.add(uploadedFile);
uploadsAvailable--;
}