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:com.formkiq.core.util.Resources.java
/** * Gets a file from classpath as bytes./*from w ww. j a v a 2 s .co m*/ * @param file {@link String} * @return {@link String} * @throws IOException IOException */ public static String getResourceAsString(final String file) throws IOException { InputStream is = getResourceAsInputStream(file); if (is == null) { throw new FileNotFoundException(file); } try { byte[] bytes = IOUtils.toByteArray(is); String s = Strings.toString(bytes); return s; } finally { IOUtils.closeQuietly(is); } }
From source file:anhttpserver.HttpRequestContext.java
/** * Create wrapper from passed {@code httpExcahnge} param * @param httpExcahnge instance if {@link HttpExchange} for current request *//*from w w w .j a va2s. co m*/ public HttpRequestContext(HttpExchange httpExcahnge) { this.httpExchange = httpExcahnge; try { this.requestBody = IOUtils.toByteArray(httpExcahnge.getRequestBody()); } catch (IOException e) { /* ignore */ } }
From source file:be.fedict.eid.dss.model.bean.XmlStyleSheetManagerBean.java
public void add(String namespace, String revision, InputStream xslInputStream) throws ExistingXmlStyleSheetException { XmlStyleSheetEntity existingXmlStyleSheetEntity = this.entityManager.find(XmlStyleSheetEntity.class, namespace);// w w w .j a v a 2s.c om if (null != existingXmlStyleSheetEntity) { throw new ExistingXmlStyleSheetException(); } byte[] xsl; try { xsl = IOUtils.toByteArray(xslInputStream); } catch (IOException e) { throw new RuntimeException("IO error: " + e.getMessage(), e); } XmlStyleSheetEntity xmlStyleSheetEntity = new XmlStyleSheetEntity(namespace, revision, xsl); this.entityManager.persist(xmlStyleSheetEntity); }
From source file:fi.helsinki.opintoni.service.storage.FileSystemFileStorage.java
@Override public byte[] get(String name) { byte[] imageData; try {/*w w w . ja va 2 s.c o m*/ InputStream inputStream = new FileInputStream(appConfiguration.get("fileStorage.path") + "/" + name); imageData = IOUtils.toByteArray(inputStream); inputStream.close(); } catch (FileNotFoundException e) { throw new RuntimeException("File not found: " + name); } catch (IOException e) { throw new RuntimeException("Could not open file: " + name); } return imageData; }
From source file:ddf.service.kml.internal.TransformedContentImpl.java
@Override public long getSize() { if (bytes == null) { try {/*from w w w. ja v a 2s.c o m*/ bytes = IOUtils.toByteArray(inputStream); } catch (IOException e) { LOGGER.warn("Error getting content size", e); bytes = new byte[0]; } } return bytes.length; }
From source file:com.tliu3.demo.springboot.service.DogeService.java
public Photo addDogePhoto(User user, Photo photo) throws IOException { Photo manipulatedPhoto = this.manipulator.manipulate(photo); byte[] rawBytes = IOUtils.toByteArray(manipulatedPhoto.getInputStream()); if (user.getPhoto() == null) { user.setPhoto(new UserPhoto(user, rawBytes)); } else {//from w w w .ja v a2s . c om user.getPhoto().setPhoto(rawBytes); } userRepository.saveAndFlush(user); return manipulatedPhoto; }
From source file:mx.materiam.gibran.ManagerBean.java
public void upload(FileUploadEvent evt) { UploadedFile uf = evt.getFile();/*from w w w . j a v a 2 s . com*/ if (uf != null) { try { byte[] bytes = IOUtils.toByteArray(uf.getInputstream()); current.setArrayPdf(bytes); } catch (IOException ex) { Logger.getLogger(ManagerBean.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:jodtemplate.pptx.ImageService.java
public void insertImage(final ImageField imageField, final Slide slide, final Resources resources, final Element pic) throws JODTemplateException { try {/* w w w .j ava2s. c o m*/ final InputStream is = imageField.getInputStream(); if (is != null) { try (final InputStream bis = new BufferedInputStream(is)) { final byte[] imageContents = IOUtils.toByteArray(bis); final Image image = getImage(imageContents, slide.getPresentation(), resources); final Relationship imageRel = getImageRelationship(image, slide); final Attribute embed = pic .getChild(PPTXDocument.BLIPFILL_ELEMENT, getPresentationmlNamespace()) .getChild(PPTXDocument.BLIP_ELEMENT, getDrawingmlNamespace()) .getAttribute(PPTXDocument.EMBED_ATTR, getRelationshipsNamespace()); embed.setValue(imageRel.getId()); setPicSize(pic, image); } } else { pic.getParent().removeContent(pic); } } catch (IOException | DataConversionException e) { throw new JODTemplateException(e); } }
From source file:com.talis.storage.memory.MemoryStore.java
@Override public synchronized StoredItem write(URI tmbURI, SubmittedItem submitted) throws IOException { byte[] entity = IOUtils.toByteArray(submitted.getEntity()); String etag = DigestUtils.md5Hex(entity); SubmittedItem clone = new SubmittedItem(submitted.getMediaType(), new ByteArrayInputStream(entity), submitted.getMetadata());//from w ww . java2s . c o m StoredItem toStore = new StoredItem(clone, new Date(System.currentTimeMillis()), etag); storage.put(tmbURI, toStore); return copyItem(entity, toStore); }
From source file:eu.hydrologis.stage.geopaparazzi.servlets.ProjectDownloadServiceHandler.java
@Override public void service(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String authHeader = req.getHeader("Authorization"); String[] userPwd = StageUtils.getUserPwdWithBasicAuthentication(authHeader); if (userPwd == null || !LoginChecker.isLoginOk(userPwd[0], userPwd[1])) { throw new ServletException("No permission!"); }//from ww w . ja v a2 s . c o m // userPwd = new String[]{"testuser"}; Object projectIdObj = req.getParameter("id"); if (projectIdObj != null) { String projectId = (String) projectIdObj; File geopaparazziFolder = StageWorkspace.getInstance().getGeopaparazziFolder(userPwd[0]); File newGeopaparazziFile = new File(geopaparazziFolder, projectId); byte[] data = IOUtils.toByteArray(new FileInputStream(newGeopaparazziFile)); DownloadService service = new DownloadService(data, newGeopaparazziFile.getName()); service.register(); resp.sendRedirect(resp.encodeRedirectURL(service.getURL())); } else { throw new ServletException("No project id provided."); } }