List of usage examples for org.apache.commons.io FileUtils forceMkdir
public static void forceMkdir(File directory) throws IOException
From source file:dk.netarkivet.systemtest.SeleniumTest.java
@AfterMethod /**/*w w w .ja v a 2 s . c o m*/ * Takes care of failure situations. This includes: <ol> * <li> Generate a a screen dump of the page failing the test. * <ol> * * This method is called by TestNG. * * @param result The result which TestNG will inject */ public void onFailure(ITestResult result) { if (!result.isSuccess()) { log.info("Test failure, dumping screenshot as " + "target/failurescreendumps/" + result.getMethod() + ".png"); File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); try { FileUtils.forceMkdir(new File("target")); FileUtils.copyFile(scrFile, new File("target/failurescreendumps/" + result.getMethod() + ".png")); } catch (IOException e) { log.error("Failed to save screendump on error"); } } }
From source file:com.alibaba.jstorm.cluster.StormConfig.java
public static String supervisor_stormdist_root(Map conf) throws IOException { String ret = stormdist_path(supervisor_local_dir(conf)); FileUtils.forceMkdir(new File(ret)); return ret;/*ww w. ja va2s . c o m*/ }
From source file:eu.openanalytics.rsb.component.AdminResourceTestCase.java
@Test public void getApplicationUnawareCatalog() throws Exception { final File fakeCatalogDir = new File(FileUtils.getTempDirectory(), "rsb_test_catalog"); FileUtils.forceMkdir(fakeCatalogDir); final Map<Pair<CatalogSection, File>, List<File>> fakeCatalog = Collections .singletonMap(Pair.of(CatalogSection.R_SCRIPTS, fakeCatalogDir), Collections.<File>emptyList()); when(catalogManager.getCatalog(null)).thenReturn(fakeCatalog); final Catalog catalog = adminResource.getCatalogIndex(null, httpHeaders, uriInfo); assertThat(catalog, is(not(nullValue()))); assertThat(catalog.getDirectories().size(), is(1)); }
From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java
@Test public void testZipDirectory() throws Exception { FileUtils.forceMkdir(new File("target/Z-testfiles/source")); FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"), new File("target/Z-testfiles/source/CP0-input.csv")); FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"), new File("target/Z-testfiles/source/CP1-input.csv")); String aTargetFilename = "target/Z2-input.zip"; ZipFilesTasklet aTasklet = new ZipFilesTasklet(); aTasklet.setSourceBaseDirectory(new FileSystemResource("target/Z-testfiles/")); FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory(); aSourceFactory.setPattern("file:target/Z-testfiles/source/"); aTasklet.setSourceFactory(aSourceFactory); ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory(); aDestinationFactory.setExpression(aTargetFilename); aTasklet.setDestinationFactory(aDestinationFactory); assertFalse(new File(aTargetFilename).exists()); StepContribution aStepContribution = mock(StepContribution.class); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null)); verify(aStepContribution, times(3)).incrementReadCount(); verify(aStepContribution, times(3)).incrementWriteCount(1); assertTrue(new File(aTargetFilename).exists()); ZipFile aZipFile = new ZipFile(new File(aTargetFilename)); Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries(); assertTrue(aEntries.hasMoreElements()); assertEquals("source", aEntries.nextElement().getName()); assertTrue(aEntries.hasMoreElements()); assertEquals("source/CP0-input.csv", aEntries.nextElement().getName()); assertTrue(aEntries.hasMoreElements()); assertEquals("source/CP1-input.csv", aEntries.nextElement().getName()); assertFalse(aEntries.hasMoreElements()); aZipFile.close();/*ww w . ja v a 2s .com*/ }
From source file:com.thoughtworks.go.server.initializers.PluginsInitializerTest.java
@Test public void shouldDeleteOldPluginDirectories() throws Exception { File pluginsBundles = new File("plugins_bundles"); File pluginsNew = new File("plugins-new"); try {//www. ja v a 2 s . c o m FileUtils.forceMkdir(pluginsBundles); FileUtils.forceMkdir(pluginsNew); pluginsInitializer.initialize(); assertThat("should have cleaned up plugins_bundles folder", pluginsBundles.exists(), is(false)); assertThat("should have cleaned up plugins-new folder", pluginsNew.exists(), is(false)); } finally { FileUtils.deleteQuietly(pluginsBundles); FileUtils.deleteQuietly(pluginsNew); } }
From source file:main.java.miro.validator.fetcher.RsyncFetcher.java
private void setupDirectories() throws IOException { File baseDirFile = new File(baseDirectory); FileUtils.forceMkdir(baseDirFile); FileUtils.cleanDirectory(baseDirFile); prefetchURIstorage.getParentFile().mkdirs(); prefetchURIstorage.createNewFile();/* w ww . j ava 2 s. com*/ }
From source file:com.xauto.ux.Emf2.java
@SuppressWarnings("deprecation") public static void extractPicturesFromDoc(String docName) throws Exception { Document doc = new Document(docName + ".docx"); Integer emfOrWmfIndex = 1; Integer pngOrJpegIndex = 100; Integer bmpOrPictIndex = 10000; Integer otherIndex = 1000; String outDir = "out" + File.separator + docName + File.separator; FileUtils.forceMkdir(new File(outDir)); FileWriter html = new FileWriter(outDir + "out.html"); html.write(//from w w w . java 2 s .co m "<html>\n<head><meta http-equiv=\"x-ua-compatible\" content=\"IE=edge,chrome=1\"></head><body>\n"); for (AsposeDrawingType type : AsposeDrawingType.values()) { Node[] drawArray = doc.getChildNodes(type.code(), true).toArray(); int index = 0; logger.info("type={};count={}", type, drawArray.length); for (Node n : drawArray) { WordDrawing node = null; DrawingML dml = null; Shape s = null; if (n instanceof Shape) { s = (Shape) n; node = new WordDrawing(s); } else if (n instanceof DrawingML) { dml = (DrawingML) n; node = new WordDrawing(dml); } index++; IImageData img = node.getImageData(); BufferedImage bi = img.toImage(); AposeWordImageType asposeWordImageType = AposeWordImageType.fromCode(img.getImageType()); String extn = null; String trimmedDrawingName = node.getName().replace(" ", "") + index; ImageSize is = img.getImageSize(); long resolution = 600; int scale = 1000; Graphics2D gd = bi.createGraphics(); gd.getClipBounds(); int jpegQual = 70; boolean antiAlias = true; boolean highQualityRendering = true; try { extn = FileFormatUtil.imageTypeToExtension(img.getImageType()); } catch (IllegalArgumentException e) { extn = "unknown"; } String drawingName = node.getName(); if (StringUtils.isBlank(drawingName)) { if (node.getNode() instanceof Shape) { Shape s = (Shape) node.getNode(); Node cell = null; Node parent = s.getParentNode(); while (parent.getNodeType() != NodeType.ROW) { if (parent.getNodeType() == NodeType.CELL) { cell = parent; } parent = parent.getParentNode(); } Row picturesRow = (Row) parent; Row captionsRow = (Row) picturesRow.getPreviousSibling(); Node[] currentPicturesRowCells = picturesRow.getChildNodes(NodeType.CELL, true).toArray(); int foundIndex = 0; for (Node n : currentPicturesRowCells) { if (n == cell) { break; } foundIndex++; } Cell captionCell = (Cell) captionsRow.getChild(NodeType.CELL, foundIndex, true); StringBuilder sb = new StringBuilder(); Paragraph[] ps = captionCell.getParagraphs().toArray(); for (Paragraph p : ps) { Run[] rs = p.getRuns().toArray(); for (Run r : rs) { r.getDirectRunAttrsCount(); sb.append(r.getText()); } } drawingName = sb.toString().replace("SEQ Figure \\* ARABIC ", ""); } } logger.debug( "imageType={};name={};hasImage()={};imageByteSize={};isLink={};imageSize.Width={};imageSize.Height={};" + "imageSize.HorRes={};imageSize.VertRes={};imageSize.WPoints={};imageSize.HPoints={};" + "bufferedImageType={}; biHeight={}; biWidth={}; trimmedDrawingName={}; extn={};" + "" + "bufferedImageInfo={};drawInfo={}", asposeWordImageType, drawingName, img.hasImage(), img.getImageBytes() == null ? 0 : img.getImageBytes().length, img.isLink(), is.getWidthPixels(), is.getHeightPixels(), is.getHorizontalResolution(), is.getVerticalResolution(), is.getWidthPoints(), is.getHeightPoints(), AwtImageType.fromCode(bi.getType()), bi.getHeight(), bi.getWidth(), trimmedDrawingName, extn, bi.toString(), node.toString()); if (StringUtils.isBlank(node.getName())) { if (dml != null) { dml.getParentNode(); logger.debug("getAncestor={}", dml.getAncestor(DocumentProperty.class)); } else if (s != null) { s.getExpandedRunPr_IInline(54); logger.debug(s.toTxt() + s.getText()); @SuppressWarnings("unchecked") NodeCollection<Node> ns = s.getChildNodes(); while (ns.iterator().hasNext()) { Node n1 = (Node) ns.iterator().next(); n1.getText(); } logger.debug("shape={}", s.getAncestor(DocumentProperty.class)); s.getParentParagraph(); } } if (asposeWordImageType == AposeWordImageType.UNKNOWN) { otherIndex++; continue; } if (img == null || asposeWordImageType == AposeWordImageType.NO_IMAGE) { continue; } if (asposeWordImageType == AposeWordImageType.EMF || asposeWordImageType == AposeWordImageType.WMF) { ShapeRenderer sr = node.getShapeRenderer(); img.save(outDir + trimmedDrawingName + extn); PngOptions pngOptions = new PngOptions(); if (asposeWordImageType == AposeWordImageType.EMF) { EmfMetafileImage emf = new EmfMetafileImage(outDir + trimmedDrawingName + extn); emf.save(outDir + trimmedDrawingName + "_buffered_emf.png", pngOptions); } else { WmfMetafileImage wmf = new WmfMetafileImage(outDir + trimmedDrawingName + extn); wmf.save(outDir + trimmedDrawingName + "_buffered_emf.png", pngOptions); } trimmedDrawingName += "_" + scale + "_" + resolution + "_" + jpegQual + "_" + antiAlias + "_" + highQualityRendering; ImageSaveOptions pngSave = new ImageSaveOptions(com.aspose.words.SaveFormat.PNG); pngSave.setResolution(resolution); pngSave.setUseHighQualityRendering(highQualityRendering); pngSave.setDmlRenderingMode(DmlRenderingMode.DRAWING_ML); pngSave.setDmlEffectsRenderingMode(DmlEffectsRenderingMode.FINE); pngSave.setUseAntiAliasing(antiAlias); pngSave.setScale((float) scale / 1000); ImageSaveOptions jpgSave = new ImageSaveOptions(SaveFormat.JPEG); jpgSave.setUseHighQualityRendering(true); jpgSave.setResolution(resolution); jpgSave.setJpegQuality(jpegQual); jpgSave.setScale((float) scale / 1000); sr.save(outDir + trimmedDrawingName + ".png", pngSave); BufferedImage savedPNG = ImageIO.read(new File(outDir + trimmedDrawingName + ".png")); BufferedImage resizedFromSaved = Scalr.resize(savedPNG, Method.ULTRA_QUALITY, Mode.FIT_TO_WIDTH, 435); BufferedImage resizedFromBi = Scalr.resize(bi, Method.ULTRA_QUALITY, Mode.FIT_TO_WIDTH, 435); ImageIO.write(bi, "png", new File(outDir + trimmedDrawingName + "_buffered.png")); ImageIO.write(resizedFromSaved, "png", new File(outDir + trimmedDrawingName + "_resized_from_saved_scalr_antialias_435.png")); ImageIO.write(resizedFromBi, "png", new File(outDir + trimmedDrawingName + "_resized_from_bi_scalr_antialias_435.png")); //sr.save(outDir+trimmedDrawingName+".jpg", jpgSave); html.write("\t<div>\n\t\t\n\t\t<br>\n\t\t<hr><p align=center>.SVG figure: " + trimmedDrawingName + "</p>\n\t\t<hr>\n\t\t<br>\n\t\t<br>\n\t\t<img src=\"" + trimmedDrawingName + ".svg\" width=\"100%\" />\n\t</div>\n"); //convertToSVG(outputDir + docId + "\\", trimmedDrawingName, extn); emfOrWmfIndex++; } else if (asposeWordImageType == AposeWordImageType.PNG || asposeWordImageType == AposeWordImageType.JPEG) { ShapeRenderer sr = node.getShapeRenderer(); ImageSaveOptions pngSave = new ImageSaveOptions(com.aspose.words.SaveFormat.PNG); pngSave.setResolution(resolution); pngSave.setUseHighQualityRendering(highQualityRendering); pngSave.setDmlRenderingMode(DmlRenderingMode.DRAWING_ML); pngSave.setDmlEffectsRenderingMode(DmlEffectsRenderingMode.FINE); pngSave.setUseAntiAliasing(antiAlias); pngSave.setScale((float) scale / 1000); img.save(outDir + trimmedDrawingName + extn); sr.save(outDir + trimmedDrawingName + "_DIRECT" + extn, pngSave); if (is.getHeightPoints() > 99) { html.write("\t<div>\n\t\t\n\t\t<br>\n\t\t<hr><p align=center>" + extn.toUpperCase() + " figure: " + trimmedDrawingName + "</p>\n\t\t<hr>\n\t\t<br>\n\t\t<br>\n\t\t<img src=\"" + trimmedDrawingName + extn + "\" width=\"100%\" />\n\t</div>\n"); } pngOrJpegIndex++; } else if (asposeWordImageType == AposeWordImageType.BMP || asposeWordImageType == AposeWordImageType.PICT) { img.save(outDir + bmpOrPictIndex + extn); bmpOrPictIndex++; } else { logger.info( "PICT type={}; isLink={}; isLinkOnly={}; imageSize={}; sourceFileName={}; hasImage={}", asposeWordImageType, img.isLink(), img.isLinkOnly(), img.getImageSize().getHorizontalResolution(), img.getSourceFullName(), img.hasImage()); } } } html.write("</body>\n</html>"); html.close(); }
From source file:com.linkedin.pinot.segments.v1.creator.BitmapInvertedIndexCreatorTest.java
@Test public void testMultiValue() throws IOException { boolean singleValue = false; String colName = "multi_value_col"; FieldSpec spec = new DimensionFieldSpec(colName, DataType.INT, singleValue); int numDocs = 20; int[][] data = new int[numDocs][]; int maxLength = 10; int cardinality = 10; File indexDirHeap = new File("/tmp/indexDirHeap"); FileUtils.forceMkdir(indexDirHeap); indexDirHeap.mkdirs();/*from w w w . ja v a 2 s .co m*/ File indexDirOffHeap = new File("/tmp/indexDirOffHeap"); FileUtils.forceMkdir(indexDirOffHeap); indexDirOffHeap.mkdirs(); File bitmapIndexFileOffHeap = new File(indexDirOffHeap, colName + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION); File bitmapIndexFileHeap = new File(indexDirHeap, colName + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION); // GENERATE RANDOM MULTI VALUE DATA SET Random r = new Random(); Map<Integer, Set<Integer>> postingListMap = new HashMap<>(); for (int i = 0; i < cardinality; i++) { postingListMap.put(i, new LinkedHashSet<Integer>()); } int totalNumberOfEntries = 0; for (int docId = 0; docId < numDocs; docId++) { int length = r.nextInt(maxLength); data[docId] = new int[length]; totalNumberOfEntries += length; for (int j = 0; j < length; j++) { data[docId][j] = r.nextInt(cardinality); postingListMap.get(data[docId][j]).add(docId); } LOGGER.debug("docId:" + docId + " dictId:" + data[docId]); } for (int i = 0; i < cardinality; i++) { LOGGER.debug("Posting list for " + i + " : " + postingListMap.get(i)); } // GENERATE BITMAP USING OffHeapCreator and validate OffHeapBitmapInvertedIndexCreator offHeapCreator = new OffHeapBitmapInvertedIndexCreator(indexDirOffHeap, cardinality, numDocs, totalNumberOfEntries, spec); for (int i = 0; i < numDocs; i++) { offHeapCreator.add(i, data[i]); } offHeapCreator.seal(); validate(colName, bitmapIndexFileOffHeap, cardinality, postingListMap); // GENERATE BITMAP USING HeapCreator and validate HeapBitmapInvertedIndexCreator heapCreator = new HeapBitmapInvertedIndexCreator(indexDirHeap, cardinality, numDocs, totalNumberOfEntries, spec); for (int i = 0; i < numDocs; i++) { heapCreator.add(i, data[i]); } heapCreator.seal(); validate(colName, bitmapIndexFileHeap, cardinality, postingListMap); // assert that the file sizes and contents are the same Assert.assertEquals(bitmapIndexFileHeap.length(), bitmapIndexFileHeap.length()); Assert.assertTrue(FileUtils.contentEquals(bitmapIndexFileHeap, bitmapIndexFileHeap)); FileUtils.deleteQuietly(indexDirHeap); FileUtils.deleteQuietly(indexDirOffHeap); }
From source file:fr.acxio.tools.agia.file.pdf.SplitPDFTasklet.java
private void writeDocument(PDDocument doc, String fileName) throws IOException, COSVisitorException { FileOutputStream output = null; COSWriter writer = null;//from www.ja v a 2s.c o m try { FileUtils.forceMkdir(new File(fileName).getAbsoluteFile().getParentFile()); output = new FileOutputStream(fileName); writer = new COSWriter(output); writer.write(doc); } finally { if (output != null) { output.close(); } if (writer != null) { writer.close(); } } }
From source file:com.linkedin.pinot.server.api.resources.ResourceTestHelper.java
public void addTable(String tableName) throws IOException, ConfigurationException { File directory = new File(INDEX_DIR, tableName); FileUtils.forceMkdir(directory); PropertiesConfiguration tableConfig = new PropertiesConfiguration(); tableConfig.setProperty("directory", tableName); tableConfig.setProperty("name", tableName); tableConfig.setProperty("dataManagerType", "offline"); tableConfig.setProperty("readMode", "heap"); FileBasedInstanceDataManager dataManager = (FileBasedInstanceDataManager) serverInstance .getInstanceDataManager();/*w w w .j ava 2 s . c om*/ dataManager.addTable(new TableDataManagerConfig(tableConfig)); }