Example usage for org.apache.commons.io FileUtils writeByteArrayToFile

List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils writeByteArrayToFile.

Prototype

public static void writeByteArrayToFile(File file, byte[] data) throws IOException 

Source Link

Document

Writes a byte array to a file creating the file if it does not exist.

Usage

From source file:com.liferay.cucumber.util.FileUtil.java

public static void write(File file, byte[] bytes) throws IOException {
    FileUtils.writeByteArrayToFile(file, bytes);
}

From source file:net.grinder.util.LogCompressUtilTest.java

@Test
public void testLogCompressDecompress() throws IOException {
    File file = new File(LogCompressUtilTest.class.getResource("/grinder1.properties").getFile());
    byte[] zippedContent = LogCompressUtils.compress(file);
    File createTempFile2 = File.createTempFile("a22aa", ".zip");
    createTempFile2.deleteOnExit();//w  ww  .  j  a  v  a2s .  c o m
    FileUtils.writeByteArrayToFile(createTempFile2, zippedContent);
    File createTempFile = File.createTempFile("a22", "tmp");
    LogCompressUtils.decompress(zippedContent, createTempFile);
    assertThat(createTempFile.exists(), is(true));
    byte[] unzippedContent = FileUtils.readFileToByteArray(createTempFile);
    assertThat(unzippedContent, is(FileUtils.readFileToByteArray(file)));
}

From source file:net.sourceforge.javydreamercsw.validation.manager.web.file.AbstractFileDisplay.java

@Override
public File loadFile(String name, byte[] bytes) throws IOException {
    File result = new File(System.getProperty("java.io.tmpdir") + System.getProperty("file.separator") + name);
    FileUtils.writeByteArrayToFile(result, bytes);
    return result;
}

From source file:com.javacreed.examples.sc.part3.MembersServiceImpl.java

@Override
public void afterPropertiesSet() throws Exception {
    FileUtils.writeByteArrayToFile(dataFile, IOUtils.toByteArray(getClass().getResource("members.txt")));
}

From source file:com.music.service.LocalFileStorageService.java

@Override
public void storeFile(String path, byte[] content) throws IOException {
    FileUtils.writeByteArrayToFile(new File(path), content);
}

From source file:io.druid.segment.SegmentUtilsTest.java

@Test
public void testVersionBin() throws Exception {
    File dir = tempFolder.newFolder();
    byte[] bytes = Ints.toByteArray(9);
    FileUtils.writeByteArrayToFile(new File(dir, "version.bin"), Ints.toByteArray(9));
    Assert.assertEquals(9, SegmentUtils.getVersionFromDir(dir));
}

From source file:br.ufrn.fonoweb.service.ArquivoService.java

public boolean saveFile(String fileName, byte[] contents) {
    boolean status = false;

    try {//from w  w w  .  j a va 2 s  .com
        FileUtils.writeByteArrayToFile(new File(this.getDataStore().concat(fileName)), contents);
        status = true;
    } catch (IOException ex) {
        Logger.getLogger(ArquivoService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return status;
}

From source file:controllers.ParseBaseController.java

@RequestMapping("/addFile")
public String addFile(Map<String, Object> model, @RequestParam("newFile") MultipartFile file)
        throws IOException {
    File newFile = new File("/usr/local/etc/qutoCatalog.sql");
    //++?   ???  
    if (!newFile.exists()) {
        FileUtils.writeByteArrayToFile(newFile, file.getBytes());
    } else {//from ww w .  j  av a  2s. c om
        newFile.delete();
        FileUtils.writeByteArrayToFile(newFile, file.getBytes());
    }
    return "redirect:/ParseBaseController/show";
}

From source file:jp.co.opentone.bsol.linkbinder.view.correspon.attachment.AttachmentInfoTest.java

@Before
public void setUp() throws Exception {
    dir = new File("tmp");
    if (!dir.exists()) {
        dir.mkdirs();//from w  w  w .j  a va2s.c  o m
    }

    file = new File(dir.getAbsolutePath(), "AttachmentInfoTest.tmp");
    FileUtils.writeByteArrayToFile(file, "this is test".getBytes());
}

From source file:de.xirp.report.ReportManager.java

/**
 * This method opens the contained PDF data of the 
 * given {@link de.xirp.report.ReportDescriptor}
 * in the default viewer of the underlying operating system.
 * //from  w ww  . j  a  v  a  2 s .  c  o  m
 * @param rd
 *          The report descriptor to open.
 */
public static void viewReport(ReportDescriptor rd) {
    File tmp = new File(Constants.TMP_DIR, "report_temp_xirp2.pdf"); //$NON-NLS-1$
    try {
        tmp.createNewFile();
        FileUtils.writeByteArrayToFile(tmp, rd.getPdfData());
        SWTUtil.openFile(tmp);
    } catch (IOException e) {
        logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
    }
    if (tmp != null) {
        DeleteManager.deleteOnShutdown(tmp);
    }
}