List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:jp.co.opentone.bsol.linkbinder.view.correspon.attachment.NewAttachmentInfoTest.java
@Before public void setUp() throws Exception { dir = new File("tmp"); if (!dir.exists()) { dir.mkdirs();/* w ww . ja v a2 s. c o m*/ } file = new File(dir.getAbsolutePath(), "AttachmentInfoTest.tmp"); FileUtils.writeByteArrayToFile(file, content.getBytes()); info = new NewAttachmentInfo(file.getName(), file.getAbsolutePath()); }
From source file:fi.jumi.threadsafetyagent.util.TransformationTestClassLoader.java
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { try {// w ww . j a v a2 s. co m byte[] b = transformer.transform(this, name, null, null, readClassBytes(name)); if (dirToWriteClasses != null) { try { FileUtils.writeByteArrayToFile(new File(dirToWriteClasses, name + ".class"), b); } catch (IOException e) { throw new RuntimeException(e); } } return defineClass(name, b, 0, b.length); } catch (IllegalClassFormatException e) { throw new ClassNotFoundException(name, e); } }
From source file:com.tesora.dve.mysqlapi.repl.MyInfileHandler.java
public void addInitialBlock(int fileId, byte[] block) throws IOException { FileUtils.writeByteArrayToFile(getInfile(fileId), block); }
From source file:jfix.db4o.xstream.converter.BlobConverter.java
public Object fromString(String str) { Blob blob = new Blob(); try {//from w ww . jav a2 s .c o m FileUtils.writeByteArrayToFile(blob.getFile(), new Base64Encoder().decode(str)); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } return blob; }
From source file:io.druid.segment.SegmentUtilsTest.java
@Test public void testIndexDrd() throws Exception { File dir = tempFolder.newFolder(); FileUtils.writeByteArrayToFile(new File(dir, "index.drd"), new byte[] { (byte) 0x8 }); Assert.assertEquals(8, SegmentUtils.getVersionFromDir(dir)); }
From source file:maku.mvc.services.ImageService.java
private static boolean save(String fileName, String path, MultipartFile image) { try {//from ww w.ja v a2 s. co m File file = new File(path + "//" + fileName); FileUtils.writeByteArrayToFile(file, image.getBytes()); } catch (IOException ex) { return false; } return true; }
From source file:com.codercowboy.photo.organizer.service.LibraryMarshaller.java
public void saveLibrary(Library library, String fileName) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {/*from ww w . j av a 2s . c om*/ Marshaller marshaller = this.createContext().createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(library, outputStream); FileUtils.writeByteArrayToFile(new File(fileName), outputStream.toByteArray()); } finally { outputStream.close(); } }
From source file:net.gplatform.sudoor.server.test.unit.TestUtils.java
/** * Take screen short & save to: target/test/selenium/ * //from ww w. j a v a 2s . c o m * @param driver * @param name */ public static void takeScreenshot(WebDriver driver, String name) { byte[] bScreenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES); File target = new File("target/test/selenium/" + name); try { FileUtils.writeByteArrayToFile(target, bScreenshot); } catch (IOException e) { e.printStackTrace(); } }
From source file:be.fedict.eid.pkira.blm.model.contracts.CertificateTest.java
@Test public void testGetCertificateZip() throws Exception { CertificateChainCertificate certificateChainCertificate2 = new CertificateChainCertificate(); certificateChainCertificate2.setCertificateData("chain2\n"); CertificateChainCertificate certificateChainCertificate1 = new CertificateChainCertificate(); certificateChainCertificate1.setCertificateData("chain1\n"); certificateChainCertificate1.setIssuer(certificateChainCertificate2); Certificate certificate = new Certificate(); certificate.setX509("x509test\n"); certificate.setCertificateChainCertificate(certificateChainCertificate1); File file = new File("target/testcertificate.zip"); FileUtils.writeByteArrayToFile(file, certificate.getCertificateZip()); ZipFile zipFile = new ZipFile(file); validateNextZipEntry(zipFile, "certificate.crt", "x509test\n"); validateNextZipEntry(zipFile, "chain1.crt", "chain1\n"); validateNextZipEntry(zipFile, "chain2.crt", "chain2\n"); }
From source file:de.ppi.selenium.util.ScreenshotUtils.java
/** * Save a screenshot./*from w ww. jav a 2s . c o m*/ * * @param screenshotFileName name of the file, without ending. * @param driver the webdriver. */ public static void saveScreenshot(String screenshotFileName, WebDriver driver) { try { WebDriver wrappedDriver = driver; while (wrappedDriver instanceof WrapsDriver) { wrappedDriver = ((WrapsDriver) wrappedDriver).getWrappedDriver(); } if (wrappedDriver instanceof TakesScreenshot) { final byte[] screenshot = ((TakesScreenshot) wrappedDriver).getScreenshotAs(OutputType.BYTES); FileUtils.writeByteArrayToFile(new File(screenshotFileName + ".png"), screenshot); } else if (wrappedDriver instanceof HtmlUnitDriver) { FileUtils.write(new File(screenshotFileName + ".html"), wrappedDriver.getPageSource(), "UTF-8"); } else { LOG.warn("The current driver doesn't make screenshots"); } } catch (IOException e) { LOG.error("IO-Error during creating of the screenshot ", e); } }