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:com.spotify.echoprintserver.nativelib.Util.java
/** * Decode an Echoprint string into its list of codes (temporal offsets are not returned). */// w w w . j a v a2 s .c om public static List<Integer> decodeEchoprintString(String echoprintString) throws IOException { byte[] decoded = b64SafeDecode(echoprintString); DeflateCompressorInputStream is = new DeflateCompressorInputStream(new ByteArrayInputStream(decoded)); ByteArrayOutputStream os = new ByteArrayOutputStream(); IOUtils.copy(is, os); String decodedEchoprintString = os.toString(); // skip the first half of the string (offsets) // take every 5 chars, parse int in base 16 List<Integer> codes = new ArrayList<Integer>(); int N = decodedEchoprintString.length(); for (int n = N / 2; n < N; n += 5) { String s = decodedEchoprintString.substring(n, n + 5); Integer c = Integer.parseInt(s, 16); codes.add(c); } return codes; }
From source file:io.selendroid.builder.AndroidDriverAPKBuilder.java
public File extractAndroidDriverAPK() { InputStream is = AndroidDriverAPKBuilder.class.getResourceAsStream( PREBUILD_WEBVIEW_APP_PATH_PREFIX + SelendroidServerBuilder.getJarVersionNumber() + ".apk"); try {/*from www . ja v a2 s. c o m*/ File tmpAndroidDriver = File.createTempFile("android-driver", ".apk"); IOUtils.copy(is, new FileOutputStream(tmpAndroidDriver)); IOUtils.closeQuietly(is); return tmpAndroidDriver; } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:cz.cuni.amis.planning4j.sicstus.AbstractSicstusPlanner.java
private static File createTempFileFromStream(InputStream s) { try {/* ww w.j av a 2 s .co m*/ File tempFile = File.createTempFile("Sicstus", ".sav"); FileOutputStream output = new FileOutputStream(tempFile); IOUtils.copy(s, output); output.close(); return tempFile; } catch (IOException ex) { throw new PlanningException("Error preparing save file"); } }
From source file:at.asitplus.regkassen.demo.testsuites.TestSuiteGenerator.java
public static List<CashBoxSimulation> getSimulationRuns() { try {/* ww w .j a v a 2 s . co m*/ //define the to-be-executed test suites List<String> testSuites = new ArrayList<>(); testSuites.add("TESTSUITE_TEST_SZENARIO_1.json"); testSuites.add("TESTSUITE_TEST_SZENARIO_2.json"); testSuites.add("TESTSUITE_TEST_SZENARIO_3.json"); testSuites.add("TESTSUITE_TEST_SZENARIO_4.json"); testSuites.add("TESTSUITE_TEST_SZENARIO_5.json"); testSuites.add("TESTSUITE_TEST_SZENARIO_6.json"); testSuites.add("TESTSUITE_TEST_SZENARIO_7.json"); testSuites.add("TESTSUITE_TEST_SZENARIO_8.json"); //prepare cashbox simulation files List<CashBoxSimulation> cashBoxSimulationList = new ArrayList<>(); for (String testSuiteIdentifier : testSuites) { //load from file system InputStream inputStream = TestSuiteGenerator.class.getClassLoader() .getResourceAsStream(testSuiteIdentifier); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); IOUtils.copy(inputStream, bOut); inputStream.close(); bOut.close(); //parse JSON structure Gson gson = new GsonBuilder().setPrettyPrinting().create(); CashBoxSimulation cashBoxSimulation = gson.fromJson(new String(bOut.toByteArray()), CashBoxSimulation.class); cashBoxSimulationList.add(cashBoxSimulation); } return cashBoxSimulationList; } catch (IOException e) { e.printStackTrace(); } return new ArrayList<>(); }
From source file:br.univali.ps.fuzzy.portugolFuzzyCorretor.control.FileController.java
public static File carregarFuzzyRules() throws FileNotFoundException, IOException { final String caminho = "Portugol_Corretor_Rules.flc"; final InputStream resourceStream = ClassLoader.getSystemClassLoader().getResourceAsStream(caminho); File PCR = new File("Portugol_Corretor_Rules.flc"); try (OutputStream outputStream = new FileOutputStream(PCR)) { IOUtils.copy(resourceStream, outputStream); }/* w w w. j a va 2 s.c o m*/ return PCR; }
From source file:io.apiman.gateway.engine.io.BytesPayloadIO.java
/** * @see io.apiman.gateway.engine.io.IPayloadIO#unmarshall(java.io.InputStream) *//*from w w w.ja v a 2 s . c o m*/ @Override public byte[] unmarshall(InputStream input) throws Exception { try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { IOUtils.copy(input, output); output.flush(); return output.toByteArray(); } }
From source file:net.bpelunit.util.XMLUtilTest.java
@Test public void testWriteXMLToStream() throws Exception { Document doc = XMLUtil.parseXML(getClass().getResourceAsStream("simple.xml")); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLUtil.writeXML(doc, out);/*from w w w. j a v a2 s.c om*/ ByteArrayOutputStream reference = new ByteArrayOutputStream(); IOUtils.copy(getClass().getResourceAsStream("simple.xml"), reference); String referenceString = normalize(reference.toString()); String actualString = normalize(out.toString()); assertEquals(referenceString, actualString); }
From source file:net.bpelunit.util.ZipUtil.java
public static void zipDirectory(File directory, File zipFile) throws IOException { @SuppressWarnings("unchecked") Collection<File> files = FileUtils.listFiles(directory, null, true); FileOutputStream fzos = null; ZipOutputStream zos = null;//www. j a va 2 s . c om try { fzos = new FileOutputStream(zipFile); zos = new ZipOutputStream(fzos); for (File f : files) { String fileNameInZIP = directory.toURI().relativize(f.toURI()).getPath(); ZipEntry zipEntry = new ZipEntry(fileNameInZIP); zos.putNextEntry(zipEntry); FileInputStream fileInputStream = new FileInputStream(f); try { IOUtils.copy(fileInputStream, zos); } finally { IOUtils.closeQuietly(fileInputStream); } } } finally { IOUtils.closeQuietly(zos); IOUtils.closeQuietly(fzos); } }
From source file:io.milton.http.LockInfoSaxHandler.java
public static LockInfo parseLockInfo(Request request) throws IOException, FileNotFoundException, SAXException { InputStream in = request.getInputStream(); XMLReader reader = XMLReaderFactory.createXMLReader(); reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false); LockInfoSaxHandler handler = new LockInfoSaxHandler(); reader.setContentHandler(handler);/*w ww . j a va 2 s.com*/ if (log.isDebugEnabled()) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); IOUtils.copy(in, bout); byte[] bytes = bout.toByteArray(); in = new ByteArrayInputStream(bytes); log.debug("LockInfo: " + bout.toString()); } reader.parse(new InputSource(in)); LockInfo info = handler.getInfo(); info.depth = LockDepth.INFINITY; // todo if (info.lockedByUser == null) { if (request.getAuthorization() != null) { if (request.getAuthorization().getUser() != null) { info.lockedByUser = request.getAuthorization().getUser(); } else { Object user = request.getAuthorization().getTag(); if (user instanceof DiscretePrincipal) { DiscretePrincipal dp = (DiscretePrincipal) user; info.lockedByUser = dp.getPrincipalURL(); } } } } if (info.lockedByUser == null) { log.warn("resource is being locked with a null user. This won't really be locked at all..."); } return info; }
From source file:com.ikon.module.db.stuff.FsDataStore.java
/** * Write to data store //from ww w .j ava 2 s. c o m */ public static File save(String uuid, InputStream is) throws IOException { log.debug("save({}, {})", uuid, is); File fs = resolveFile(uuid); fs.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(fs); IOUtils.copy(is, fos); IOUtils.closeQuietly(fos); return fs; }