List of usage examples for java.io BufferedOutputStream close
@Override public void close() throws IOException
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;//from w w w . j ava2s .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 {/* ww w . ja va2 s.c o m*/ 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:com.ibm.dbwkl.helper.CryptionModule.java
/** * @param result/*from www .ja v a 2 s. c om*/ * 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:com.streamsets.pipeline.stage.processor.geolocation.TestGeolocationProcessor.java
@Before public void setup() throws Exception { tempDir = Files.createTempDir(); databaseFile = new File(tempDir, "GeoLite2-Country.mmdb"); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(databaseFile)); Resources.copy(Resources.getResource("GeoLite2-Country.mmdb"), out); out.flush();/*from w w w.j a v a2 s .c om*/ out.close(); }
From source file:org.zols.documents.service.DocumentService.java
/** * Upload documents/*w ww . j a va2s . c om*/ * * @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:net.sf.firemox.deckbuilder.BuildBook.java
/** * @param cardName//from ww w .ja v a 2 s . c o m * the key card name. * @return the image associated to this card * @throws BadElementException * @throws IOException * If some other I/O error occurs */ @SuppressWarnings("null") public Image getImage(String cardName) throws BadElementException, IOException { Iterator<String> i = null; i = cachedImageDir.iterator(); File img = null; while (i.hasNext()) { String[] extensions = new String[] { ".jpg", ".jpeg", ".png", ".gif", ".tiff" }; String base = i.next(); for (int j = 0; j < extensions.length; j++) { img = new File(base, cardName.toLowerCase() + extensions[j]); if (img.exists()) { break; } img = null; } if (img != null) break; img = null; } if (img != null) { java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(img.getAbsolutePath()); java.awt.Image awtImageX4 = awtImage.getScaledInstance(800, -1, java.awt.Image.SCALE_SMOOTH); awtImage = null; return Image.getInstance(awtImageX4, null); } i = imageSources.iterator(); while (i.hasNext()) { String urlpath = i.next(); urlpath = urlpath.replace("{name}", cardName); URL url = new URL(urlpath); URLConnection cn = url.openConnection(); if (cn.getContentType() == null || cn.getContentType().startsWith("image") && cn.getInputStream() != null) { img = new File(this.cachedImageDirStore, cardName.toLowerCase() + ".jpg"); BufferedOutputStream fw = new BufferedOutputStream(new FileOutputStream(img)); BufferedInputStream is = new BufferedInputStream(cn.getInputStream()); IOUtils.copy(is, fw); fw.close(); java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(img.getAbsolutePath()); java.awt.Image awtImageX4 = null; awtImageX4 = awtImage.getScaledInstance(800, -1, java.awt.Image.SCALE_SMOOTH); return Image.getInstance(awtImageX4, null); } } return Image.getInstance(this.dedfaultImage); }
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(); System.out.println("You have successfully uploaded " + fileName); } catch (Exception e) { System.out.println("You failed to upload " + fileName + ": " + e.getMessage()); }/*from www. jav a 2 s . co m*/ } 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.streamsets.pipeline.stage.origin.kafka.TestKafkaSource.java
@BeforeClass public static void setUp() throws IOException, InterruptedException { sdcKafkaTestUtil.startZookeeper();/* w ww . jav a 2s . c om*/ sdcKafkaTestUtil.startKafkaBrokers(3); zkConnect = sdcKafkaTestUtil.getZkConnect(); sdcKafkaTestUtil.createTopic(TOPIC1, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC2, MULTIPLE_PARTITIONS, MULTIPLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC3, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC4, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC5, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC6, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC7, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC8, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC9, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC10, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC11, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC12, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC13, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC14, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC15, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); sdcKafkaTestUtil.createTopic(TOPIC16, SINGLE_PARTITION, SINGLE_REPLICATION_FACTOR); for (int i = 1; i <= 16; i++) { TestUtils.waitUntilMetadataIsPropagated( scala.collection.JavaConversions.asScalaBuffer(sdcKafkaTestUtil.getKafkaServers()), "TestKafkaSource" + String.valueOf(i), 0, 5000); // For now, the only topic that needs more than one partition is topic 2. Eventually we should put all these into // a class and make sure we create the topics based on a list of Topic/Partition info, rather than this. if (i == 2) { for (int j = 0; j < MULTIPLE_PARTITIONS; j++) { TestUtils.waitUntilMetadataIsPropagated( scala.collection.JavaConversions.asScalaBuffer(sdcKafkaTestUtil.getKafkaServers()), "TestKafkaSource" + String.valueOf(i), j, 5000); } } } producer = sdcKafkaTestUtil.createProducer(sdcKafkaTestUtil.getMetadataBrokerURI(), true); tempDir = Files.createTempDir(); protoDescFile = new File(tempDir, "Employee.desc"); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(protoDescFile)); Resources.copy(Resources.getResource("Employee.desc"), out); out.flush(); out.close(); }
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 w w w .j a v a2 s .co m*/ 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.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 w ww . ja v a2 s. c om 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."; } }