List of usage examples for java.io BufferedOutputStream write
@Override public synchronized void write(int b) throws IOException
From source file:org.openmrs.module.bannerprototype.web.controller.bannerprototypeManageController.java
@RequestMapping(value = "/module/bannerprototype/upload", method = RequestMethod.POST) public @ResponseBody String handleFileUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) throws IOException { String path = new ClassPathResource("taggers/").getURL().getPath(); if (!file.isEmpty()) { try {//from w w w .j av a 2s . c o m byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File(path + name))); stream.write(bytes); stream.close(); return "You successfully uploaded " + name + "!\n<a href=manage.form>back</a>"; } catch (FileNotFoundException ex) { ex.printStackTrace(); return "ERROR: Please name your file"; } catch (Exception e) { e.printStackTrace(); return "You failed to upload " + name + " => " + e.getMessage(); } } else { return "You failed to upload " + name + " because the file was empty."; } }
From source file:org.pegadi.webapp.view.FileView.java
protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response) throws IOException { // get the file from the map File file = (File) map.get("file"); // check if it exists if (file == null || !file.exists() || !file.canRead()) { log.warn("Error reading: " + file); try {//from ww w .j av a 2 s . com response.sendError(404); } catch (IOException e) { log.error("Could not write to response", e); } return; } // give some info in the response response.setContentType(getServletContext().getMimeType(file.getAbsolutePath())); // files does not change so often, allow three days caching response.setHeader("Cache-Control", "max-age=259200"); response.setContentLength((int) file.length()); // start writing to the response BufferedOutputStream out = null; BufferedInputStream in = null; try { out = new BufferedOutputStream(response.getOutputStream()); in = new BufferedInputStream(new FileInputStream(file)); int c = in.read(); while (c != -1) { out.write(c); c = in.read(); } } finally { if (in != null) { in.close(); } if (out != null) { out.flush(); out.close(); } } }
From source file:com.company.project.web.controller.FileUploadController.java
@RequestMapping(value = "/doUpload", method = RequestMethod.POST) public String handleFileUpload(HttpServletRequest request, @RequestParam CommonsMultipartFile[] fileUpload) throws Exception { if (fileUpload != null && fileUpload.length > 0) { for (CommonsMultipartFile aFile : fileUpload) { String fileName = null; if (!aFile.isEmpty()) { try { fileName = aFile.getOriginalFilename(); byte[] bytes = aFile.getBytes(); BufferedOutputStream buffStream = new BufferedOutputStream( new FileOutputStream(new File("D:/CX1/" + fileName))); buffStream.write(bytes); buffStream.close();/* w w w . ja v a 2 s . c o m*/ System.out.println("You have successfully uploaded " + fileName); } catch (Exception e) { System.out.println("You failed to upload " + fileName + ": " + e.getMessage()); } } else { System.out.println("Unable to upload. File is empty."); } System.out.println("Saving file: " + aFile.getOriginalFilename()); aFile.getOriginalFilename(); aFile.getBytes(); } } return "admin"; }
From source file:com.company.project.web.controller.FileUploadController.java
@RequestMapping(value = "/asyncUpload", method = RequestMethod.POST/*, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE*/) @ResponseBody/*from www . ja v a2 s. com*/ public ResponseEntity<String> asyncFileUpload(HttpServletRequest request, @RequestParam CommonsMultipartFile[] fileUpload) throws Exception { if (fileUpload != null && fileUpload.length > 0) { for (CommonsMultipartFile aFile : fileUpload) { String fileName = null; if (!aFile.isEmpty()) { try { fileName = aFile.getOriginalFilename(); byte[] bytes = aFile.getBytes(); BufferedOutputStream buffStream = new BufferedOutputStream( new FileOutputStream(new File("D:/CX1/" + fileName))); buffStream.write(bytes); buffStream.close(); System.out.println("You have successfully uploaded " + fileName); } catch (Exception e) { System.out.println("You failed to upload " + fileName + ": " + e.getMessage()); } } else { System.out.println("Unable to upload. File is empty."); } System.out.println("Saving file: " + aFile.getOriginalFilename()); aFile.getOriginalFilename(); aFile.getBytes(); } } return new ResponseEntity<>("success", HttpStatus.OK); }
From source file:com.orchestra.portale.controller.NewDeepeningPageController.java
@RequestMapping(value = "/savedpage", method = RequestMethod.POST) public ModelAndView savedpage(HttpServletRequest request, @RequestParam Map<String, String> params, @RequestParam("cover") MultipartFile cover, @RequestParam("file") MultipartFile[] files) throws InterruptedException { ModelAndView model = new ModelAndView("okpageadmin"); DeepeningPage dp = new DeepeningPage(); dp.setName(params.get("name")); System.out.println(params.get("name")); int i = 1;/* w w w. j a v a 2 s . c om*/ ArrayList<String> categories = new ArrayList<String>(); while (params.containsKey("category" + i)) { categories.add(params.get("category" + i)); i = i + 1; } dp.setCategories(categories); ArrayList<AbstractPoiComponent> listComponent = new ArrayList<AbstractPoiComponent>(); //componente cover if (!cover.isEmpty()) { CoverImgComponent coverimg = new CoverImgComponent(); coverimg.setLink("cover.jpg"); listComponent.add(coverimg); } //componente galleria immagini ArrayList<ImgGallery> links = new ArrayList<ImgGallery>(); if (files.length > 0) { ImgGalleryComponent img_gallery = new ImgGalleryComponent(); i = 0; while (i < files.length) { ImgGallery img = new ImgGallery(); Thread.sleep(100); Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyyhmmssSSa"); String currentTimestamp = sdf.format(date); img.setLink("img_" + currentTimestamp + ".jpg"); if (params.containsKey("credit" + (i + 1))) { img.setCredit(params.get("credit" + (i + 1))); } i = i + 1; links.add(img); } img_gallery.setLinks(links); listComponent.add(img_gallery); } //DESCRIPTION COMPONENT i = 1; if (params.containsKey("par" + i)) { ArrayList<Section> list = new ArrayList<Section>(); while (params.containsKey("par" + i)) { Section section = new Section(); if (params.containsKey("titolo" + i)) { section.setTitle(params.get("titolo" + i)); } section.setDescription(params.get("par" + i)); list.add(section); i = i + 1; } DescriptionComponent description_component = new DescriptionComponent(); description_component.setSectionsList(list); listComponent.add(description_component); } dp.setComponents(listComponent); pm.saveDeepeningPage(dp); DeepeningPage poi2 = pm.findDeepeningPageByName(dp.getName()); for (int z = 0; z < files.length; z++) { MultipartFile file = files[z]; try { byte[] bytes = file.getBytes(); // Creating the directory to store file HttpSession session = request.getSession(); ServletContext sc = session.getServletContext(); File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "dpage" + File.separator + "img" + File.separator + poi2.getId()); if (!dir.exists()) { dir.mkdirs(); } // Create the file on server File serverFile = new File(dir.getAbsolutePath() + File.separator + links.get(z).getLink()); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile)); stream.write(bytes); stream.close(); } catch (Exception e) { model.addObject("mess", "ERRORE!"); return model; } } MultipartFile file = cover; try { byte[] bytes = file.getBytes(); // Creating the directory to store file HttpSession session = request.getSession(); ServletContext sc = session.getServletContext(); File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "dpage" + File.separator + "img" + File.separator + poi2.getId()); if (!dir.exists()) { dir.mkdirs(); } // Create the file on server File serverFile = new File(dir.getAbsolutePath() + File.separator + "cover.jpg"); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile)); stream.write(bytes); stream.close(); } catch (Exception e) { } model.addObject("mess", "PAGINA INSERITA CORRETTAMENTE!"); return model; }
From source file:com.xiovr.unibot.web.controller.ManageController.java
@RequestMapping(value = "/env/uploadcryptor", method = RequestMethod.POST) public @ResponseBody String cryptoreFileUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) { if (!file.isEmpty()) { try {//from www .j av a 2 s .c om byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream( new File(botGameConfig.getAbsDirPath() + "/" + BotEnvironment.LIBS_PATH + "/" + name))); stream.write(bytes); stream.close(); return "You successfully uploaded " + name + " into " + name + "-uploaded !"; } catch (Exception e) { return "You failed to upload " + name + " => " + e.getMessage(); } } else { return "You failed to upload " + name + " because the file was empty."; } }
From source file:org.zols.documents.service.DocumentService.java
/** * Upload documents//from w ww . j a v a2 s . co m * * @param documentRepositoryName name of the repository * @param upload documents to be uploaded * @param rootFolderPath source path of the document */ public void upload(String documentRepositoryName, Upload upload, String rootFolderPath) throws DataStoreException { DocumentRepository documentRepository = documentRepositoryService.read(documentRepositoryName); String folderPath = documentRepository.getPath(); if (rootFolderPath != null && rootFolderPath.trim().length() != 0) { folderPath = folderPath + File.separator + rootFolderPath; } List<MultipartFile> multipartFiles = upload.getFiles(); if (null != multipartFiles && multipartFiles.size() > 0) { for (MultipartFile multipartFile : multipartFiles) { //Handle file content - multipartFile.getInputStream() byte[] bytes; try { bytes = multipartFile.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream( new File(folderPath + File.separator + multipartFile.getOriginalFilename()))); stream.write(bytes); stream.close(); } catch (IOException ex) { java.util.logging.Logger.getLogger(DocumentService.class.getName()).log(Level.SEVERE, null, ex); } } } }
From source file:com.ibm.dbwkl.helper.CryptionModule.java
/** * @param result/* w ww .j a va 2 s. co m*/ * as encryptedPassword * @param path * @return STAFResult */ public STAFResult writePassfile(String result, String path) { byte[] passbytes; if (path != null) { if (path.length() != 0) { this.passpath = path; } } try { File passfile = new File(this.passpath); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(passfile)); passbytes = result.getBytes(); bos.write(passbytes); bos.close(); } catch (IOException e) { return new STAFResult(STAFResult.InvalidRequestString, "Error while wrting to path"); } return new STAFResult(STAFResult.Ok, "Encrypted Password saved in " + this.passpath); }
From source file:logicProteinHypernetwork.analysis.complexes.offline.ComplexPredictionCommand.java
/** * Returns predicted complexes for a given undirected graph of proteins. * * @param g the graph/*from w w w . j a v a 2 s. co m*/ * @return the predicted complexes */ public Collection<Complex> transform(UndirectedGraph<Protein, Interaction> g) { try { Process p = Runtime.getRuntime().exec(command); BufferedOutputStream outputStream = new BufferedOutputStream(p.getOutputStream()); BufferedInputStream inputStream = new BufferedInputStream(p.getInputStream()); for (Interaction i : g.getEdges()) { String out = i.first() + " pp " + i.second(); outputStream.write(out.getBytes()); } outputStream.close(); p.waitFor(); if (!hypernetwork.getProteins().hasIndex()) { hypernetwork.getProteins().buildIndex(); } Collection<Complex> complexes = new ArrayList<Complex>(); Scanner s = new Scanner(inputStream); Pattern rowPattern = Pattern.compile(".*?\\n"); Pattern proteinPattern = Pattern.compile(".*?\\s"); while (s.hasNext(rowPattern)) { Complex c = new Complex(); while (s.hasNext(proteinPattern)) { c.add(hypernetwork.getProteins().getProteinById(s.next(proteinPattern).trim())); } complexes.add(c); } inputStream.close(); return complexes; } catch (InterruptedException ex) { Logger.getLogger(ComplexPredictionCommand.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ComplexPredictionCommand.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:com.xiovr.unibot.web.controller.ManageController.java
@RequestMapping(value = "/bot/uploadscript", method = RequestMethod.POST) public @ResponseBody String scriptFileUpload(@RequestParam("name") String name, @RequestParam("file") MultipartFile file) { if (!file.isEmpty()) { try {/*from ww w. j a va 2 s . c o m*/ byte[] bytes = file.getBytes(); BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(new File( botGameConfig.getAbsDirPath() + "/" + botEnvironment.getScriptsPathPrefix() + "/" + name))); stream.write(bytes); stream.close(); return "You successfully uploaded " + name + " into " + name + "-uploaded !"; } catch (Exception e) { return "You failed to upload " + name + " => " + e.getMessage(); } } else { return "You failed to upload " + name + " because the file was empty."; } }