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:org.kuali.coeus.s2sgen.impl.generate.support.stylesheet.StylesheetValidationTest.java

private void saveData(String xml, byte[] pdf, Class<? extends S2SFormGenerator> clazz) {
    final String printLogging = System.getProperty(ConfigurationConstants.PRINT_LOGGING_ENABLE);
    final String printPdfLogging = System.getProperty(ConfigurationConstants.PRINT_PDF_LOGGING_ENABLE);
    final String printDirectory = System.getProperty(ConfigurationConstants.PRINT_LOGGING_DIRECTORY);

    if (StringUtils.isNotBlank(printDirectory)) {
        try {//from  ww w  . j  ava  2s  . c  o  m
            if ("true".equalsIgnoreCase(printLogging)) {
                File xmlFile = new File(new File(printDirectory),
                        clazz.getSimpleName() + LocalDateTime.now().toString() + ".xml");
                FileUtils.write(xmlFile, xml);
            }

            if ("true".equalsIgnoreCase(printPdfLogging) && pdf != null) {
                File pdfFile = new File(new File(printDirectory),
                        clazz.getSimpleName() + LocalDateTime.now().toString() + ".pdf");
                FileUtils.writeByteArrayToFile(pdfFile, pdf);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.kuali.ole.docstore.engine.service.storage.rdbms.RdbmsLicenseAttachmentDocumentManager.java

@Override
protected License getLicenseInfo(LicenseRecord licenseRecord) {
    LicenseAttachment licenseAttachment = new LicenseAttachment();
    licenseAttachment.setFileName(licenseRecord.getFileName());
    licenseAttachment.setDocumentTitle(licenseRecord.getDocumentTitle());
    licenseAttachment.setDocumentMimeType(licenseRecord.getDocumentMimeType());
    licenseAttachment.setDocumentNote(licenseRecord.getDocumentNote());
    licenseAttachment.setFilePath(FileUtils.getTempDirectoryPath() + File.separator + "license attachment");
    File file = new File(licenseAttachment.getFilePath() + File.separator + licenseRecord.getFileName());
    LOG.info("file path in docstore : " + licenseAttachment.getFilePath());
    try {//  w w w  .j  a v  a2s .c om
        FileUtils.writeByteArrayToFile(file, licenseRecord.getContent());
    } catch (IOException e) {
        LOG.error("Exception : ", e);
    }
    return licenseAttachment;
}

From source file:org.kuali.rice.kew.batch.XmlIngestionTest.java

public void testXmlReIngestion() throws Exception {

    // Define the path for the test environment
    String filePath = "org/kuali/rice/kew/batch/data/widgetsTest.xml";
    File ingestedFile = new ClasspathOrFileResourceLoader().getResource(filePath).getFile();
    List<XmlDocCollection> collections = new ArrayList<XmlDocCollection>();
    XmlDocCollection fileDoc = new FileXmlDocCollection(ingestedFile);
    collections.add(fileDoc);//from  w ww  . jav  a  2  s .c o  m
    // ingest the collection and save it to the database
    Collection<XmlDocCollection> ingestedXmlFile = null;
    try {
        ingestedXmlFile = CoreApiServiceLocator.getXmlIngesterService().ingest(collections);
    } catch (Exception e) {
        LOG.error("Error ingesting data", e);
        //throw new RuntimeException(e);
    }

    EdlExportDataSet dataSet = new EdlExportDataSet();

    //Cast this for now
    List<EDocLiteAssociation> edla = EdlServiceLocator.getEDocLiteService().getEDocLiteAssociations();
    String style = null;
    for (EDocLiteAssociation edl : edla) {
        if (edl != null) {
            style = edl.getStyle();
            if ("widgetsTest".equals(style)) {
                dataSet.getEdocLites().add(edl);
            }
        }
    }

    byte[] xmlBytes = CoreApiServiceLocator.getXmlExporterService().export(dataSet.createExportDataSet());
    // now export that xml into a file
    File reingestFile = File.createTempFile("widgetsTestOutput", ".xml");
    FileUtils.writeByteArrayToFile(reingestFile, xmlBytes);
    String ingestedString = FileUtils.readFileToString(ingestedFile);
    String reingestedString = FileUtils.readFileToString(reingestFile);
    //assertTrue(FileUtils.contentEquals(ingestedFile, reingestFile));
}

From source file:org.kurento.test.browser.WebPage.java

public File getRecording(String fileName) throws IOException {
    browser.executeScript("kurentoTest.recordingToData();");
    String recording = getProperty("recordingData").toString();

    // Base64 to File
    File outputFile = new File(fileName);
    byte[] bytes = Base64.decodeBase64(recording.substring(recording.lastIndexOf(",") + 1));
    FileUtils.writeByteArrayToFile(outputFile, bytes);

    return outputFile;
}

From source file:org.languagetool.gui.Main.java

private void saveFile(boolean newFile) {
    if (currentFile == null || newFile) {
        JFileChooser jfc = new JFileChooser();
        jfc.setFileFilter(new PlainTextFileFilter());
        jfc.showSaveDialog(frame);//from   w ww  . java2s  . c  o m

        File file = jfc.getSelectedFile();
        if (file == null) { // user clicked cancel
            return;
        }
        currentFile = file;
        bom = null;
        updateTitle();
    }
    try {
        if (bom != null) {
            FileUtils.writeByteArrayToFile(currentFile, bom.getBytes());
            FileUtils.write(currentFile, textArea.getText(), bom.getCharsetName(), true);
        } else {
            FileUtils.write(currentFile, textArea.getText(), Charset.defaultCharset());
        }
    } catch (IOException ex) {
        Tools.showError(ex);
    }
}

From source file:org.lilyproject.solrtestfw.SolrHomeDirSetup.java

private void writeSchema(File solrConfDir, byte[] schemaData) throws IOException {
    FileUtils.writeByteArrayToFile(new File(solrConfDir, "schema.xml"), schemaData);
}

From source file:org.limy.eclipse.qalab.action.part.AbstractPartAction.java

public void run(final IAction action) {
    Job job = new Job(getClass().getSimpleName()) {
        @Override//from ww  w .jav  a  2s.c o  m
        protected IStatus run(IProgressMonitor monitor) {
            try {
                innerExecute(true);
                if (action instanceof ISelectionListener) {
                    LimyCompatibleUtils.openBrowser(getReportHtml().toURI().toURL());
                }
            } catch (final CoreException e) {
                window.getShell().getDisplay().syncExec(new Runnable() {
                    public void run() {
                        QalabActionUtils.showConfirmDialog(null, e.getMessage());
                    }
                });
                return Status.CANCEL_STATUS;
            } catch (final IOException e) {
                window.getShell().getDisplay().syncExec(new Runnable() {
                    public void run() {
                        QalabActionUtils.showConfirmDialog(null, e.getMessage());
                    }
                });
                return Status.CANCEL_STATUS;
            } finally {
                try {
                    FileUtils.writeByteArrayToFile(getDestFile(".eclipse.log"),
                            getWriter().toString().getBytes());
                } catch (IOException e) {
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}

From source file:org.limy.eclipse.qalab.action.part.CalcCoberturaAction.java

@Override
protected void makeReport() throws CoreException {

    try {/* w  ww  .  java 2s .co m*/

        FileUtils.deleteDirectory(getDestFile("instrumented"));
        getDestFile("cobertura.ser").delete();

        FileUtils.deleteDirectory(getDestFile("classes"));
        copyAllClassFiles();

        ProcessUtils.execProgram(getBaseDir(), getWriter(), "java", "-classpath",
                createClasspath(getFile("cobertura.jar"), getFilePrefix("asm"), getFilePrefix("asm-tree"),
                        getFilePrefix("log4j"), getFilePrefix("jakarta-oro")),
                "net.sourceforge.cobertura.instrument.Main", "--destination",
                getDestFile("instrumented").getAbsolutePath(), "--datafile",
                getDestFile("cobertura.ser").getAbsolutePath(), getDestFile("classes").getAbsolutePath());

        getDestFile("coverage/xml").mkdirs();

        List<String> args = new ArrayList<String>();
        args.add("java");
        args.add("-Dnet.sourceforge.cobertura.datafile=" + getDestFile("cobertura.ser").getAbsolutePath());
        args.add("-classpath");
        args.add(createClasspath(LimyQalabUtils.getPath(""), LimyQalabUtils.getPath("bin"), getFile("ant.jar"),
                getFile("ant-junit.jar"), getFilePrefix("junit")));
        args.add("org.limy.eclipse.qalab.action.part.JUnit4Support");
        args.add("--destdir");
        args.add(getDestDir().getAbsolutePath());

        for (IPath path : getEnv().getTestSourcePaths(true)) {
            args.add("--testsrc");
            args.add(LimyQalabUtils.createFullPath(getJavaProject(), path));
        }

        args.add("--classpath");
        args.add(getFilePrefix("junit"));
        args.add("--classpath");
        args.add(getDestFile("instrumented").getAbsolutePath());
        for (IPath path : getEnv().getBinPaths(true)) {
            String dir = LimyQalabUtils.createFullPath(getJavaProject(), path);
            args.add("--classpath");
            args.add(dir);
        }
        args.add("--classpath");
        args.add(getFile("cobertura.jar"));
        args.add("--classpath");
        args.add(getFilePrefix("asm"));
        args.add("--classpath");
        args.add(getFilePrefix("asm-tree"));
        args.add("--classpath");
        args.add(getFilePrefix("log4j"));
        args.add("--classpath");
        args.add(getFilePrefix("jakarta-oro"));
        for (String location : LimyQalabUtils.getJavaLibraries(getJavaProject())) {
            args.add("--classpath");
            args.add(location);
        }

        ProcessUtils.execProgram(getBaseDir(), getWriter(), args.toArray(new String[args.size()]));

        ProcessUtils.execProgram(getBaseDir(), getWriter(), "java", "-classpath",
                createClasspath(getFile("cobertura.jar"), getFilePrefix("asm"), getFilePrefix("asm-tree"),
                        getFilePrefix("log4j"), getFilePrefix("jakarta-oro")),
                "net.sourceforge.cobertura.reporting.Main", "--format", "xml", "--destination",
                getDestDir().getAbsolutePath(), "--datafile", getDestFile("cobertura.ser").getAbsolutePath(),
                "--charset", getEncoding(), getAllSrcDir().getAbsolutePath());

        FileUtils.writeByteArrayToFile(getDestFile("test.txt"), getWriter().toString().getBytes("UTF-8"));

        getDestFile("junit").mkdirs();

        XMLResultAggregator reportTask = new XMLResultAggregator();
        reportTask.setTodir(getDestFile("junit"));
        FileSet fs = new FileSet();
        fs.setDir(getDestFile("coverage/xml"));
        fs.setIncludes("TEST-*.xml");
        AggregateTransformer report = reportTask.createReport();
        report.setFormat((Format) Format.getInstance(Format.class, AggregateTransformer.FRAMES));
        report.setTodir(getDestFile("junit/html"));
        reportTask.addFileSet(fs);

        Project project = new Project();
        project.setProperty("java.io.tmpdir", System.getProperty("java.io.tmpdir"));
        reportTask.setProject(project);

        reportTask.execute();

        ProcessUtils.execProgram(getBaseDir(), getWriter(), "java", "-classpath",
                createClasspath(getFile("cobertura.jar"), getFilePrefix("asm"), getFilePrefix("asm-tree"),
                        getFilePrefix("log4j"), getFilePrefix("jakarta-oro")),
                "net.sourceforge.cobertura.reporting.Main", "--format", "html", "--destination",
                getDestFile("coverage/html").getAbsolutePath(), "--datafile",
                getDestFile("cobertura.ser").getAbsolutePath(), "--charset", getEncoding(),
                getAllSrcDir().getAbsolutePath());

    } catch (IOException e) {
        LimyEclipseUtils.log(e);
    }

    //        outputReport("pmd");

}

From source file:org.limy.eclipse.qalab.action.part.CalcJavancssAction.java

@Override
protected void makeReport() throws CoreException {

    try {//  ww w. j a  va 2s  .  com

        ProcessUtils.execProgram(getBaseDir(), getWriter(), "java", "-classpath",
                createClasspath(getFile("javancss.jar"), getFile("ccl.jar"), getFile("jhbasic.jar")),
                "javancss.Main", "-all", "-xml", "-out", getDestFile("javancss_report.xml").getAbsolutePath(),
                getDestFile("src").getAbsolutePath() + "\\*.java");

        FileUtils.writeByteArrayToFile(getDestFile("pmd_report.xml"), getWriter().toString().getBytes("UTF-8"));

    } catch (IOException e) {
        LimyEclipseUtils.log(e);
    }

    outputReport("javancss");

}

From source file:org.limy.eclipse.qalab.action.part.CalcPmdAction.java

@Override
protected void makeReport() throws CoreException {

    try {//from  w ww  . j a  v a 2  s.  co  m

        File file = LimyQalabUtils.getConfigFile(getEnv(), "pmd-ruleset.xml", LimyQalabConstants.KEY_PMD_TYPE,
                LimyQalabConstants.KEY_PMD_CFG);
        FileUtils.copyFile(file, getDestFile("pmd.xml"));

        ProcessUtils.execProgram(getBaseDir(), getWriter(), "java", "-classpath",
                createClasspath(getFile("pmd.jar"), getFilePrefix("jaxen"), getFilePrefix("asm"),
                        getFile("backport-util-concurrent.jar")),
                "net.sourceforge.pmd.PMD", getDestFile("src").getAbsolutePath(), "xml", file.getAbsolutePath(),

                "-shortnames", "-targetjdk", LimyQalabUtils.getJdkVersion(getEnv().getJavaProject()),
                "-encoding", getEncoding());
        FileUtils.writeByteArrayToFile(getDestFile("pmd_report.xml"), getWriter().toString().getBytes("UTF-8"));

    } catch (IOException e) {
        LimyEclipseUtils.log(e);
    }

    outputReport("pmd");

}