List of usage examples for org.apache.commons.io IOUtils copy
public static void copy(Reader input, OutputStream output) throws IOException
Reader
to bytes on an OutputStream
using the default character encoding of the platform, and calling flush. From source file:azkaban.jobtype.connectors.teradata.TeraDataWalletInitializer.java
/** * As of TDCH 1.4.1, integration with Teradata wallet only works with hadoop jar command line command. * This is mainly because TDCH depends on the behavior of hadoop jar command line which extracts jar file * into hadoop tmp folder./* w ww .ja v a 2 s . co m*/ * * This method will extract tdchJarfile and place it into temporary folder, and also add jvm shutdown hook * to delete the directory when JVM shuts down. * @param tdchJarFile TDCH jar file. */ public static void initialize(File tmpDir, File tdchJarFile) { synchronized (TeraDataWalletInitializer.class) { if (tdchJarExtractedDir != null) { return; } if (tdchJarFile == null) { throw new IllegalArgumentException("TDCH jar file cannot be null."); } if (!tdchJarFile.exists()) { throw new IllegalArgumentException( "TDCH jar file does not exist. " + tdchJarFile.getAbsolutePath()); } try { //Extract TDCH jar. File unJarDir = createUnjarDir( new File(tmpDir.getAbsolutePath() + File.separator + UNJAR_DIR_NAME)); JarFile jar = new JarFile(tdchJarFile); Enumeration<JarEntry> enumEntries = jar.entries(); while (enumEntries.hasMoreElements()) { JarEntry srcFile = enumEntries.nextElement(); File destFile = new File(unJarDir + File.separator + srcFile.getName()); if (srcFile.isDirectory()) { // if its a directory, create it destFile.mkdir(); continue; } InputStream is = jar.getInputStream(srcFile); BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(destFile)); IOUtils.copy(is, os); close(os); close(is); } jar.close(); tdchJarExtractedDir = unJarDir; } catch (IOException e) { throw new RuntimeException("Failed while extracting TDCH jar file.", e); } } logger.info("TDCH jar has been extracted into directory: " + tdchJarExtractedDir.getAbsolutePath()); }
From source file:com.talis.storage.s3.S3ObjectFactoryTest.java
@Test public void createdObjectDataContainsBytesFromBuffer() throws Exception { S3Object obj = factory.newObject("second", 8, MediaType.TEXT_PLAIN_TYPE, buffer); ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(obj.getDataInputStream(), out); assertTrue(Arrays.equals(entity, out.toByteArray())); }
From source file:de.micromata.genome.tpsb.httpmockup.HttpClientRequestAcceptor.java
@Override public void acceptRequest(MockHttpServletRequest request, MockHttpServletResponse response) throws IOException, ServletException { HttpPost method = buildMethod(request); httpClient.executeMethod(method);//ww w. j a v a2s. c o m response.setStatus(httpClient.getLastHttpStatus()); byte[] data = httpClient.getLastResponseBody(); if (data != null) { IOUtils.copy(new ByteArrayInputStream(data), response.getOutputStream()); } }
From source file:de.crowdcode.movmvn.core.Unzipper.java
/** * Unzip a file./*from ww w.ja va 2 s . co m*/ * * @param archiveFile * to be unzipped * @param outPath * the place to put the result * @throws IOException * exception * @throws ZipException * exception */ public void unzipFileToDir(final File archiveFile, final File outPath) throws IOException, ZipException { ZipFile zipFile = new ZipFile(archiveFile); Enumeration<ZipArchiveEntry> e = zipFile.getEntries(); while (e.hasMoreElements()) { ZipArchiveEntry entry = e.nextElement(); File file = new File(outPath, entry.getName()); if (entry.isDirectory()) { FileUtils.forceMkdir(file); } else { InputStream is = zipFile.getInputStream(entry); FileOutputStream os = FileUtils.openOutputStream(file); try { IOUtils.copy(is, os); } finally { os.close(); is.close(); } file.setLastModified(entry.getTime()); } } }
From source file:de.nrw.hbz.regal.sync.ingest.OpusDownloader.java
private void downloadXMetaDissPlus(File dir, String pid) throws IOException { String url = server + pid;/*from w w w .ja v a 2s. c o m*/ logger.info("Download: " + url); URL dataStreamUrl = new URL(url); File dataStreamFile = new File(dir.getAbsolutePath() + File.separator + "" + pid + ".xml"); // dataStreamFile.createNewFile(); logger.info("Save: " + dataStreamFile.getAbsolutePath()); String data = null; StringWriter writer = new StringWriter(); IOUtils.copy(dataStreamUrl.openStream(), writer); data = writer.toString(); FileUtils.writeStringToFile(dataStreamFile, data, "utf-8"); }
From source file:ee.ria.DigiDoc.configuration.Configuration.java
private static void placeAccessCertificate(Context context) { File schemaPath = FileUtils.getSchemaCacheDirectory(context); try {//from www . ja va 2s. c om InputStream is = context.getResources().openRawResource(R.raw.sk878252); File accessCertificate = new File(schemaPath, "878252.p12"); FileOutputStream out = new FileOutputStream(accessCertificate); IOUtils.copy(is, out); out.close(); } catch (IOException e) { Timber.e(e, "error placing access certificate"); } }
From source file:de.quadrillenschule.azocamsyncd.astromode.SmartPhoneWrapper.java
public static SmartPhoneStatus update(PhotoSerie ps) throws IOException { URL url;//from w w w .j a va 2 s .co m String retval; try { url = new URL(PROTOCOL + "://" + LAST_WORKING_IP + ":" + PORT + "/" + WebService.WebCommands.updateTriggered + "/?" + WebService.WebParameters.jobid + "=" + ps.getId() + "&" + WebService.WebParameters.receivedImages + "=" + ps.getReceived()); lastStatus = SmartPhoneStatus.TRYING; URLConnection uc = url.openConnection(); uc.setConnectTimeout(3000); StringWriter sw = new StringWriter(); IOUtils.copy((InputStream) uc.getContent(), System.out); } catch (MalformedURLException ex) { Logger.getLogger(SmartPhoneWrapper.class.getName()).log(Level.SEVERE, null, ex); return SmartPhoneStatus.ERROR; } lastStatus = SmartPhoneStatus.CONNECTED; return SmartPhoneStatus.CONNECTED; }
From source file:md.archivers.ZIPArchiver.java
private void zipDirectory(File zipFile, File directory) throws FileNotFoundException, IOException { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)); FileInputStream fin = null;//from w w w .j a v a 2s .c o m for (File d : directory.listFiles()) { for (File f : d.listFiles()) { zos.putNextEntry(new ZipEntry(createNameForZip(f))); try { fin = new FileInputStream(f); IOUtils.copy(fin, zos); } finally { if (fin != null) fin.close(); } zos.closeEntry(); } } zos.close(); }
From source file:fr.putnami.pwt.plugin.spring.file.server.controller.FileTransfertController.java
@RequestMapping(value = "/file/upload/{uploadId}", method = RequestMethod.POST) @ResponseBody/*from ww w . java 2 s. co m*/ public FileDto upload(@PathVariable String uploadId, @RequestParam("data") CommonsMultipartFile multipart, HttpServletRequest request, HttpServletResponse response) { OutputStream out = null; InputStream in = null; try { out = this.store.write(uploadId, multipart.getOriginalFilename(), multipart.getContentType()); in = multipart.getInputStream(); IOUtils.copy(in, out); return this.store.getFileBean(uploadId); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:com.googlecode.arit.systest.Application.java
public File getExplodedWAR() { if (explodedWAR == null) { File explodedDir = new File(tmpDir, "exploded"); explodedDir.mkdir();/*from www . j a v a 2 s . c o m*/ String file = url.getFile(); explodedWAR = new File(explodedDir, file.substring(file.lastIndexOf('/'))); try { InputStream in = url.openStream(); try { JarInputStream jar = new JarInputStream(in); JarEntry jarEntry; while ((jarEntry = jar.getNextJarEntry()) != null) { File dest = new File(explodedWAR, jarEntry.getName()); if (jarEntry.isDirectory()) { dest.mkdir(); } else { dest.getParentFile().mkdirs(); OutputStream out = new FileOutputStream(dest); try { IOUtils.copy(jar, out); } finally { out.close(); } } } } finally { in.close(); } } catch (IOException ex) { throw new SystestException("Failed to explode WAR", ex); } } return explodedWAR; }