List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.FullTextIndexerRunnable.java
public final void run() { final IndexMode indexMode = context.getIndexMode(); if (indexMode == IndexMode.NO_INDEX) { return;//from w w w . ja v a 2 s . c om } final Set<Class<?>> indexedEntities = indexedEntityFinder.getIndexedEntities(); // final Set<Class<?>> indexedEntities = new HashSet<Class<?>>(); // indexedEntities.add(ExternalDataPE.class); // indexedEntities.add(ExperimentPE.class); if (indexedEntities.size() == 0) { operationLog.info( String.format("No entity annotated with '%s' has been found.", Indexed.class.getSimpleName())); return; } Class<?> currentEntity = null; try { // timeout exceptions were observed for the default timeout when database was bigger IndexWriter.setDefaultWriteLockTimeout(3000); final File indexBase = new File(context.getIndexBase()); final File markerFile = new File(indexBase, FULL_TEXT_INDEX_MARKER_FILENAME); if (indexMode == IndexMode.SKIP_IF_MARKER_FOUND && markerFile.exists()) { operationLog .debug(String.format("Skipping indexing process as " + "marker file '%s' already exists.", markerFile.getAbsolutePath())); return; } final Session session = getSession(); final StopWatch stopWatch = new StopWatch(); for (final Class<?> indexedEntity : indexedEntities) { currentEntity = indexedEntity; stopWatch.reset(); stopWatch.start(); fullTextIndexer.doFullTextIndex(session, indexedEntity); stopWatch.stop(); operationLog .info(String.format("Indexing entity '%s' took %s.", indexedEntity.getName(), stopWatch)); } FileUtils.touch(markerFile); releaseSession(session); } catch (final Throwable th) { notificationLog .error(String.format("A problem has occurred while indexing entity '%s'.", currentEntity), th); } }
From source file:com.linkedin.pinot.core.segment.store.SegmentLocalFSDirectoryTest.java
@Test public void testStarTree() throws IOException, ConfigurationException { Assert.assertFalse(segmentDirectory.hasStarTree()); FileUtils.touch(new File(segmentDirectory.getPath().toFile(), V1Constants.STAR_TREE_INDEX_FILE)); String data = "This is star tree"; try (SegmentDirectory.Writer writer = segmentDirectory.createWriter(); OutputStream starTreeOstream = writer.starTreeOutputStream()) { starTreeOstream.write(data.getBytes()); }//from w w w . j a v a 2s . c o m try (SegmentDirectory.Reader reader = segmentDirectory.createReader(); InputStream starTreeIstream = reader.getStarTreeStream()) { byte[] fileDataBytes = new byte[data.length()]; starTreeIstream.read(fileDataBytes, 0, fileDataBytes.length); String fileData = new String(fileDataBytes); Assert.assertEquals(fileData, data); } try (SegmentDirectory.Writer writer = segmentDirectory.createWriter()) { writer.removeStarTree(); Assert.assertFalse(segmentDirectory.hasStarTree()); } }
From source file:com.linkedin.pinot.core.segment.index.loader.invertedindex.InvertedIndexHandler.java
private void createInvertedIndexForColumn(ColumnMetadata columnMetadata) throws IOException { String column = columnMetadata.getColumnName(); File inProgress = new File(indexDir, column + ".inv.inprogress"); File invertedIndexFile = new File(indexDir, column + V1Constants.Indexes.BITMAP_INVERTED_INDEX_FILE_EXTENSION); if (!inProgress.exists()) { // Marker file does not exist, which means last run ended normally. if (segmentWriter.hasIndexFor(column, ColumnIndexType.INVERTED_INDEX)) { // Skip creating inverted index if already exists. LOGGER.info("Found inverted index for segment: {}, column: {}", segmentName, column); return; }// w ww .ja v a 2 s .c om // Create a marker file. FileUtils.touch(inProgress); } else { // Marker file exists, which means last run gets interrupted. // Remove inverted index if exists. // For v1 and v2, it's the actual inverted index. For v3, it's the temporary inverted index. FileUtils.deleteQuietly(invertedIndexFile); } // Create new inverted index for the column. LOGGER.info("Creating new inverted index for segment: {}, column: {}", segmentName, column); int totalDocs = columnMetadata.getTotalDocs(); OffHeapBitmapInvertedIndexCreator creator = new OffHeapBitmapInvertedIndexCreator(indexDir, columnMetadata.getCardinality(), totalDocs, columnMetadata.getTotalNumberOfEntries(), columnMetadata.getFieldSpec()); try (DataFileReader fwdIndex = getForwardIndexReader(columnMetadata, segmentWriter)) { if (columnMetadata.isSingleValue()) { // Single-value column. FixedBitSingleValueReader svFwdIndex = (FixedBitSingleValueReader) fwdIndex; for (int i = 0; i < totalDocs; i++) { creator.add(i, svFwdIndex.getInt(i)); } } else { // Multi-value column. SingleColumnMultiValueReader mvFwdIndex = (SingleColumnMultiValueReader) fwdIndex; int[] dictIds = new int[columnMetadata.getMaxNumberOfMultiValues()]; for (int i = 0; i < totalDocs; i++) { int len = mvFwdIndex.getIntArray(i, dictIds); creator.add(i, dictIds, len); } } } creator.seal(); // For v3, write the generated inverted index file into the single file and remove it. if (segmentVersion == SegmentVersion.v3) { LoaderUtils.writeIndexToV3Format(segmentWriter, column, invertedIndexFile, ColumnIndexType.INVERTED_INDEX); } // Delete the marker file. FileUtils.deleteQuietly(inProgress); LOGGER.info("Created inverted index for segment: {}, column: {}", segmentName, column); }
From source file:it.geosolutions.geostore.services.rest.auditing.AuditingFilesManager.java
private void createOutputFile() { try {/*from w w w . j a va2 s . co m*/ LogUtils.info(logger, "Creating output file '%s'.", outputFile.getPath()); FileUtils.touch(outputFile); } catch (Exception exception) { throw new AuditingException(exception, "Error creating output file '%s'.", outputFile.getPath()); } }
From source file:com.ning.metrics.collector.processing.TestEventSpoolWriterFactory.java
private void testProcessLeftBelowFilesTooSoon() throws Exception { final EventSpoolWriterFactory factory = new EventSpoolWriterFactory( new HashSet<EventSpoolProcessor>(Arrays.asList(new NoWriteHadoopWriterFactory(null, config))), config, configFactory);//w w w .ja v a 2 s . c om factory.setCutoffTime(CUTOFF_TIME); FileUtils.touch(new File(lockDirectory.getPath() + "/some_file_which_should_be_sent_1")); FileUtils.touch(new File(lockDirectory.getPath() + "/some_file_which_should_be_sent_2")); FileUtils.touch(new File(quarantineDirectory.getPath() + "/some_other_file_which_should_be_sent")); Assert.assertEquals(FileUtils .listFiles(spoolDirectory, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter()) .size(), 3); Assert.assertTrue(spoolDirectory.exists()); Assert.assertTrue(tmpDirectory.exists()); Assert.assertTrue(lockDirectory.exists()); Assert.assertTrue(quarantineDirectory.exists()); // No sleep! factory.processLeftBelowFiles(); // No file should have been sent Assert.assertEquals(FileUtils .listFiles(spoolDirectory, FileFilterUtils.trueFileFilter(), FileFilterUtils.trueFileFilter()) .size(), 3); Assert.assertTrue(spoolDirectory.exists()); Assert.assertTrue(tmpDirectory.exists()); Assert.assertTrue(lockDirectory.exists()); Assert.assertTrue(quarantineDirectory.exists()); // We could even test the mapping in HDFS here (with the keys) Assert.assertEquals(hdfs.values().size(), 0); }
From source file:com.orange.mmp.dao.flf.DeliveryTicketDaoFlfImpl.java
public DeliveryTicket createOrUdpdate(DeliveryTicket deliveryTicket) throws MMPDaoException { if (deliveryTicket == null) { throw new MMPDaoException("missing or bad data access object"); }/*w w w .j a v a 2s . co m*/ OutputStream outProps = null; try { this.lock.lock(); File temp; if (deliveryTicket.getId() != null) { temp = new File(this.path, deliveryTicket.getId().concat(TMP_FILE_EXT)); if (!temp.exists()) throw new MMPDaoException("Invalid ticket id " + deliveryTicket.getId()); } else { temp = File.createTempFile(String.valueOf(Math.round(Math.random() * 10000)), null, new File(this.path)); } deliveryTicket.setId(temp.getName().split("\\.")[0]); deliveryTicket.setCreationDate(temp.lastModified()); Properties clientProps = new Properties(); if (deliveryTicket.getMsisdn() != null) { clientProps.setProperty(ND_PARAMETER, deliveryTicket.getMsisdn()); } if (deliveryTicket.getServiceId() != null) { clientProps.setProperty(SERVICE_PARAMETER, deliveryTicket.getServiceId()); } if (deliveryTicket.getUaKey() != null) { clientProps.setProperty(UAKEY_PARAMETER, deliveryTicket.getUaKey()); } if (deliveryTicket.getCallback() != null) { clientProps.setProperty(CALLBACK_PARAMETER, deliveryTicket.getCallback()); } if (deliveryTicket.getServiceSpecific() != null) { Map<String, String> serviceSpecificMap = deliveryTicket.getServiceSpecific(); for (String key : serviceSpecificMap.keySet()) { clientProps.setProperty(JAD_PREFIX_ENTRY.concat(key), serviceSpecificMap.get(key).toString()); } } outProps = new FileOutputStream(temp); clientProps.store(outProps, null); outProps.close(); FileUtils.touch(new File(this.path)); } catch (IOException ioe) { throw new MMPDaoException("failed to add ticket : " + ioe.getMessage()); } finally { try { if (outProps != null) outProps.close(); } catch (IOException ioe) { //Nop } this.lock.unlock(); } return deliveryTicket; }
From source file:com.p6spy.engine.spy.option.P6TestOptionsReload.java
@Test public void testAutoReloadLifecycle() throws Exception { // precondition assertFalse(P6SpyOptions.getActiveInstance().getStackTrace()); // value modification P6SpyOptions.getActiveInstance().setStackTrace(true); assertTrue(P6SpyOptions.getActiveInstance().getStackTrace()); // disable auto reload P6SpyOptions.getActiveInstance().setReloadProperties(false); FileUtils.touch(new File(System.getProperty(SpyDotProperties.OPTIONS_FILE_PROPERTY))); Thread.sleep(2000);/* www .j a v a2 s . c o m*/ // reload didn't happen assertTrue(P6SpyOptions.getActiveInstance().getStackTrace()); // enable auto reload P6SpyOptions.getActiveInstance().setReloadProperties(true); FileUtils.touch(new File(System.getProperty(SpyDotProperties.OPTIONS_FILE_PROPERTY))); Thread.sleep(2000); // reload did happen assertFalse(P6SpyOptions.getActiveInstance().getStackTrace()); }
From source file:com.linkedin.pinot.core.segment.creator.impl.SegmentDictionaryCreator.java
public SegmentDictionaryCreator(boolean hasNulls, Object sortedList, FieldSpec spec, File indexDir, char paddingChar) throws IOException { rowCount = ArrayUtils.getLength(sortedList); Object first = null;/*from w w w .ja va 2 s . co m*/ Object last = null; if (0 < rowCount) { if (sortedList instanceof int[]) { int[] intSortedList = (int[]) sortedList; first = intSortedList[0]; last = intSortedList[rowCount - 1]; } else if (sortedList instanceof long[]) { long[] longSortedList = (long[]) sortedList; first = longSortedList[0]; last = longSortedList[rowCount - 1]; } else if (sortedList instanceof float[]) { float[] floatSortedList = (float[]) sortedList; first = floatSortedList[0]; last = floatSortedList[rowCount - 1]; } else if (sortedList instanceof double[]) { double[] doubleSortedList = (double[]) sortedList; first = doubleSortedList[0]; last = doubleSortedList[rowCount - 1]; } else if (sortedList instanceof String[]) { String[] intSortedList = (String[]) sortedList; first = intSortedList[0]; last = intSortedList[rowCount - 1]; } else if (sortedList instanceof Object[]) { Object[] intSortedList = (Object[]) sortedList; first = intSortedList[0]; last = intSortedList[rowCount - 1]; } } // make hll column log info different than other columns, since range makes no sense for hll column if (spec instanceof MetricFieldSpec && ((MetricFieldSpec) spec).getDerivedMetricType() == MetricFieldSpec.DerivedMetricType.HLL) { LOGGER.info( "Creating segment for column {}, hasNulls = {}, cardinality = {}, dataType = {}, single value field = {}, is HLL derived column", spec.getName(), hasNulls, rowCount, spec.getDataType(), spec.isSingleValueField()); } else { LOGGER.info( "Creating segment for column {}, hasNulls = {}, cardinality = {}, dataType = {}, single value field = {}, range = {} to {}", spec.getName(), hasNulls, rowCount, spec.getDataType(), spec.isSingleValueField(), first, last); } this.sortedList = sortedList; this.spec = spec; this.paddingChar = paddingChar; dictionaryFile = new File(indexDir, spec.getName() + ".dict"); FileUtils.touch(dictionaryFile); }
From source file:com.redhat.rhn.frontend.action.common.test.DownloadActionTest.java
public void testKSSessionAndPackageCount() throws Exception { Package p = PackageManagerTest.addPackageToChannel("some-package", tree.getChannel()); String fileName = "some-package-2.13.1-6.fc9.x86_64.rpm"; p.setPath(//from w w w. j a v a 2 s .c o m "redhat/1/c7d/some-package/2.13.1-6.fc9/" + "x86_64/c7dd5e9b6975bc7f80f2f4657260af53/" + fileName); TestUtils.saveAndFlush(p); FileUtils.touch(new File("/tmp/Server/" + fileName)); KickstartSession ksession = KickstartSessionTest.createKickstartSession(ksdata, user); ksession.setKstree(tree); ksession.setKsdata(ksdata); TestUtils.saveAndFlush(ksession); String encodedSession = SessionSwap.encodeData(ksession.getId().toString()); addRequestParameter("url", "/ks/dist/session/" + encodedSession + "/" + tree.getLabel() + "/Server/" + fileName); request.setQueryString( "url=/ks/dist/session/" + encodedSession + "/" + tree.getLabel() + "/Server/" + fileName); actionPerform(); assertNotNull(request.getAttribute("params")); assertEquals(1, ksession.getPackageFetchCount().longValue()); request.setHeader("Range", "333"); actionPerform(); assertEquals(1, ksession.getPackageFetchCount().longValue()); }
From source file:com.github.neio.filesystem.paths.TestDirectoryPath.java
@Test public void test_Path_Iterator() throws IOException { Directory directory = new DirectoryPath("./testTempDir"); FileUtils.forceMkdir(new File("./testTempDir/path1")); FileUtils.touch(new File("./testTempDir/path1/file1")); Iterator<Path> iterator = directory.iterator(); Assert.assertTrue(iterator.hasNext()); Path path1 = iterator.next(); Assert.assertTrue(path1 instanceof FilePath); Assert.assertEquals("testTempDir/path1/file1", path1.getPath()); }