List of usage examples for org.apache.commons.io FileUtils writeByteArrayToFile
public static void writeByteArrayToFile(File file, byte[] data) throws IOException
From source file:org.limy.eclipse.qalab.action.part.CalcPmdCpdAction.java
@Override protected void makeReport() throws CoreException { try {/*w w w .ja v a2 s . c om*/ ProcessUtils.execProgram(getBaseDir(), getWriter(), "java", "-classpath", createClasspath(getFile("pmd.jar"), getFilePrefix("jaxen"), getFilePrefix("asm"), getFile("backport-util-concurrent.jar")), "net.sourceforge.pmd.cpd.CPD", "--minimum-tokens", "50", "--format", "net.sourceforge.pmd.cpd.XMLRenderer", "--charset", getEncoding(), "--files", getDestFile("src").getAbsolutePath()); FileUtils.writeByteArrayToFile(getDestFile("pmd_cpd_report.xml"), getWriter().toString().getBytes("UTF-8")); } catch (IOException e) { LimyEclipseUtils.log(e); } VmParam param = new VmParam("minimumTokenCount", "50"); outputReport("pmd_cpd", param); }
From source file:org.limy.eclipse.qalab.action.toolbar.AbstractPartAction.java
public void run(final IAction action) { Job job = new Job(getClass().getSimpleName()) { @Override//from w w w . ja va 2 s .c om protected IStatus run(IProgressMonitor monitor) { try { progressMonitor = monitor; makeReport(); LimyUIUtils.openBrowser(getReportHtml().toURI().toURL()); // 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.outline.sequence.SequenceImageCreator.java
/** * V?[PX?}?? layoutData, pngFile ?o?B/* www . ja v a 2s. c o m*/ * @param root V?[PX?}Bean * @throws IOException I/OO * @throws ParserException */ private void writeSequence(SequenceBean root) throws IOException, ParserException { StringWriter out = new StringWriter(); Context context = new VelocityContext(); context.put("root", root); VelocitySupport.write(new File(LimyQalabPlugin.getDefault().getPluginRoot(), "resource/sequence/index.vm") .getAbsolutePath(), context, out); File txtFile = LimyQalabUtils.createTempFile(env.getProject(), "sequence.txt"); pngFile = LimyQalabUtils.createTempFile(env.getProject(), "sequence.png"); FileUtils.writeByteArrayToFile(txtFile, out.toString().getBytes()); Parser parser = ParserFactory.getInstance().getDefaultParser(); NodeFactory nodeFactory = ParserFactory.getInstance().getNodeFactoryForParser(parser); Diagram diagram = new Diagram(parser, nodeFactory); PushbackReader reader = new PushbackReader(new FileReader(txtFile)); try { diagram.parse(reader); } finally { reader.close(); } Model model = new Model(new ExceptionHandler() { public void exception(Exception e) { e.printStackTrace(); } }, diagram); BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bi.createGraphics(); layoutData = new LayoutData(new SwingStringMeasure(graphics)); diagram.layout(layoutData); int height = layoutData.getHeight(); int width = layoutData.getWidth(); BufferedImage png = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D pngGraphics = png.createGraphics(); pngGraphics.setClip(0, 0, width, height); Map<Key, Object> hintsMap = new HashMap<Key, Object>(); hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); pngGraphics.addRenderingHints(hintsMap); pngGraphics.setBackground(Prefs.getColorValue(Prefs.BACKGROUND_COLOR)); pngGraphics.fillRect(0, 0, width, height); SwingPainter painter = new SwingPainter(); painter.setGraphics(pngGraphics); model.layout(layoutData); layoutData.paint(painter); ImageIO.write(png, "png", pngFile); }
From source file:org.limy.eclipse.qalab.task.Java2HtmlTask.java
/** * t@C\pindex.htmlt@C???B//from w w w .j av a 2s .c o m * @param classNames JavaSNX * @throws IOException */ private void createIndexHtml(Collection<String> classNames) throws IOException { StringBuilder buff = new StringBuilder(); appendLine(buff, "<html><body>"); appendLine(buff, "<h1>Java Source List</h1>"); for (String name : classNames) { name = name.substring(0, name.length() - 5); String className = name.replaceAll("\\\\", "."); className = className.replaceAll("/", "."); appendLine(buff, "<a href=\"" + name + ".html\">" + className + "</a><br>"); } appendLine(buff, "</body></html>"); FileUtils.writeByteArrayToFile(new File(destDir, "index.html"), buff.toString().getBytes()); }
From source file:org.limy.lrd.admin.AddRepositoryAction.java
/** * ?????// w ww .ja v a2 s. com * @param bean * @throws LrdException * @throws IOException */ private void copyDefaultTemplateFiles(RepositoryBean bean) throws LrdException, IOException { File baseDir = bean.getLocalContentFile(); // ???????? LrdRepository repository = bean.getRepository(); LrdNode root = repository.getDirectoryRoot(); LrdNode node = root.searchSubNode(".template"); if (node != null) { Collection<String> lrdPaths = new ArrayList<String>(); for (LrdNode child : node.getSubNodes()) { for (LrdNode file : child.getSubNodes()) { lrdPaths.add(file.getPath().getRelativePath()); } } CommitFileInfo[] files = repository.getRepositoryFiles(lrdPaths.toArray(new String[lrdPaths.size()])); for (CommitFileInfo file : files) { FileUtils.writeByteArrayToFile(new File(baseDir, file.getPath()), file.getContents()); } return; } for (File file : WebworkUtils.getFile("template/vm").listFiles((FileFilter) FileFileFilter.FILE)) { FileUtils.copyFile(file, new File(baseDir, ".template/vm/" + file.getName())); } for (File file : WebworkUtils.getFile("template/style").listFiles((FileFilter) FileFileFilter.FILE)) { FileUtils.copyFile(file, new File(baseDir, ".template/style/" + file.getName())); } }
From source file:org.limy.lrd.repository.file.LrdFileRepository.java
private void writeFiles(CommitFileInfo[] commitInfos, boolean force) throws LrdException { for (CommitFileInfo info : commitInfos) { File file = getFile(info.getPath(), force); try {//from w w w . j a va 2 s . c o m FileUtils.writeByteArrayToFile(file, info.getContents()); } catch (IOException e) { throw new LrdException(e); } } }
From source file:org.mabb.fontverter.opentype.DebugGlyphDrawer.java
@Test public void given_type0_withCFF_HelveticaNeueBug() throws Exception { PDDocument doc = PDDocument.load(TestUtils.readTestFile("pdf/HorariosMadrid_Segovia.pdf")); PDFont rawType0Font = extractFont(doc, "TCQDAA+HelveticaNeue-Light-Identity-H"); OpenTypeFont font = (OpenTypeFont) PdfFontExtractor.convertType0FontToOpenType((PDType0Font) rawType0Font); TestUtils.saveTempFile(font.getData(), "TCQDAA+HelveticaNeue-Light-Identity-H.ttf"); FileUtils.writeByteArrayToFile( new File("C:/projects/Pdf2Dom/fontTest/TCQDAA+HelveticaNeue-Light-Identity-H.ttf"), font.getData()); List<TtfGlyph> glyphs = font.getGlyfTable().getNonEmptyGlyphs(); TtfGlyph glyph = glyphs.get(1);//from www . java2s . c o m List<TtfInstruction> instructions = glyph.getInstructions(); DebugGlyphDrawer.drawGlyph(glyph); }
From source file:org.mabb.fontverter.opentype.TestOpenTypeFont.java
@Test public void given_OTF_without_an_OS2WindowsMetricsTable_thenNormalize_addsOS2Table() throws IOException { FVFont font = FontVerter.readFont(TestUtils.TEST_PATH + "Missing-OS2WinTable.otf"); font.normalize();/* w w w. j a v a2 s . c o m*/ OpenTypeFont otfFont = ((OpenTypeFont) font); Assert.assertTrue(font.isValid()); Assert.assertTrue(otfFont.getOs2() != null); FileUtils.writeByteArrayToFile(new File(TestUtils.tempOutputPath + "Fixed-Missing-OS2WinTable.otf"), font.getData()); }
From source file:pl.nask.hsn2.task.CuckooTask.java
private File downloadFile(Long contentId) throws StorageException, ResourceException { try {/*from ww w .j a v a2s .c o m*/ byte[] fileInByte = IOUtils.toByteArray(jobContext.getFileAsInputStream(contentId)); String fileName = data.getString("filename"); if (fileName == null) { fileName = DigestUtils.md5Hex(fileInByte); } File file = new File(cuckooProcPath, fileName); FileUtils.writeByteArrayToFile(file, fileInByte); return file; } catch (IOException e) { throw new ResourceException(e.getMessage(), e); } }