List of usage examples for javax.sql.rowset.serial SerialBlob SerialBlob
public SerialBlob(Blob blob) throws SerialException, SQLException
SerialBlob
object that is a serialized version of the given Blob
object. From source file:br.com.manish.ahy.kernel.util.JPAUtil.java
public static Blob bytesToBlob(byte[] bytes) { Blob ret = null;//from www . j a v a 2s . c o m try { ret = new SerialBlob(bytes); } catch (Exception e) { throw new OopsException(e, "Error reading file data."); } return ret; }
From source file:org.ambraproject.article.service.ArticleDocumentServiceTest.java
@DataProvider(name = "blob") public Object[][] blob() throws Exception { String xml = "<xml><childNode>some test xml</childNode></xml>"; Document parsedXml = documentBuilderFactory.newDocumentBuilder() .parse(new ByteArrayInputStream(xml.getBytes())); return new Object[][] { { new SerialBlob(xml.getBytes()), parsedXml } }; }
From source file:it.swim.util.ConvertitoreFotoInBlob.java
/** * Metodo per convertire un fileItem in blob, per poterlo salvare sul database * @param item : FileItem ottenuta nella servlet * @param lunghezza : int che rappresenta la lunghezza che dovra' avere l'immagine sul database * @param altezza : int che rappresenta l'altezza che dovra' avere l'immagine sul database * @param dimensioneMaxInMB : int che rappresenta la dimensione massima del file caricato * @return <b>blob</b> che rappresenta l'oggetto gia' ridimensionato, pronto per essere salvato sul database * @throws IOException errore durante il ridimensionamento oppure nella conversione in Blob * @throws SerialException errore nella conversione in Blob * @throws SQLException errore nella conversione in Blob * @throws FotoException errore con cause: * FILETROPPOGRANDE: se la dimensione del file supera quella prevista * NONRICONOSCIUTACOMEFOTO: dovuto all'upload di un file che non e' una foto, oppure lo e' ma il sistema non la riconosce come tale *//*from www . j av a2 s .co m*/ public static Blob getBlobFromFileItem(FileItem item, int lunghezza, int altezza, int dimensioneMaxInMB) throws IOException, SerialException, SQLException, FotoException { Blob blob = null; InputStream filecontent = item.getInputStream(); byte[] b = new byte[filecontent.available()]; log.debug("inputstream blob: " + filecontent.available()); if (filecontent.available() > 0) { filecontent.read(b); //metto i dati nell'array b che uso nei metodi successivi log.debug(" ------------ " + b.length); if (b.length > dimensioneMaxInMB * 1024 * 1024) { //se file piu' grande di dimensioneMaxInMB lancia eccezione throw new FotoException(FotoException.Causa.FILETROPPOGRANDE); } //per poter ridimensionare l'immagine ho bisogno dia vere un BufferedImage, allora converto il byte[] in BufferedImage BufferedImage bufferedImage = ImageResizer.convertiByteArrayInBufferedImage(b); //attenzione se non e' una immagine o ci sono altri problemi nel capire che il file e' una immagine, la variabile bufferedImage==null if (bufferedImage == null) { throw new FotoException(FotoException.Causa.NONRICONOSCIUTACOMEFOTO); } else { //ridimensiono l'immagine e riottengo un riferimento BufferedImage BufferedImage ridimensionata = ImageResizer.ridimensionaImmagine(bufferedImage, lunghezza, altezza); //ora riconverto la bufferedImage in byte[] byte[] ridottaConvertita = ImageResizer.convertiBufferedImageInByteArray(ridimensionata); //infine converto l'immagine in byte[] in un Blob per salvarlo sul database, non in questo metodo pero' blob = new SerialBlob(ridottaConvertita); } } filecontent.close(); return blob; }
From source file:fr.univrouen.poste.web.admin.GalaxieExcelController.java
@RequestMapping(value = "/addFile", method = RequestMethod.POST, produces = "text/html") public String addFile(@Valid GalaxieExcel galaxieExcel, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) throws IOException, SQLException { if (bindingResult.hasErrors()) { logger.warn(bindingResult.getAllErrors()); return "redirect:/admin/galaxieexcels"; }/* w ww.j av a 2 s .c o m*/ uiModel.asMap().clear(); // upload file MultipartFile file = galaxieExcel.getFile(); String filename = file.getOriginalFilename(); InputStream inputStream = file.getInputStream(); byte[] bytes = IOUtils.toByteArray(inputStream); galaxieExcel.setFilename(filename); galaxieExcel.getBigFile().setBinaryFile(new SerialBlob(bytes)); galaxieExcel.getBigFile().persist(); // set current date Calendar cal = Calendar.getInstance(); galaxieExcel.setCreation(cal.getTime()); // persist galaxieExcel.persist(); // process : generate GalaxieEntries galaxieExcelParser.process(galaxieExcel); return "redirect:/admin/galaxieexcels"; }
From source file:fr.univrouen.poste.web.admin.CommissionExcelController.java
@RequestMapping(value = "/addFile", method = RequestMethod.POST, produces = "text/html") public String addFile(@Valid CommissionExcel commissionExcel, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) throws IOException, SQLException { if (bindingResult.hasErrors()) { logger.warn(bindingResult.getAllErrors()); return "redirect:/admin/commissionexcels"; }//from ww w . j av a 2 s . c om uiModel.asMap().clear(); // upload file MultipartFile file = commissionExcel.getFile(); String filename = file.getOriginalFilename(); InputStream inputStream = file.getInputStream(); byte[] bytes = IOUtils.toByteArray(inputStream); commissionExcel.setFilename(filename); commissionExcel.getBigFile().setBinaryFile(new SerialBlob(bytes)); commissionExcel.getBigFile().persist(); // set current date Calendar cal = Calendar.getInstance(); commissionExcel.setCreation(cal.getTime()); // persist commissionExcel.persist(); // process : generate CommissionEntries commissionExcelParser.process(commissionExcel); return "redirect:/admin/commissionexcels"; }
From source file:com.xeiam.datasets.hjabirdsong.bootstrap.RawData2DB.java
private void go(String labelsFile, String wavNameFile) throws IOException { List<String> labelsLines = FileUtils.readLines(new File(labelsFile), "UTF-8"); List<String> wavNameLines = FileUtils.readLines(new File(wavNameFile), "UTF-8"); for (int i = 0; i < labelsLines.size(); i++) { String labelLine = labelsLines.get(i); String wavNameLine = wavNameLines.get(i); // System.out.println(labelLine); // System.out.println(wavNameLine); String bagIDString = labelLine.substring(0, labelLine.indexOf(",")); String labelsCSV = labelLine.substring(labelLine.indexOf(",") + 1, labelLine.length()); String wavFileName = wavNameLine.substring(wavNameLine.indexOf(",") + 1, wavNameLine.length()) + ".wav"; InputStream fis = null;/*from www .j a va 2 s.c om*/ try { // the Wav file Bytes File srcFile = new File("./raw/wav/" + wavFileName); fis = new FileInputStream(srcFile); byte[] buffer = new byte[(int) srcFile.length()]; fis.read(buffer, 0, buffer.length); HJABirdSong hJABirdSong = new HJABirdSong(); hJABirdSong.setBagid(Integer.parseInt(bagIDString)); hJABirdSong.setLabels(labelsCSV); hJABirdSong.setWavfilename(wavFileName); hJABirdSong.setWavbytes(new SerialBlob(buffer)); HJABirdsongDAO.insert(hJABirdSong); // System.out.println(hJABirdSong.toString()); idx++; } catch (Exception e) { e.printStackTrace(); // eat it. skip first line in file. } finally { if (fis != null) { fis.close(); } } } System.out.println("Number parsed: " + idx); }
From source file:com.denimgroup.threadfix.service.DocumentServiceImpl.java
@Override public String saveFileToApp(Integer appId, MultipartFile file) { if (appId == null || file == null) { log.warn("The document upload file failed to save, it had null input."); return null; }/*from w w w. j a v a2 s . c o m*/ Application application = applicationDao.retrieveById(appId); if (application == null) { log.warn("Unable to retrieve Application - document save failed."); return null; } if (!contentTypeService.isValidUpload(file.getContentType())) { log.warn("Invalid filetype for upload: " + file.getContentType()); return null; } Document doc = new Document(); String fileFullName = file.getOriginalFilename(); doc.setApplication(application); doc.setName(getFileName(fileFullName)); doc.setType(getFileType(fileFullName)); if (!doc.getType().equals("json")) { doc.setContentType(contentTypeService.translateContentType(file.getContentType())); } else { doc.setContentType(contentTypeService.translateContentType("json")); } try { Blob blob = new SerialBlob(file.getBytes()); doc.setFile(blob); List<Document> appDocs = application.getDocuments(); if (appDocs == null) appDocs = new ArrayList<Document>(); appDocs.add(doc); documentDao.saveOrUpdate(doc); applicationDao.saveOrUpdate(application); } catch (SQLException | IOException e) { log.warn("Unable to save document - exception occurs."); return null; } return fileFullName; }
From source file:it.swim.util.ConvertitoreFotoInBlob.java
/** * Metodo per caricare la foto del profilo di default * @return <b>blob</b> che rappresenta l'oggetto pronto per essere salvato sul database * @throws IOException errore durante il ridimensionamento oppure nella conversione in Blob * @throws SerialException errore nella conversione in Blob * @throws SQLException errore nella conversione in Blob * @throws FotoException errore con causa: ERROREFOTODEFAULT se non e' stata letta la foto di default dal disco *//*from www .j a v a 2 s . c o m*/ public static Blob getBlobFromDefaultImage() throws IOException, SerialException, SQLException, FotoException { Blob blob = null; //per poter caricare l'immagine ho bisogno di leggere dal disco una BufferedImage BufferedImage bufferedImage = FotoProfiloDefault.getInstance().getFotoProfiloDefault(); if (!FotoProfiloDefault.getInstance().isErrore() && bufferedImage != null) { //ora converto la bufferedImage in byte[] byte[] ridottaConvertita = ImageResizer.convertiBufferedImageInByteArray(bufferedImage); //infine converto l'immagine in byte[] in un Blob per salvarlo sul database, non in questo metodo pero' blob = new SerialBlob(ridottaConvertita); } else { throw new FotoException(FotoException.Causa.ERROREFOTODEFAULT); } return blob; }
From source file:com.ebay.pulsar.analytics.dao.service.BaseDBService.java
public static Map<String, Object> describe(Object obj) { if (obj == null) { return null; }// ww w . j a va2s .co m Map<String, Object> map = new HashMap<String, Object>(); try { BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor property : propertyDescriptors) { String key = property.getName(); if (!key.equals("class")) { try { Method getter = property.getReadMethod(); Object value = getter.invoke(obj); if (value != null) { if ("properties".equalsIgnoreCase(key) || "config".equalsIgnoreCase(key)) { value = new SerialBlob(((String) value).getBytes()); } map.put(key, value); } } catch (Exception e) { logger.error("transBean1Map Error " + e); } } } } catch (Exception e) { logger.error("transBean2Map Error " + e); } return map; }
From source file:com.denimgroup.threadfix.service.DocumentServiceImpl.java
@Override public String saveFileToVuln(Integer vulnId, MultipartFile file) { if (vulnId == null || file == null) { log.warn("The document upload file failed to save, it had null input."); return null; }/*from w w w . ja v a 2 s .c o m*/ if (!contentTypeService.isValidUpload(file.getContentType())) { log.warn("Invalid filetype for upload: " + file.getContentType()); return null; } Vulnerability vulnerability = vulnerabilityDao.retrieveById(vulnId); if (vulnerability == null) { log.warn("Unable to retrieve Vulnerability - document save failed."); return null; } Document doc = new Document(); String fileFullName = file.getOriginalFilename(); doc.setVulnerability(vulnerability); doc.setName(getFileName(fileFullName)); doc.setType(getFileType(fileFullName)); doc.setContentType(contentTypeService.translateContentType(file.getContentType())); try { Blob blob = new SerialBlob(file.getBytes()); doc.setFile(blob); List<Document> appDocs = vulnerability.getDocuments(); if (appDocs == null) appDocs = new ArrayList<Document>(); appDocs.add(doc); documentDao.saveOrUpdate(doc); vulnerabilityDao.saveOrUpdate(vulnerability); } catch (SQLException | IOException e) { log.warn("Unable to save document - exception occurs."); return null; } return fileFullName; }