use of com.google.common.base.Predicate in project jackrabbit-oak by apache.
the class DataStoreCacheUpgradeUtils method moveDownloadCache.
/**
* Move the DataStore downloaded cache files to the appropriate folder used by the new cache
* {@link FileCache}
* @param path the root of the datastore
*/
public static void moveDownloadCache(final File path) {
final List<String> exceptions = ImmutableList.of("tmp", UPLOAD_STAGING_DIR, DOWNLOAD_DIR);
File newDownloadDir = new File(path, DOWNLOAD_DIR);
Iterator<File> iterator = Files.fileTreeTraverser().postOrderTraversal(path).filter(new Predicate<File>() {
@Override
public boolean apply(File input) {
return input.isFile() && !input.getParentFile().equals(path) && !notInExceptions(input, exceptions);
}
}).iterator();
while (iterator.hasNext()) {
File download = iterator.next();
LOG.trace("Download cache file absolute pre-upgrade path " + download);
File newDownload = new File(newDownloadDir, download.getAbsolutePath().substring(path.getAbsolutePath().length()));
newDownload.getParentFile().mkdirs();
LOG.trace("Downloaded cache file absolute post-upgrade path " + newDownload);
try {
FileUtils.moveFile(download, newDownload);
LOG.info("Download cache file [{}] moved to [{}]", download, newDownload);
recursiveDelete(download, path);
} catch (Exception e) {
LOG.warn("Unable to move download cache file [{}] to [{}]", download, newDownload);
}
}
}
use of com.google.common.base.Predicate in project jackrabbit-oak by apache.
the class FileBlobStore method getAllChunkIds.
@Override
public Iterator<String> getAllChunkIds(final long maxLastModifiedTime) throws Exception {
FluentIterable<File> iterable = Files.fileTreeTraverser().postOrderTraversal(baseDir);
final Iterator<File> iter = iterable.filter(new Predicate<File>() {
// Ignore the directories and files newer than maxLastModifiedTime if specified
@Override
public boolean apply(@Nullable File input) {
if (!input.isDirectory() && ((maxLastModifiedTime <= 0) || FileUtils.isFileOlder(input, maxLastModifiedTime))) {
return true;
}
return false;
}
}).iterator();
return new AbstractIterator<String>() {
@Override
protected String computeNext() {
if (iter.hasNext()) {
File file = iter.next();
return FilenameUtils.removeExtension(file.getName());
}
return endOfData();
}
};
}
use of com.google.common.base.Predicate in project jackrabbit-oak by apache.
the class SegmentGraph method createRegExpFilter.
/**
* Create a regular expression based inclusion filter for segment.
*
* @param pattern regular expression specifying inclusion of nodes.
* @return
*/
public static Predicate<UUID> createRegExpFilter(@Nonnull String pattern, @Nonnull final SegmentIdProvider idProvider) {
final Pattern regExp = compile(checkNotNull(pattern));
checkNotNull(idProvider);
return new Predicate<UUID>() {
@Override
public boolean apply(UUID segment) {
try {
String info = getSegmentInfo(segment, idProvider);
if (info == null) {
info = "NULL";
}
return regExp.matcher(info).matches();
} catch (Exception e) {
System.err.println("Error accessing segment " + segment + ": " + e);
return false;
}
}
};
}
use of com.google.common.base.Predicate in project jackrabbit-oak by apache.
the class AbstractBlobTrackerRegistrationTest method assertTrackerReinitialized.
private void assertTrackerReinitialized() {
File blobIdFiles = new File(repoHome, "blobids");
ImmutableList<File> files = Files.fileTreeTraverser().postOrderTraversal(blobIdFiles).filter(new Predicate<File>() {
@Override
public boolean apply(@Nullable File input) {
return input.getAbsolutePath().endsWith(".process");
}
}).toList();
assertEquals(1, files.size());
}
use of com.google.common.base.Predicate in project jackrabbit-oak by apache.
the class FilteringNodeStateTest method shouldHaveCorrectChildOrderProperty.
@Test
public void shouldHaveCorrectChildOrderProperty() throws CommitFailedException {
final NodeState content = rootNodeState.getChildNode("content");
final NodeState decorated = wrap("/content", content, null, of("/content/foo"), null, null);
assertTrue(decorated.hasProperty(OAK_CHILD_ORDER));
{
// access via getProperty()
final PropertyState childOrder = decorated.getProperty(OAK_CHILD_ORDER);
final Iterable<String> values = childOrder.getValue(Type.STRINGS);
assertEquals(newArrayList("football"), newArrayList(values));
}
{
// access via getProperties()
final Predicate<PropertyState> isChildOrderProperty = new Predicate<PropertyState>() {
@Override
public boolean apply(PropertyState propertyState) {
return OAK_CHILD_ORDER.equals(propertyState.getName());
}
};
final PropertyState childOrder = Iterables.find(decorated.getProperties(), isChildOrderProperty);
final Iterable<String> values = childOrder.getValue(Type.STRINGS);
assertEquals(newArrayList("football"), newArrayList(values));
}
}
Aggregations