List of usage examples for javax.servlet.http Part getInputStream
public InputStream getInputStream() throws IOException;
From source file:com.cloudera.oryx.app.serving.AbstractOryxResource.java
protected static InputStream maybeDecompress(Part item) throws IOException { InputStream in = item.getInputStream(); String contentType = item.getContentType(); if (contentType != null) { switch (contentType) { case "application/zip": in = new ZipInputStream(in); break; case "application/gzip": case "application/x-gzip": in = new GZIPInputStream(in); break; }// w ww . j av a 2 s.c o m } return in; }
From source file:com.playright.servlet.DataController.java
private static CoverageData getCoverageDateFromRequest(HttpServletRequest request) throws ServletException { CoverageData cd = new CoverageData(); try {/*from ww w . j a v a2 s.c o m*/ if (!"".equalsIgnoreCase(request.getParameter("id")) && request.getParameter("id") != null) { cd.setId(Integer.parseInt(request.getParameter("id"))); } SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); java.util.Date ud = sdf.parse(request.getParameter("newsDate")); cd.setNewsDate(new java.sql.Date(ud.getTime())); cd.setNewspaper(request.getParameter("newspaper")); cd.setHeadline(request.getParameter("headline")); cd.setLanguage(request.getParameter("language")); cd.setEdition(request.getParameter("edition")); cd.setSupplement(request.getParameter("supplement")); cd.setSource(request.getParameter("source")); if (!"".equalsIgnoreCase(request.getParameter("pageNo")) && request.getParameter("pageNo") != null) { cd.setPageNo(Integer.parseInt(request.getParameter("pageNo"))); } if (!"".equalsIgnoreCase(request.getParameter("height")) && request.getParameter("height") != null) { cd.setHeight(Integer.parseInt(request.getParameter("height"))); } if (!"".equalsIgnoreCase(request.getParameter("width")) && request.getParameter("width") != null) { cd.setWidth(Integer.parseInt(request.getParameter("width"))); } if (!"".equalsIgnoreCase(request.getParameter("totalArticleSize")) && request.getParameter("totalArticleSize") != null) { cd.setTotalArticleSize(Integer.parseInt(request.getParameter("totalArticleSize"))); } if (!"".equalsIgnoreCase(request.getParameter("circulationFigure")) && request.getParameter("circulationFigure") != null) { cd.setCirculationFigure(Integer.parseInt(request.getParameter("circulationFigure"))); } if (!"".equalsIgnoreCase(request.getParameter("journalistFactor")) && request.getParameter("journalistFactor") != null) { cd.setJournalistFactor(Integer.parseInt(request.getParameter("journalistFactor"))); } if (!"".equalsIgnoreCase(request.getParameter("quantitativeAve")) && request.getParameter("quantitativeAve") != null) { cd.setQuantitativeAve(new BigDecimal(request.getParameter("quantitativeAve"))); } if (!"".equalsIgnoreCase(request.getParameter("imageExists")) && request.getParameter("imageExists") != null) { cd.setImageExists(request.getParameter("imageExists")); } Blob b = null; String fileName = ""; String contentType = ""; try { Part filePart = request.getPart("image"); InputStream fileContent = filePart.getInputStream(); byte[] bytes = IOUtils.toByteArray(fileContent); b = new SerialBlob(bytes); fileName = filePart.getSubmittedFileName(); contentType = filePart.getContentType(); } catch (IOException ex) { Logger.getLogger(DataController.class.getName()).log(Level.SEVERE, null, ex); } if (b != null && b.length() != 0) { cd.setImageBlob(b); cd.setImageFileName(fileName); cd.setImageType(contentType); } } catch (ParseException ex) { Logger.getLogger(DataController.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(DataController.class.getName()).log(Level.SEVERE, null, ex); } return cd; }
From source file:gob.dp.simco.comun.FunctionUtil.java
public static String uploadArchive(Part fil) { String nameArchive = getFilename(fil); String extencion = getFileExtension(getFilename(fil)); if (StringUtils.isNoneBlank(nameArchive)) { String formato = RandomStringUtils.random(32, 0, 20, true, true, "qw32rfHIJk9iQ8Ud7h0X".toCharArray()); String ruta = formato + extencion; File file = new File(ConstantesUtil.FILE_SYSTEM + ruta); try (InputStream input = fil.getInputStream()) { Files.copy(input, file.toPath()); } catch (IOException ex) { log.error(ex);//from w w w. j a va 2s . c o m } return ruta; } return null; }
From source file:org.helm.rest.AjaxTool.java
static String getValue(Part part) throws IOException { if (part == null) { return null; }/* w w w . ja va2 s . co m*/ BufferedReader reader = new BufferedReader(new InputStreamReader(part.getInputStream(), "UTF-8")); StringBuilder value = new StringBuilder(); char[] buffer = new char[1024]; for (int length = 0; (length = reader.read(buffer)) > 0;) { value.append(buffer, 0, length); } return value.toString(); }
From source file:org.sherlok.FileBased.java
/** * PUTs (writes) this resource to disk./* w w w. j a v a 2s .co m*/ * * @param path * the path where to write this resource to * @param part * holds the resource file itself */ public static void putResource(String path, Part part) throws SherlokException { validateArgument(!path.contains(".."), "path cannot contain '..'"); validateArgument(part.getSize() < MAX_UPLOAD_SIZE, "file too large, max allowed " + MAX_UPLOAD_SIZE + " bytes"); validateArgument(part.getSize() > 0, "file is empty"); File outFile = new File(RUTA_RESOURCES_PATH, path); outFile.getParentFile().mkdirs(); try { FileUtils.copyInputStreamToFile(part.getInputStream(), outFile); } catch (IOException e) { new SherlokException("could not upload file to", path); } }
From source file:com.sishuok.chapter4.web.servlet.UploadServlet3.java
@Override protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { Part part = req.getPart("file1"); InputStream is = part.getInputStream(); System.out.println(IOUtils.toString(is)); is.close();//from w w w . ja v a2s . c o m /** * jetty * fileSizeThreshold * 1?content-disposition??? * 2??byte array input stream * 3?[2]?fileSizeThreshold * * 4?? * 4.1?@MultipartConfiglocation? * 4.2?Part.write ? * */ }
From source file:com.daniel.processimage.ImageManager.java
public byte[] readImage(Part file) throws FileNotFoundException, IOException { InputStream is = file.getInputStream(); BufferedImage bufferedImage = ImageIO.read(is); ByteArrayOutputStream byteMas = new ByteArrayOutputStream(); ImageIO.write(bufferedImage, "png", byteMas); byteMas.flush();/* w w w . ja v a 2s . c o m*/ byte[] imageInBytes = byteMas.toByteArray(); byteMas.close(); return imageInBytes; }
From source file:CiudadesApp.Modelo.Parameter.GuardarCiudades_Parameter.java
public GuardarCiudades_Parameter(HttpServletRequest request) { try {//from w w w .j ava2 s .c o m request.setCharacterEncoding("UTF-8"); nombreCiudad = (String) request.getParameter("nombreCiudad"); descripcion = (String) request.getParameter("descripcion"); Part filePart = request.getPart("fileName"); InputStream in = filePart.getInputStream(); foto = IOUtils.toByteArray(in); } catch (UnsupportedEncodingException ex) { Logger.getLogger(GuardarCiudades_Parameter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GuardarCiudades_Parameter.class.getName()).log(Level.SEVERE, null, ex); } catch (ServletException ex) { Logger.getLogger(GuardarCiudades_Parameter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:io.github.jass2125.pesoa.jpa.core.servlets.RegisterImageServlet.java
public byte[] getImage(HttpServletRequest req) throws IOException, ServletException { List<Part> parts = (List<Part>) req.getParts(); for (Part it : parts) { if (it.getName().equals("img")) { InputStream stream = it.getInputStream(); return IOUtils.toByteArray(stream); }/*ww w . ja v a2s . co m*/ } return null; }
From source file:com.vigglet.oei.technician.UploadProfilePhoto.java
@Override protected void preProcessRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException { try {//from ww w . j a va 2 s .com User user = getUser(req); for (Part part : req.getParts()) { byte[] b = IOUtils.toByteArray(part.getInputStream()); String fileName = extractFileName(part); File file = new File(Content.FILE_LOCATION + "/" + fileName); FileOutputStream fos = new FileOutputStream(file); ByteArrayInputStream bais = new ByteArrayInputStream(b); IOUtils.copy(bais, fos); fos.flush(); fos.close(); bais.close(); Content content = new Content(); content.setCompany(user.getCompany()); content.setUser(user.getId()); content.setName(file.getName()); content.setFilesize((int) file.length()); content.setLocation(file.getAbsolutePath()); ContentUtil.getInstance().insertOrUpdate(content); } } catch (ServletException ex) { logger.log(Level.SEVERE, null, ex); } }