List of usage examples for org.apache.commons.io FileUtils deleteQuietly
public static boolean deleteQuietly(File file)
From source file:com.linkedin.pinot.tools.segment.converter.PinotSegmentConvertCommand.java
@Override public boolean execute() throws Exception { // Make sure output directory is empty. File outputDir = new File(_outputDir); if (outputDir.exists()) { if (_overwrite) { if (!FileUtils.deleteQuietly(outputDir)) { throw new RuntimeException("Output directory: " + outputDir.getAbsolutePath() + " already exists and cannot be deleted."); }/*from w w w.j a v a 2s . c o m*/ } else { throw new RuntimeException("Output directory: " + outputDir.getAbsolutePath() + " already exists and overwrite flag is not set."); } } if (!outputDir.mkdirs()) { throw new RuntimeException("Output directory: " + outputDir.getAbsolutePath() + " cannot be created."); } File tempDir = new File(outputDir, TEMP_DIR_NAME); try { // Add all segments to the segment path map. Map<String, String> segmentPath = new HashMap<>(); File dataDir = new File(_dataDir); File[] files = dataDir.listFiles(); if (files == null || files.length == 0) { throw new RuntimeException("Data directory does not contain any files."); } for (File file : files) { String fileName = file.getName(); if (file.isDirectory()) { // Uncompressed segment. if (segmentPath.containsKey(fileName)) { throw new RuntimeException("Multiple segments with the same segment name: " + fileName); } segmentPath.put(fileName, file.getAbsolutePath()); } else if (fileName.toLowerCase().endsWith(".tar.gz") || fileName.toLowerCase().endsWith(".tgz")) { // Compressed segment. File segment = TarGzCompressionUtils.unTar(file, new File(tempDir, fileName)).get(0); String segmentName = segment.getName(); if (segmentPath.containsKey(segmentName)) { throw new RuntimeException("Multiple segments with the same segment name: " + fileName); } segmentPath.put(segmentName, segment.getAbsolutePath()); } } // Do the conversion according to the output format. for (Map.Entry<String, String> entry : segmentPath.entrySet()) { String segmentName = entry.getKey(); String inputPath = entry.getValue(); String outputPath = new File(outputDir, segmentName).getAbsolutePath(); switch (FileFormat.valueOf(_outputFormat.toUpperCase())) { case AVRO: outputPath += ".avro"; new PinotSegmentToAvroConverter(inputPath, outputPath).convert(); break; case CSV: outputPath += ".csv"; new PinotSegmentToCsvConverter(inputPath, outputPath, _csvDelimiter, _csvDelimiter, _csvWithHeader).convert(); break; case JSON: outputPath += ".json"; new PinotSegmentToJsonConverter(inputPath, outputPath).convert(); break; default: throw new RuntimeException("Unsupported conversion to file format: " + _outputFormat); } LOGGER.info("Finish converting segment: {} into file: {}", segmentName, outputPath); } return true; } finally { FileUtils.deleteQuietly(tempDir); } }
From source file:com.machinepublishers.jbrowserdriver.Context.java
private void setUpUserDataDir() { FileUtils.deleteQuietly(autoUserDataDirectory.get()); autoUserDataDirectory.set(null);/*from www. ja v a2s . co m*/ if (SettingsManager.settings().userDataDirectory() == null) { //Temporary because cookies aren't saved too. //App has its own temp dir, so this won't collide with other instances. try { userDataDirectory.set(Files.createTempDirectory("jbd_userdata_").toFile()); autoUserDataDirectory.set(userDataDirectory.get()); } catch (IOException e) { Util.handleException(e); } } else { userDataDirectory.set(SettingsManager.settings().userDataDirectory()); userDataDirectory.get().mkdirs(); } }
From source file:com.spotify.helios.servicescommon.coordination.ZooKeeperUpdatingPersistentDirectoryTest.java
@After public void tearDown() throws Exception { sut.stopAsync().awaitTerminated();/*from w ww .ja v a2 s . c o m*/ zk.close(); FileUtils.deleteQuietly(stateFile.toFile()); FileUtils.deleteQuietly(backupDir.toFile()); }
From source file:io.apiman.manager.api.migrator.DataMigratorTest.java
private void doTest(String fileToMigrate, String expectedResultFile, String versionToMigrateTo) throws Exception { Version version = new Version(); setVersion(version, versionToMigrateTo); StringBuilderLogger logger = new StringBuilderLogger(); File tempOutputFile = File.createTempFile("_apiman", "tst"); tempOutputFile.deleteOnExit();/*w ww .j a v a 2 s .c o m*/ try { DataMigrator migrator = new DataMigrator(); migrator.setLogger(logger); migrator.setVersion(version); InputStream input = getClass().getClassLoader().getResourceAsStream(fileToMigrate); OutputStream output = new FileOutputStream(tempOutputFile); // Migrate the data! migrator.migrate(input, output); JsonCompare compare = new JsonCompare(); compare.setArrayOrdering(JsonArrayOrderingType.strict); compare.setIgnoreCase(false); compare.setMissingField(JsonMissingFieldType.fail); try (FileInputStream actual = new FileInputStream(tempOutputFile); InputStream expected = getClass().getClassLoader().getResourceAsStream(expectedResultFile);) { compare.assertJson(expected, actual); } } finally { FileUtils.deleteQuietly(tempOutputFile); } }
From source file:gov.usgs.cida.coastalhazards.rest.data.util.MetadataUtilTest.java
@After public void tearDown() { // FileUtils.listFiles(workDir, null, true).stream().forEach((file) -> { //FileUtils.deleteQuietly(file); //});/*from w w w.java 2 s . c o m*/ Collection<File> files = FileUtils.listFiles(workDir, null, true); for (File file : files) { FileUtils.deleteQuietly(file); } }
From source file:net.sourceforge.cobertura.test.IgnoreMethodAnnotationFunctionalTest.java
@Before public void setUp() throws IOException { FileUtils.deleteQuietly(new File(TestUtils.getTempDir(), "src")); FileUtils.deleteQuietly(new File(TestUtils.getTempDir(), "instrument")); }
From source file:de.uzk.hki.da.utils.FolderUtils.java
public static boolean deleteQuietlySafe(File file) { boolean result = FileUtils.deleteQuietly(file); if (!result) { waitToCompleteNFSAwareFileOperation(); result = FileUtils.deleteQuietly(file); }/*from w ww . jav a 2 s .c o m*/ return result; }
From source file:com.linkedin.pinot.core.plan.maker.MetadataAndDictionaryAggregationPlanMakerTest.java
@BeforeTest public void buildSegment() throws Exception { FileUtils.deleteQuietly(INDEX_DIR); FileUtils.deleteQuietly(INDEX_DIR_STARTREE); // Get resource file path. URL resource = getClass().getClassLoader().getResource(AVRO_DATA); Assert.assertNotNull(resource);//from w w w. ja v a 2 s . com String filePath = resource.getFile(); // Build the segment schema. Schema schema = new Schema.SchemaBuilder().setSchemaName("testTable") .addMetric("column1", FieldSpec.DataType.INT).addMetric("column3", FieldSpec.DataType.INT) .addSingleValueDimension("column5", FieldSpec.DataType.STRING) .addSingleValueDimension("column6", FieldSpec.DataType.INT) .addSingleValueDimension("column7", FieldSpec.DataType.INT) .addSingleValueDimension("column9", FieldSpec.DataType.INT) .addSingleValueDimension("column11", FieldSpec.DataType.STRING) .addSingleValueDimension("column12", FieldSpec.DataType.STRING) .addMetric("column17", FieldSpec.DataType.INT).addMetric("column18", FieldSpec.DataType.INT) .addTime("daysSinceEpoch", 1, TimeUnit.DAYS, DataType.INT).build(); // Create the segment generator config. SegmentGeneratorConfig segmentGeneratorConfig = new SegmentGeneratorConfig(schema); segmentGeneratorConfig.setInputFilePath(filePath); segmentGeneratorConfig.setTableName("testTable"); segmentGeneratorConfig.setSegmentName(SEGMENT_NAME); segmentGeneratorConfig.setOutDir(INDEX_DIR.getAbsolutePath()); segmentGeneratorConfig.setInvertedIndexCreationColumns( Arrays.asList("column6", "column7", "column11", "column17", "column18")); // Build the index segment. SegmentIndexCreationDriver driver = new SegmentIndexCreationDriverImpl(); driver.init(segmentGeneratorConfig); driver.build(); // Star Tree segment // Build the segment schema. schema = new Schema.SchemaBuilder().setSchemaName("testTableStarTree") .addMetric("column1", FieldSpec.DataType.INT).addMetric("column3", FieldSpec.DataType.INT) .addSingleValueDimension("column5", FieldSpec.DataType.STRING) .addSingleValueDimension("column6", FieldSpec.DataType.INT) .addSingleValueDimension("column7", FieldSpec.DataType.INT) .addSingleValueDimension("column9", FieldSpec.DataType.INT) .addSingleValueDimension("column11", FieldSpec.DataType.STRING) .addSingleValueDimension("column12", FieldSpec.DataType.STRING) .addMetric("column17", FieldSpec.DataType.INT).addMetric("column18", FieldSpec.DataType.INT) .addTime("daysSinceEpoch", 1, TimeUnit.DAYS, DataType.INT).build(); // Create the segment generator config. segmentGeneratorConfig = new SegmentGeneratorConfig(schema); segmentGeneratorConfig.setInputFilePath(filePath); segmentGeneratorConfig.setTableName("testTableStarTree"); segmentGeneratorConfig.setSegmentName(SEGMENT_NAME_STARTREE); segmentGeneratorConfig.setOutDir(INDEX_DIR_STARTREE.getAbsolutePath()); segmentGeneratorConfig.enableStarTreeIndex(new StarTreeIndexSpec()); // Build the index segment. driver = new SegmentIndexCreationDriverImpl(); driver.init(segmentGeneratorConfig); driver.build(); }
From source file:net.sf.diningout.app.AppApplication.java
@Override public void onVersionChanged(int oldCode, String oldName, int newCode, String newName) { PreferenceManager.setDefaultValues(this, R.xml.preferences, true); if (oldCode > 0 && oldCode < 110) { // first so that prefs are moved to right location HashSet<String> notifs = new HashSet<>(Prefs.getStringSet(this, SHOW_NOTIFICATIONS)); notifs.add(getString(R.string.at_restaurant_notifications_value)); Prefs.putStringSet(this, SHOW_NOTIFICATIONS, notifs); migrateAppPrefs();/*w w w. j a v a 2s .c om*/ } TokenService.refreshTokens(this); if (oldCode < 100) { // delete pre-1.0.0 restaurant images File file = getExternalFilesDir(null); if (file != null) { FileUtils.deleteQuietly(new File(file, "images")); } } if (oldCode == 0) { // nothing else to do if run for the first time return; } if (oldCode < 107) { // get colors of existing photos startService(new Intent(this, RestaurantColorService.class)); startService(new Intent(this, FriendColorService.class)); } if (oldCode < 109) { startService(new Intent(this, RestaurantsRefreshService.class)); } if (oldCode < 112) { startService(new Intent(this, ContactNormalisedNameService.class)); } if (oldCode < 113 && TextUtils.isEmpty(Prefs.getString(this, DISTANCE_UNIT))) { Prefs.putString(this, DISTANCE_UNIT, getString(R.string.automatic_value)); } }
From source file:com.linkedin.pinot.segments.v1.creator.DictionariesTest.java
@BeforeClass public static void before() throws Exception { final String filePath = TestUtils .getFileFromResourceUrl(DictionariesTest.class.getClassLoader().getResource(AVRO_DATA)); if (INDEX_DIR.exists()) { FileUtils.deleteQuietly(INDEX_DIR); }/*from w w w.j a v a 2 s. c o m*/ final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns( new File(filePath), INDEX_DIR, "time_day", TimeUnit.DAYS, "test"); final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null); driver.init(config); driver.build(); final Schema schema = AvroUtils.extractSchemaFromAvro(new File(filePath)); final DataFileStream<GenericRecord> avroReader = AvroUtils.getAvroReader(new File(filePath)); final org.apache.avro.Schema avroSchema = avroReader.getSchema(); final String[] columns = new String[avroSchema.getFields().size()]; int i = 0; for (final Field f : avroSchema.getFields()) { columns[i] = f.name(); i++; } uniqueEntries = new HashMap<String, Set<Object>>(); for (final String column : columns) { uniqueEntries.put(column, new HashSet<Object>()); } while (avroReader.hasNext()) { final GenericRecord rec = avroReader.next(); for (final String column : columns) { Object val = rec.get(column); if (val instanceof Utf8) { val = ((Utf8) val).toString(); } uniqueEntries.get(column) .add(getAppropriateType(schema.getFieldSpecFor(column).getDataType(), val)); } } }