private Resource copyFileToPictures(MultipartFile file) throws IOException { String fileExtension = getFileExtension(file.getOriginalFilename()); File tempFile = File.createTempFile("pic", fileExtension, picturesDir.getFile()); try (InputStream in = file.getInputStream(); OutputStream out = new FileOutputStream(tempFile)) { IOUtils.copy(in, out); } return new FileSystemResource(tempFile); }
@RequestMapping(value = "/uploadedPicture") public void getUploadedPicture(HttpServletResponse response) throws IOException { Resource picturePath = userProfileSession.getPicturePath(); if (picturePath == null) { picturePath = anonymousPicture; } response.setHeader( "Content-Type", URLConnection.guessContentTypeFromName(picturePath.getFilename())); IOUtils.copy(picturePath.getInputStream(), response.getOutputStream()); }
public static byte[] decompress(final byte[] contentBytes) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(new GZIPInputStream(new ByteArrayInputStream(contentBytes)), out); return out.toByteArray(); }
/** * retourne toutes les infos sur un film * * @param request * @param response * @return */ public static String getFilmInfo(HttpServletRequest request, HttpServletResponse response) { int i = -1; String html = ""; Blob image = null; byte[] imgData = null; // SearchSignaletique(ident films.idfilm%type) try { // Ouvre la BDD BeanDBAccessORA dba = (BeanDBAccessORA) Beans.instantiate(null, "Bean.BeanDBAccessORA"); if (dba.init()) { String param = request.getParameter("id"); int idfilm = Integer.parseInt(param); ResultSet result = dba.SearchSignaletique(idfilm); // ResultSet result = array.getResultSet(); if (result == null) html += "Aucun résultat trouvé<br/>"; int count = 0; while (result.next()) { if (count == 0) { html += "<p>Titre: " + result.getString("Titre") + "</p>"; html += "<p>Durée: " + result.getString("Duree") + "</p>"; html += "<p>Cote: " + result.getString("Cote") + "</p>"; html += "<p>Date de sortie: " + result.getString("Datesortie") + "</p>"; html += "<p>Tagline: " + result.getString("Tagline") + "</p>"; html += "<p>Votes: " + result.getString("Votes") + "</p>"; // récupération de l'image final String path = "..\\webapps\\Web_Applic_Reservations\\" + idfilm + ".jpg"; InputStream instream = result.getBlob("POSTER").getBinaryStream(); BufferedInputStream bis = new BufferedInputStream(instream); if (!new File(path).exists()) { FileOutputStream fos = new FileOutputStream(path); BufferedOutputStream bos = new BufferedOutputStream(fos); IOUtils.copy(bis, bos); bos.close(); } // html += "<p>Affiche: <img // src=\"D:\\Serveur\\apache-tomcat-7.0.33-windows-x64\\apache-tomcat-7.0.33\\bin\\75.jpg\" /></p>"; html += "<p>current dir:" + System.getProperty("user.dir") + " </p>"; html += "<p>Affiche: <img src=\"./" + idfilm + ".jpg\" width=200 height=300/></p>"; html += "<p>Producteur: " + result.getString("Producteur") + "</p>"; html += "<p>Certification: " + result.getString("Certification") + "</p>"; html += "<p>Acteurs: </p>"; } else { html += "<dd>" + result.getString("acteur") + "</br>"; } count++; } } else { html = "dba.init() error2<br/>"; } } catch (NumberFormatException ex) { html += "NumberFormatException: " + ex.getMessage(); } catch (SQLException ex) { html += "SQLException: " + ex.getMessage(); } catch (IOException ex) { html += "IOException: " + ex.getMessage(); } catch (ClassNotFoundException ex) { html += "ClassNotFoundException: " + ex.getMessage(); } catch (NullPointerException ex) { html += "nullPointerException: " + ex.getMessage(); } return html; }