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


Java MultipartFile.getInputStream方法代码示例

本文整理汇总了Java中org.springframework.web.multipart.MultipartFile.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java MultipartFile.getInputStream方法的具体用法?Java MultipartFile.getInputStream怎么用?Java MultipartFile.getInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.multipart.MultipartFile的用法示例。


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

示例1: _fileUpload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
private String _fileUpload(MultipartFile file1, Part file2) {
  try (InputStream is1 = file1.getInputStream(); InputStream is2 = file2.getInputStream()) {
    String content1 = IOUtils.toString(is1);
    String content2 = IOUtils.toString(is2);
    return String.format("%s:%s:%s\n"
        + "%s:%s:%s",
        file1.getOriginalFilename(),
        file1.getContentType(),
        content1,
        file2.getSubmittedFileName(),
        file2.getContentType(),
        content2);
  } catch (IOException e) {
    throw new IllegalArgumentException(e);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:17,代码来源:CodeFirstSpringmvc.java

示例2: getBody

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@Override
public InputStream getBody() throws IOException {
	if (this.multipartRequest instanceof StandardMultipartHttpServletRequest) {
		try {
			return this.multipartRequest.getPart(this.partName).getInputStream();
		}
		catch (Exception ex) {
			throw new MultipartException("Could not parse multipart servlet request", ex);
		}
	}
	else {
		MultipartFile file = this.multipartRequest.getFile(this.partName);
		if (file != null) {
			return file.getInputStream();
		}
		else {
			String paramValue = this.multipartRequest.getParameter(this.partName);
			return new ByteArrayInputStream(paramValue.getBytes(FORM_CHARSET));
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:RequestPartServletServerHttpRequest.java

示例3: uploadRatingFromFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@Override
public int uploadRatingFromFile(MultipartFile inputFile, Integer dayNumber) throws IOException {
    logger.info("Uploading rating from file for day {}", dayNumber);
    Day day = dayRepository.findOne(dayNumber);
    int rowCounter = 0;
    logger.info("Processing file {}", inputFile.getOriginalFilename());
    Scanner scanner = new Scanner(inputFile.getInputStream());
    List<String> params = Arrays.asList(scanner.nextLine().split(","));
    while (scanner.hasNext()) {
        String row = scanner.nextLine();
        List<String> values = Arrays.asList(row.split(",", -1));
        logger.info(values.toString());
        String name = values.get(params.indexOf("Nome"));
        String surname = values.get(params.indexOf("Cognome"));
        Rating rating = ratingRepository.findByGiornataAndGiocatore(
                day,
                playerService.getByNameAndSurname(name, surname));
        rating.setVoto(Float.valueOf(values.get(params.indexOf("Voto"))));
        ratingRepository.save(rating);
        rowCounter += 1;
    }
    scanner.close();
    day.setCalcolabile(true);
    dayRepository.save(day);
    return rowCounter;
}
 
开发者ID:atifovac,项目名称:FantaParrocchie,代码行数:27,代码来源:DBDataLoaderServiceImpl.java

示例4: uploadExcel

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value="uploadexcle",method={RequestMethod.GET,RequestMethod.POST})
public  String  uploadExcel(HttpServletRequest request, Model model) throws Exception {
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    InputStream in =null;
    List<List<Object>> list = null;
    MultipartFile file = multipartRequest.getFile("upfile");
    if(file.isEmpty()){
        throw new Exception("文件不存在!");
    }
    in = file.getInputStream();
    list = teacherService.getListByExcel(in,file.getOriginalFilename());
    in.close();
    model.addAttribute("list",list);
    return "admin/teacher/upload";
}
 
开发者ID:junrui-zhao,项目名称:Educational-Management-System,代码行数:16,代码来源:TeacherTableController.java

示例5: buildAvatarHttpEntity

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
public static HttpEntity<Resource> buildAvatarHttpEntity(MultipartFile multipartFile) throws IOException {
    // result headers
    HttpHeaders headers = new HttpHeaders();

    // 'Content-Type' header
    String contentType = multipartFile.getContentType();
    if (StringUtils.isNotBlank(contentType)) {
        headers.setContentType(MediaType.valueOf(contentType));
    }

    // 'Content-Length' header
    long contentLength = multipartFile.getSize();
    if (contentLength >= 0) {
        headers.setContentLength(contentLength);
    }

    // File name header
    String fileName = multipartFile.getOriginalFilename();
    headers.set(XM_HEADER_CONTENT_NAME, fileName);

    Resource resource = new InputStreamResource(multipartFile.getInputStream());
    return new HttpEntity<>(resource, headers);
}
 
开发者ID:xm-online,项目名称:xm-ms-entity,代码行数:24,代码来源:XmHttpEntityUtils.java

示例6: upload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@PostMapping("/test/upload/handler") 
public String upload(@RequestParam("file") MultipartFile file) throws IllegalStateException, IOException {
	String destFile = new File(".").getCanonicalPath() + File.separator + file.getOriginalFilename();
	InputStream in = file.getInputStream();
	OutputStream out = new FileOutputStream(new File(destFile));
	int read = 0;
	byte[] bytes = new byte[1024];
	while((read = in.read(bytes)) != -1) {
		out.write(bytes, 0, read);
	}
	out.flush();
	out.close();
	return file.getOriginalFilename();
}
 
开发者ID:bndynet,项目名称:web-framework-for-java,代码行数:15,代码来源:HomeController.java

示例7: uploadFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public View uploadFile(@RequestParam("file") MultipartFile file) {
	try {
		InputStream input = file.getInputStream();
		this.messageManagementService.importFromExcel(input);
	} catch (Exception e) {
		LOG.error("error on uploading messages", e);
		return new RedirectView("../files.html?uploadSuccess=no&message=" + e.getMessage().toString());
	}
	return new RedirectView("../files.html?uploadSuccess=yes");
}
 
开发者ID:namics,项目名称:spring-i18n-support,代码行数:12,代码来源:FileController.java

示例8: inputStreamSupplier

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * Supplier for file input
 *
 * @param file the attachment
 * @return a supplier that wraps the attachment's input stream retrieval
 */
Supplier<InputStream> inputStreamSupplier(MultipartFile file) {
	return () -> {
		try {
			return file.getInputStream();
		} catch (IOException ex) {
			throw new UncheckedIOException(ex);
		}
	};
}
 
开发者ID:CMSgov,项目名称:qpp-conversion-tool,代码行数:16,代码来源:QrdaControllerV1.java

示例9: upload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@ResponseStatus(HttpStatus.OK)
   @RequestMapping(value = "/upload/tagCircle/{exerciseId}",
   				method = RequestMethod.POST)
   public @ResponseBody ResponseEntity<Void> upload(@RequestParam("file") MultipartFile file, @PathVariable Long exerciseId ) throws URISyntaxException, BuenOjoCSVParserException {
	
	if (exerciseId == null) return ResponseEntity.badRequest().headers(HeaderUtil.createBadRequestHeaderAlert("Exercise ID null or invalid")).build();
	
	List<TagCircle> circles = null;
	TagCircleCSVParser parser = null ;
	try {
		parser = new TagCircleCSVParser(file.getInputStream());
		circles = parser.parse();
		
		if (circles == null) {
			return ResponseEntity.badRequest().headers(HeaderUtil.createBadCSVRequestAlert(file.getName())).build();
		}else if (circles.isEmpty()) {
			return ResponseEntity.badRequest().headers(HeaderUtil.createBadRequestHeaderAlert("File "+ file.getName()+" is empty")).build();
		}
		
	} catch (IOException e) {

		return ResponseEntity.badRequest().headers(HeaderUtil.createBadCSVRequestAlert(file.getName())).build();
		
	}
			
	return ResponseEntity.ok().headers(HeaderUtil.createEntityCreationAlert("TagCircle", new Integer(circles.size()).toString())).build();
	
	
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:30,代码来源:TagCircleUploadResource.java

示例10: uploadTagCircles

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
   * POST  /tagCircles -> Create a new tagCircle.
   * @throws BuenOjoCSVParserException 
   */
  @RequestMapping(value = "/tagCircle/upload/{exercise_id}",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<Void> uploadTagCircles(@PathVariable("exercise_id")Long id, @RequestParam("file") MultipartFile csvMetadataFile) throws URISyntaxException, IOException, BuenOjoCSVParserException{
  	if (id == null)
  		return ResponseEntity.badRequest().headers(HeaderUtil.createBadRequestHeaderAlert("falta el parámetro ID de ejercicio")).body(null);
  	if (csvMetadataFile == null)
  		return ResponseEntity.badRequest().headers(HeaderUtil.createBadRequestHeaderAlert("falta el parámetro CSV")).body(null);
  	
  	TagCircleCSVParser parser = new TagCircleCSVParser(csvMetadataFile.getInputStream());
  	
  	List<TagCircle> circles = parser.parse();
  	
  	ImageCompletionExercise exercise =  exerciseRepository.findOne(id);
  	
  	if (exercise == null) {
  		return ResponseEntity.badRequest().headers(HeaderUtil.createBadRequestHeaderAlert("No existe el ejercicio "+id)).body(null);
  		
  	}
  	for (TagCircle tagCircle : circles) {
	tagCircle.setImageCompletionExercise(exercise);
}
  	tagCircleRepository.save(circles);
  	exercise.setTagCircles(new HashSet<TagCircle>(circles));
  	
  	exerciseRepository.saveAndFlush(exercise);

  	return ResponseEntity.ok().headers(HeaderUtil.createEntitiesCreationAlert("tagCircle", new Integer(circles.size()).toString())).build(); 
  }
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:35,代码来源:TagCircleResource.java

示例11: addXInfoToSegments

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@PostMapping(value="/segments/graphs/{graph}/versions/{version}/xinfos")
    @ResponseStatus(HttpStatus.CREATED)
    public String addXInfoToSegments(@PathVariable String graph,
                                     @PathVariable String version,
//                                     InputStream stream,
                                     @RequestParam(value = "file") MultipartFile file) throws IOException, XInfoNotSupportedException, GraphImportException, GraphNotExistsException, GraphStorageException {
//        this.service.streamBaseSegmentXInfos(graph,this.getCurrentVersion(graph,version),stream);
    	if (!file.isEmpty()) {
    		log.info("Parsing file " + file.getName() + " with " + file.getSize() + " Bytes");
            InputStream inputStream = file.getInputStream();
            this.service.streamBaseSegmentXInfos(graph,this.getCurrentVersion(graph,version),inputStream);
        }
        return null;
    }
 
开发者ID:graphium-project,项目名称:graphium,代码行数:15,代码来源:GraphXInfoController.java

示例12: addXInfosToConnections

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@PostMapping(value="/connections/graphs/{graph}/versions/{version}/xinfos")
public String addXInfosToConnections(@PathVariable String graph,
                                     @PathVariable String version,
                                     @RequestParam(value = "file") MultipartFile file) throws XInfoNotSupportedException,
        GraphImportException, GraphStorageException, GraphNotExistsException, IOException {
    if (!file.isEmpty()) {
        log.info("Parsing file " + file.getName() + " with " + file.getSize() + " Bytes");
        InputStream inputStream = file.getInputStream();
        this.service.streamBaseConnectionXInfos(graph,this.getCurrentVersion(graph,version),inputStream);
    }
    return null;
}
 
开发者ID:graphium-project,项目名称:graphium,代码行数:13,代码来源:GraphXInfoController.java

示例13: upload

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
/**
 * Uploads a file.
 *
 * <p>
 *     File should be uploaded as multipart/form-data.
 * </p>
 * @param uploadFile Provided file with metadata
 * @param index Should be the content of file indexed
 * @return Reference to a stored file
 */
@ApiOperation(value = "Uploads a file and returns the reference to the stored file.",
        notes = "File should be uploaded as multipart/form-data.",
        response = FileRef.class)
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Successful response", response = FileRef.class)})
@RequestMapping(value = "/", method = RequestMethod.POST)
public FileRef upload(@ApiParam(value = "Provided file with metadata", required = true)
                          @RequestParam("file") MultipartFile uploadFile,
                      @ApiParam(value = "Should be the content of file indexed")
                          @RequestParam(name = "index", defaultValue = "false") Boolean index) {

    try (InputStream stream = uploadFile.getInputStream()) {
        String filename = uploadFile.getOriginalFilename();

        if (filename != null) {
            filename = FilenameUtils.getName(filename);
        }

        String contentType = uploadFile.getContentType();

        return repository.create(stream, filename, contentType, index);

    } catch (IOException e) {
        throw new BadArgument("file");
    }
}
 
开发者ID:LIBCAS,项目名称:ARCLib,代码行数:37,代码来源:FileApi.java

示例14: parseFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@FileResolver
public void parseFile(UploadFile uploadFile, Map<String, Object> parameter) throws Exception {

		MultipartFile file = uploadFile.getMultipartFile();
		String name = file.getOriginalFilename();
		if (name.endsWith(".xlsx") || name.endsWith(".xls")) {
			InputStream input = file.getInputStream();
			try {
				String bigData = (String)parameter.get("bigData");
				String startRow = (String)parameter.get("startRow");
				String endRow = (String)parameter.get("endRow");
				String excelModelId = (String)parameter.get("excelModelId");
				String fileExtension = null;
				if (name.endsWith(".xlsx")) {
					fileExtension = "xlsx";
				} else if (name.endsWith(".xls")) {
					fileExtension = "xls";
				}
				boolean supportBigData = false;
				if (StringUtils.isNotEmpty(bigData) && bigData.equals("true")) {
					supportBigData = true;
				}
				ImportContext.setParameters(parameter);
				IExcelParser excelParser = (IExcelParser) getExcelParser(fileExtension, supportBigData);
				ExcelDataWrapper excelDataWrapper = excelParser.parse(excelModelId, Integer.valueOf(startRow), Integer.valueOf(endRow), input);
				excelParser.put2Cache(excelDataWrapper);
			} finally {
				IOUtils.closeQuietly(input);
			}
		}
}
 
开发者ID:bsteker,项目名称:bdf2,代码行数:32,代码来源:ExcelImportResolver.java

示例15: uploadFile

import org.springframework.web.multipart.MultipartFile; //导入方法依赖的package包/类
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public ResponseEntity uploadFile(@RequestParam("file") MultipartFile file, UriComponentsBuilder builder) throws IOException {
	InputStream input = file.getInputStream();
	this.messageManagementService.importFromExcel(input);
	HttpHeaders headers = new HttpHeaders();
	headers.setLocation(builder.path("/upload.html").build().toUri());
	return new ResponseEntity<>("/admin/", headers, HttpStatus.OK);
}
 
开发者ID:namics,项目名称:spring-i18n-support,代码行数:9,代码来源:MessageSourceDataController.java


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