List of usage examples for org.apache.commons.io IOUtils toByteArray
public static byte[] toByteArray(String input) throws IOException
String
as a byte[]
using the default character encoding of the platform. From source file:br.ufac.sion.service.retorno.ArquivoRetornoCaixaService.java
public ArquivoRetornoDetalhe carregar(String fileName, InputStream inputstream) throws ArquivoRetornoException { try {/*from ww w . j a v a2 s. com*/ ArquivoRetornoCaixa arquivoRetorno = criarArquivoRetorno(fileName, inputstream); this.ard = new ArquivoRetornoDetalhe(); this.ar = new ArquivoRetorno(); this.ar.setNome(fileName); this.ar.setDataUpload(LocalDateTime.now()); this.ar.setNumero(arquivoRetorno.getCabecalhoLote().getNumeroRetorno()); this.ar.setArquivo(IOUtils.toByteArray(inputstream)); this.ar = em.merge(ar); carregarMensagens(arquivoRetorno); carregarTitulos(arquivoRetorno); return ard; } catch (Exception e) { e.printStackTrace(); throw new ArquivoRetornoException("Erro ao processar o arquivo de retorno: " + e.getMessage()); } }
From source file:com.Yakreem15.managedBean.ProductMBean.java
public String createProduct() { String userEmail = findCurrentUserEamil(); System.out.println(uploadedFiles == null); System.out.println("before iterating"); for (UploadedFile uploadedFile : uploadedFiles) { System.out.println(uploadedFile == null); System.out.println("in the loop"); if (uploadedFile != null) { byte[] foto; try { foto = IOUtils.toByteArray(uploadedFile.getInputstream()); System.out.println(Arrays.toString(foto)); Product_Photos temp = new Product_Photos(); temp.setProduct_photo(foto); temp.setProduct(product); photo_list.add(temp);//from ww w . ja v a 2 s . c o m } catch (IOException ex) { Logger.getLogger(ProductMBean.class.getName()).log(Level.SEVERE, null, ex); } } } product.setPhotos(photo_list); productBean.addProdcut(product, userEmail); return "/index"; }
From source file:com.nirima.jenkins.repo.build.MetadataChecksumRepositoryItem.java
protected String generateContent() { try {//from ww w . j a v a 2 s . c o m MessageDigest md = MessageDigest.getInstance(algorithm.toUpperCase()); byte[] digest = md.digest(IOUtils.toByteArray(item.getContent())); String hex = new BigInteger(1, digest).toString(16); // Need to prepend with 0s if not the correct length int requiredNumberOfCharacters = md.getDigestLength() * 2; while (hex.length() < requiredNumberOfCharacters) { hex = "0" + hex; } return hex; } catch (Exception nsae) { return "ERROR: " + nsae.getMessage(); } }
From source file:ddf.service.kml.internal.TransformedContentImpl.java
@Override public byte[] getByteArray() throws IOException { if (bytes == null) { try {// w w w . j a v a 2s. co m bytes = IOUtils.toByteArray(inputStream); } catch (IOException e) { LOGGER.warn("Error getting content size", e); } } return bytes; }
From source file:com.github.restdriver.clientdriver.integration.SecureClientDriverRuleTest.java
private static KeyStore getKeystore() { try {// w w w .ja va2s. co m ClassLoader loader = SecureClientDriverTest.class.getClassLoader(); byte[] binaryContent = IOUtils.toByteArray(loader.getResourceAsStream("keystore.jks")); KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(new ByteArrayInputStream(binaryContent), "password".toCharArray()); return keyStore; } catch (Exception e) { throw new ClientDriverSetupException("Key store could not be loaded.", e); } }
From source file:com.shoylpik.controller.AddProduct.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String SAVE_DIRECTORY = "menu_assets/ProductImage"; String absolutePath = request.getServletContext().getRealPath(""); String savePath = absolutePath + File.separator + SAVE_DIRECTORY; File imageSaveDirectory = new File(savePath); if (!imageSaveDirectory.exists()) { imageSaveDirectory.mkdir();/* ww w . java2s . com*/ } System.out.println("absolutePath: " + absolutePath); System.out.println("SavePath: " + savePath); // System.out.println("imageSaveDirectory.getAbsolutePath(): " + imageSaveDirectory.getAbsolutePath()); String fileName = null; try { Part filePart = request.getPart("IPimage"); String filename = getFilename(filePart); // System.out.println("filename: " + filename); InputStream imageInputStream = filePart.getInputStream(); byte[] bytes = IOUtils.toByteArray(imageInputStream); Product product = new Product(); product.setProductId(Integer.parseInt(request.getParameter("IPID"))); product.setProductName(request.getParameter("IPname")); product.setProductImageName(filename); product.setProductCategory(request.getParameter("IPcat")); product.setProductPrice(Float.parseFloat(request.getParameter("IPprice"))); product.setProductQuantity(Integer.parseInt(request.getParameter("IPQuant"))); ProductBean pBean = new ProductBean(); pBean.addProduct(product); // String fullImagePath = "menu_assets/images/"+filename; String fullImagePath = savePath + File.separator + filename; File file = new File(fullImagePath); // System.out.println("fullImagePath : " + fullImagePath); FileOutputStream fos = new FileOutputStream(file); fos.write(bytes); } catch (SQLException ex) { Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException | ServletException | NumberFormatException ex) { Logger.getLogger(AddProduct.class.getName()).log(Level.SEVERE, null, ex); } response.sendRedirect("AdministrationPage.jsp"); }
From source file:com.wso2mobile.mam.packageExtractor.ZipFileReading.java
public String readAndroidManifestFile(String filePath) { String xml = ""; try {/*from www .j a va 2s . c om*/ ZipInputStream stream = new ZipInputStream(new FileInputStream(filePath)); try { ZipEntry entry; while ((entry = stream.getNextEntry()) != null) { if (entry.getName().equals("AndroidManifest.xml")) { StringBuilder builder = new StringBuilder(); xml = AndroidXMLParsing.decompressXML(IOUtils.toByteArray(stream)); } } } finally { stream.close(); } Document doc = loadXMLFromString(xml); doc.getDocumentElement().normalize(); JSONObject obj = new JSONObject(); obj.put("version", doc.getDocumentElement().getAttribute("versionName")); obj.put("package", doc.getDocumentElement().getAttribute("package")); xml = obj.toJSONString(); } catch (Exception e) { xml = "Exception occured " + e; } return xml; }
From source file:com.enonic.cms.core.http.HTTPService.java
public byte[] getURLAsBytes(String address, int timeoutMs, int readTimeoutMs) { BufferedReader reader = null; try {/*from w w w . jav a 2s. co m*/ URLConnection urlConn = setUpConnection(address, timeoutMs, readTimeoutMs); InputStream responseStream = urlConn.getInputStream(); return IOUtils.toByteArray(responseStream); } catch (Exception e) { String message = "Failed to get URL: \"" + address + "\": " + e.getMessage(); LOG.warn(message); } finally { try { closeReader(reader); } catch (IOException ioe) { String message = "Failed to close reader stream: \"" + address + "\": " + ioe.getMessage(); LOG.warn(message); } } return null; }
From source file:net.ontopia.infoset.content.InMemoryContentStore.java
@Override public int add(InputStream data, int length) throws ContentStoreException { try {/* w ww . ja va 2s . co m*/ content.put(nextKey, IOUtils.toByteArray(data)); return nextKey++; } catch (IOException e) { throw new ContentStoreException(e); } }
From source file:io.tourniquet.junit.http.rules.HttpExchange.java
public byte[] getPayload() { if (this.payload == null) { try {/* w w w .j a v a 2 s . co m*/ this.payload = IOUtils.toByteArray(this.exchange.getInputStream()); } catch (IOException e) { throw new RuntimeException(e); } } final byte[] data = new byte[this.payload.length]; System.arraycopy(this.payload, 0, data, 0, this.payload.length); return data; }