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


Java Part.getInputStream方法代码示例

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


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

示例1: _fileUpload

import javax.servlet.http.Part; //导入方法依赖的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: getPostMap

import javax.servlet.http.Part; //导入方法依赖的package包/类
public static Map<String, byte[]> getPostMap(HttpServletRequest request) throws IOException {
    Map<String, byte[]> map = new HashMap<>();
    Map<String, String[]> pm = request.getParameterMap();
    if (pm != null && pm.size() > 0) {
        for (Map.Entry<String, String[]> entry: pm.entrySet()) {
            String[] v = entry.getValue();
            if (v != null && v.length > 0) map.put(entry.getKey(), v[0].getBytes(StandardCharsets.UTF_8));
        }
    } else try {
        request.setAttribute("org.eclipse.jetty.multipartConfig", multipartConfigElement); // without that we get a IllegalStateException in getParts()
        final byte[] b = new byte[1024];
        for (Part part: request.getParts()) {
            String name = part.getName();
            InputStream is = part.getInputStream();
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int c;
            try {while ((c = is.read(b, 0, b.length)) > 0) {
                baos.write(b, 0, c);
            }} finally {is.close();}
            map.put(name, baos.toByteArray());
        }
    } catch (IOException | ServletException | IllegalStateException e) {
        Data.logger.debug("Parsing of POST multipart failed", e);
        throw new IOException(e.getMessage());
    }
    return map;
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:28,代码来源:RemoteAccess.java

示例3: getInputStream

import javax.servlet.http.Part; //导入方法依赖的package包/类
public InputStream getInputStream(SectionInfo info)
{
    Part file = getMultipartFile(info);
    if( file != null )
    {
        try
        {
            return file.getInputStream();
        }
        catch( IOException e )
        {
            SectionUtils.throwRuntime(e);
        }
    }
    return null;
}
 
开发者ID:equella,项目名称:Equella,代码行数:17,代码来源:AbstractFileUpload.java

示例4: doPost

import javax.servlet.http.Part; //导入方法依赖的package包/类
public void doPost(MCRServletJob job) throws Exception {
    HttpServletRequest req = job.getRequest();
    Collection<Part> parts = req.getParts();
    File uploadDir = new File(inputDir + "/upload"); 
    if (!uploadDir.exists()) uploadDir.mkdirs();
    byte[] buffer = new byte[8 * 1024];
    for (Part part : parts) {
    File uploadedFile = new File(uploadDir,getFileName(part));
    
    InputStream input = part.getInputStream();
    try {
      OutputStream output = new FileOutputStream(uploadedFile);
      try {
        int bytesRead;
        while ((bytesRead = input.read(buffer)) != -1) {
          output.write(buffer, 0, bytesRead);
        }
      } finally {
        output.close();
      }
    } finally {
      input.close();
    }
    LOGGER.info("saved csv-file " + uploadedFile);
    job.getResponse().sendRedirect("getScopusAuthorData?listName="+ uploadedFile);
    }
    
}
 
开发者ID:ETspielberg,项目名称:bibliometrics,代码行数:29,代码来源:CSVUploadServlet.java

示例5: processRequest

import javax.servlet.http.Part; //导入方法依赖的package包/类
/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");
    
    String templateName = request.getParameter("demo_name");
    Part filePart = request.getPart("demo_img");
    try{
        // String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString(); // MSIE fix.
        InputStream fileContent = filePart.getInputStream();
        System.out.println(templateName);
        File file = new File("uploads/"+templateName+".png");
        System.out.println(file.getAbsolutePath());
        OutputStream outputStream = new FileOutputStream(file);
        IOUtils.copy(fileContent, outputStream);
        outputStream.close();
        
        Thumbnails.of(new File("uploads/"+templateName+".png"))
        .size(500, 707)
        .outputFormat("PNG")
        .toFiles(Rename.NO_CHANGE);
        
    }catch(NullPointerException ex){
        System.out.println("null param");
    }
    
    response.getWriter().write("uploaded lmao");  
    
    System.out.println("fking shit");
    response.sendRedirect("init.jsp?req="+templateName);
}
 
开发者ID:lupino22,项目名称:kronometer,代码行数:41,代码来源:UploadFile.java

示例6: parseMultipart

import javax.servlet.http.Part; //导入方法依赖的package包/类
/**
 * Parses the content of the input as a series of multipart binary encoded
 * data;
 * 
 * @param paramsClass
 * @return
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ServletException
 * @throws IOException
 */
