List of usage examples for org.springframework.util FileCopyUtils copy
public static void copy(String in, Writer out) throws IOException
From source file:Main.java
/** * Print xml to System.out./*from w w w. ja v a 2 s . com*/ * * @param xml XML */ public static void println(byte[] xml) throws Exception { FileCopyUtils.copy(new InputStreamReader(new ByteArrayInputStream(xml), "utf8"), new PrintWriter(System.out)); System.out.println(); System.out.flush(); }
From source file:com.eschava.forevernote.EvernoteUtil.java
public static Resource createResource(InputStream stream, String contentType) throws IOException { try {/*w ww. jav a 2s . c om*/ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); FileCopyUtils.copy(stream, outputStream); byte[] bytes = outputStream.toByteArray(); MessageDigest messageDigest = MessageDigest.getInstance("MD5"); byte[] hash = messageDigest.digest(bytes); Data data = new Data(); data.setBody(bytes); data.setBodyHash(hash); Resource resource = new Resource(); resource.setMime(contentType); resource.setData(data); return resource; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); // is not possible } }
From source file:Main.java
/** * Reads the XML document and returns it as a {@link String}. * //w w w .j av a 2 s. c o m * @param url the URL of the XML document * * @return the XML document, as a {@link String} * * @throws IOException */ public static String readXmlDocument(URL url) throws IOException { Reader in = new InputStreamReader(url.openStream()); CharArrayWriter out = new CharArrayWriter(); FileCopyUtils.copy(in, out); return out.toString(); }
From source file:Main.java
/** * Reads an XML document and returns it as a {@link String}. * /*from ww w .j a v a 2 s . c o m*/ * @param source the input source for the XML document * * @return the XML document, as a {@link String} * * @throws IOException */ public static String readXmlDocument(InputSource source) throws IOException { CharArrayWriter out = new CharArrayWriter(); FileCopyUtils.copy(source.getCharacterStream(), out); return out.toString(); }
From source file:com.nicksa.flickrtopicasa.io.IoUtils.java
public static void copyFile(File sourceFile, File toFile) throws Throwable { // Does the source file exist? if (!sourceFile.exists()) { throw new IllegalStateException("Source file does not exist."); }//www .j a va2 s.co m // Is the destination path a directory? if (toFile.isDirectory()) { toFile = new File(toFile, sourceFile.getName()); } // Does the destination path already exist on the filesystem? File parentDirectory = toFile.getParentFile(); if (!parentDirectory.exists()) { boolean successInMakingDirectory = parentDirectory.mkdirs(); if (!successInMakingDirectory) { throw new IllegalStateException("Could not create directories."); } } // Start copying. FileCopyUtils.copy(sourceFile, toFile); }
From source file:com.qpark.eip.core.sftp.InputStreamCallbackImpl.java
/** * @see org.springframework.integration.file.remote.InputStreamCallback#doWithInputStream(java.io.InputStream) *//*w w w.j a v a 2s .c o m*/ @Override public void doWithInputStream(final InputStream stream) throws IOException { FileCopyUtils.copy(stream, this.os); }
From source file:cz.muni.fi.pb138.cvmanager.controller.PDFcontroller.java
/** * Http Get request for "/auth/download" * Converts cv from xml format to latex and uploads pdf to users pc * * @param lang language of cv in downloaded pdf * @param response http server response//from ww w . ja va 2 s . co m */ @RequestMapping(value = "/auth/download", method = RequestMethod.GET) public void downloadPDF(@RequestParam("l") String lang, HttpServletResponse response) { try { //uncomment the calling of method when login finished pdfGenerator.xmlToLatex(getPrincipalUsername(), lang); InputStream pdf = pdfGenerator.latexToPdf(getPrincipalUsername()); response.setContentType("application/pdf"); FileCopyUtils.copy(pdf, response.getOutputStream()); response.flushBuffer(); } catch (Exception ex) { System.out.print(ex.toString()); try { PrintWriter out = response.getWriter(); out.println("Sorry, generating of CV to PDF failed"); out.close(); } catch (Exception e) { System.out.print("not able to print on web site"); } } }
From source file:controller.UploadFileController.java
@RequestMapping(method = RequestMethod.POST) public @ResponseBody String upload(@RequestParam(value = "file") MultipartFile mfile, HttpServletResponse res, HttpServletRequest req) {// ww w.j a v a 2s. com long time = Calendar.getInstance().getTimeInMillis(); String fileName = ""; try { fileName = time + mfile.getOriginalFilename(); File f = new File(req.getServletContext().getRealPath("/images") + "/" + fileName); if (!f.exists()) { f.createNewFile(); } FileOutputStream out = new FileOutputStream(f); FileCopyUtils.copy(mfile.getBytes(), out); } catch (Exception ex) { ex.printStackTrace(); } return "<img src='" + req.getContextPath() + "/images/" + fileName + "'/>"; }
From source file:doge.photo.DogePhotoManipulatorTest.java
@Test public void testDogePhotoManipulatorService() throws Exception { Photo photo = () -> new ClassPathResource("thehoff.jpg").getInputStream(); Photo manipulated = this.manipulator.manipulate(photo); FileCopyUtils.copy(manipulated.getInputStream(), new FileOutputStream(this.file)); }
From source file:org.focusns.common.web.page.engine.widget.WidgetResponse.java
@Override public void flushBuffer() throws IOException { FileCopyUtils.copy(content.toByteArray(), super.getOutputStream()); }