private TParams parseMultipart(RestrictionAspect<TParams> aspect) throws Exception {
	String encoding = request.getCharacterEncoding();
	Charset charset = Charset.forName(
			encoding == null || encoding.isEmpty()
					? "UTF-8"
					: encoding);
	TParams target = aspect.dataType.newInstance();
	for (RestrictionAspectField field : aspect) {
		try {
			Part part = request.getPart(field.name);
			if (part != null) {
				if (UploadedFile.class.isAssignableFrom(field.getDataType())) {
					field.setValue(target, new UploadedFile(part));
				} else {
					byte[] bytes = new byte[(int) part.getSize()];
					InputStream is = part.getInputStream();
					is.read(bytes);
					is.close();
					String txt = new String(bytes, charset);
					field.setValue(target, txt);
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(
					String.join(
							" ",
							"Unable to set value to field",
							aspect.dataType.getSimpleName() + "." + field.name,
							"(" + field.getDataType() + ")",
							":",
							e.getMessage()));
		}
	}
	return target;
}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:47,代码来源:UsecaseExecutionServlet.java

示例7: attachFile

import javax.servlet.http.Part; //导入方法依赖的package包/类
private void attachFile(String boundary, Iterator<Entry<String, Part>> uploadsIterator) {
  if (!uploadsIterator.hasNext()) {
    request.write(boundaryEndInfo(boundary));
    request.end();
    return;
  }

  Entry<String, Part> entry = uploadsIterator.next();
  // do not use part.getName() to get parameter name
  // because pojo consumer not easy to set name to part
  String name = entry.getKey();
  Part part = entry.getValue();
  String filename = part.getSubmittedFileName();

  InputStreamToReadStream fileStream = null;
  try {
    fileStream = new InputStreamToReadStream(vertx, part.getInputStream());
  } catch (IOException e) {
    asyncResp.consumerFail(e);
    return;
  }

  InputStreamToReadStream finalFileStream = fileStream;
  fileStream.exceptionHandler(e -> {
    LOGGER.debug("Failed to sending file [{}:{}].", name, filename, e);
    IOUtils.closeQuietly(finalFileStream.getInputStream());
    asyncResp.consumerFail(e);
  });
  fileStream.endHandler(V -> {
    LOGGER.debug("finish sending file [{}:{}].", name, filename);
    IOUtils.closeQuietly(finalFileStream.getInputStream());

    attachFile(boundary, uploadsIterator);
  });

  Buffer fileHeader = fileBoundaryInfo(boundary, name, part);
  request.write(fileHeader);
  Pump.pump(fileStream, request).start();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:40,代码来源:RestClientRequestImpl.java

示例8: initialSync

import javax.servlet.http.Part; //导入方法依赖的package包/类
void initialSync(HttpServletRequest request, HttpServletResponse response, String workspaceRoot, String workspaceSaveDir) throws IOException, ServletException {
	// Expected: one part containing zip
	Part part = request.getParts().iterator().next();
	try (final InputStream inputStream = part.getInputStream()) {
		syncWorkspace(inputStream, new File(workspaceSaveDir));
		response.getWriter().append(workspaceRoot);
		response.setStatus(HttpServletResponse.SC_CREATED);
	} catch (NoSuchElementException ePart) {
		response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
	}
}
 
开发者ID:SAP,项目名称:cloud-language-servers-container,代码行数:12,代码来源:WSSynchronization.java

示例9: handleMultipartForm

import javax.servlet.http.Part; //导入方法依赖的package包/类
private void handleMultipartForm(HttpServletRequest req, String frontier, FrontierMethod frontierMethod,
                                 Map paramsMap) throws FrontierCallException{

    try {

        Part uploadsPart = req.getPart("$uploads");
        Scanner uploadsScanner = new Scanner(uploadsPart.getInputStream(),"UTF-8");
        StringBuilder uploadsJSONStringBuilder = new StringBuilder();
        while (uploadsScanner.hasNextLine())
            uploadsJSONStringBuilder.append(uploadsScanner.nextLine());

        Part argsPart = req.getPart("$args");
        Scanner argsScanner = new Scanner(argsPart.getInputStream(),"UTF-8");
        StringBuilder argsJSONStringBuilder = new StringBuilder();
        while (argsScanner.hasNextLine())
            argsJSONStringBuilder.append(argsScanner.nextLine());

        Gson gson = new Gson();
        Map<String,Object> uploadsMap = gson.fromJson(uploadsJSONStringBuilder.toString(),Map.class);
        Map<String,Object> argsMaps = gson.fromJson(argsJSONStringBuilder.toString(),Map.class);
        MethodParam methodParams[] = frontierMethod.getParams();

        for(MethodParam methodParam : methodParams)
            paramsMap.put(methodParam.getName(),getParamValue(frontier,frontierMethod,methodParam,uploadsMap,argsMaps,req));


    }catch (IOException | ServletException ex){

        throw new FrontierCallException(frontier,frontierMethod.getName(),"Failed to read parameters of frontier call with files attached",ex);

    }

}
 
开发者ID:Emerjoin,项目名称:Hi-Framework,代码行数:34,代码来源:FrontiersReqHandler.java

示例10: getBuffer

import javax.servlet.http.Part; //导入方法依赖的package包/类
public static byte[] getBuffer(Part file) throws IOException {

        InputStream fileInStream = file.getInputStream();

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream(1024);
        byte[] bytes = new byte[512];

        int readBytes;
        while ((readBytes = fileInStream.read(bytes)) > 0) {
            outputStream.write(bytes, 0, readBytes);
        }

        return outputStream.toByteArray();
    }
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:PartHandler.java

示例11: getInputStream

import javax.servlet.http.Part; //导入方法依赖的package包/类
@Override
public InputStream getInputStream(final String name) {
    try {
        final Part part = values.get(name);
        return part == null ? null : part.getInputStream();
    } catch (final IOException ex) {
        throw ExceptionUtils.toWebAppException(ex);
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:10,代码来源:MinijaxMultipartForm.java


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