org.geoserver.platform.resource.Resource.list()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中org.geoserver.platform.resource.Resource.list方法的一些代码示例,展示了Resource.list的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resource.list方法的具体详情如下:
包路径:org.geoserver.platform.resource.Resource
类名称:Resource
方法名:list

Resource.list介绍

[英]List of directory contents.

The listed files exist (and may be DIRECTORY or RESOURCE items).
[中]目录内容列表。
列出的文件存在(可能是目录或资源项)。

代码示例

代码示例来源:origin: geoserver/geoserver

@Override
public List<Resource> list() {
  List<Resource> children = new ArrayList<Resource>();
  for (Resource child : delegate.list()) {
    children.add(new SerializableResourceWrapper(child));
  }
  return children;
}

代码示例来源:origin: geoserver/geoserver

/**
 * Returns filtered children of a directory
 *
 * @param dir parent directory
 * @param filter the filter that selects children
 * @param recursive searches recursively
 * @return filtered list
 */
public static List<Resource> list(Resource dir, Filter<Resource> filter, boolean recursive) {
  List<Resource> res = new ArrayList<Resource>();
  for (Resource child : dir.list()) {
    if (filter.accept(child)) {
      res.add(child);
    }
    if (recursive && child.getType() == Type.DIRECTORY) {
      res.addAll(list(child, filter, true));
    }
  }
  return res;
}

代码示例来源:origin: geoserver/geoserver

SortedSet<String> listFiles(Resource dir) {
  SortedSet<String> result = new TreeSet<String>();
  List<Resource> dirs = dir.list();
  for (Resource d : dirs) {
    if (d.getType() == Type.DIRECTORY
        && d.get(CONFIG_FILENAME).getType() == Type.RESOURCE) {
      result.add(d.name());
    }
  }
  return result;
}

代码示例来源:origin: geoserver/geoserver

/**
 * Search for resources using pattern and last modified time.
 *
 * @param resource Resource indicated
 * @param lastModified time stamp to search from
 * @return list of modified resources
 */
public static List<Resource> search(Resource resource, long lastModified) {
  if (resource.getType() == Type.DIRECTORY) {
    ArrayList<Resource> results = new ArrayList<Resource>();
    for (Resource child : resource.list()) {
      switch (child.getType()) {
        case RESOURCE:
          if (child.lastmodified() > lastModified) {
            results.add(child);
          }
          break;
        default:
          break;
      }
    }
    return results;
  }
  return Collections.emptyList();
}

代码示例来源:origin: geoserver/geoserver

root.list()
    .parallelStream()
    .filter(r -> filter.accept(r))

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryLeavesHaveEmptyListOfChildren(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(resource()));
  Collection<Resource> result = res.list();
  assertThat(result, empty());
}

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryUndefinedHaveEmptyListOfChildren(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(undefined()));
  Collection<Resource> result = res.list();
  assertThat(result, empty());
}

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryDirectoriesHaveChildren(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(directory()));
  Collection<Resource> result = res.list();
  assertThat(result, notNullValue());
}

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryChildrenKnowTheirParents(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(directory()));
  Collection<Resource> children = res.list();
  assumeThat(children, not(empty())); // Make sure this resource has children
  for (Resource child : children) {
    Resource parent = child.parent();
    assertThat(parent, equalTo(res));
  }
}

代码示例来源:origin: geoserver/geoserver

/**
 * Write the contents of a resource into another resource. Also supports directories
 * (recursively).
 *
 * @param data resource to read
 * @param destination resource to write to
 * @throws IOException If data could not be copied to destination
 */
public static void copy(Resource data, Resource destination) throws IOException {
  if (data.getType() == Type.DIRECTORY) {
    for (Resource child : data.list()) {
      copy(child, destination.get(child.name()));
    }
  } else {
    try (InputStream in = data.in()) {
      copy(in, destination);
    }
  }
}

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryParentsKnowTheirChildren(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(directory()));
  Resource parent = res.parent();
  assumeThat(path, parent, notNullValue()); // Make sure this resource has a parent
  Collection<Resource> result = parent.list();
  assertThat(path, result, hasItem(res)); // this assumed equals was written!
}

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryRecursiveDelete(String path) throws Exception {
  final Resource res = getResource(path);
  assumeThat(res, is(directory()));
  assumeThat(res, is(directory()));
  Collection<Resource> result = res.list();
  assumeThat(result.size(), greaterThan(0));
  assertTrue(res.delete());
}

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryAddingFileToDirectoryAddsResource(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(directory()));
  File dir = res.dir();
  File file = new File(dir, "newFileCreatedDirectly");
  assumeTrue(file.createNewFile());
  Resource child = getResource(Paths.path(res.path(), "newFileCreatedDirectly"));
  Collection<Resource> children = res.list();
  assertThat(child, is(defined()));
  assertThat(children, hasItem(child));
}

代码示例来源:origin: geoserver/geoserver

@Theory
public void theoryDirectoriesHaveFileWithSameNamedChildren(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(directory()));
  File dir = res.dir();
  Collection<Resource> resChildren = res.list();
  String[] fileChildrenNames = dir.list();
  String[] resChildrenNames = new String[resChildren.size()];
  int i = 0;
  for (Resource child : resChildren) {
    resChildrenNames[i] = child.name();
    i++;
  }
  assertThat(fileChildrenNames, arrayContainingInAnyOrder(resChildrenNames));
}

代码示例来源:origin: geoserver/geoserver

@Test
public void testReloadDefaultStyles() throws Exception {
  // clear up all "point" styles
  final Resource styles = getDataDirectory().getStyles();
  styles.list()
      .stream()
      .filter(r -> r.getType() == Resource.Type.RESOURCE && r.name().contains("point"))
      .forEach(r -> r.delete());
  // reload
  getGeoServer().reload();
  // check the default point style has been re-created
  final StyleInfo point = getCatalog().getStyleByName("point");
  assertNotNull(point);
}

代码示例来源:origin: geoserver/geoserver

.list()
.parallelStream()
.filter(r -> Resources.DirectoryFilter.INSTANCE.accept(r))

代码示例来源:origin: geoserver/geoserver

Map<String, Map<String, Object>> dataStores = creader.dataStores();
for (Resource featureTypeDir : featureTypesDir.list()) {
  if (featureTypeDir.getType() != Type.DIRECTORY) {
    continue;
  if (destFeatureTypeDir != null) {
    for (Resource file : featureTypeDir.list()) {
      if (file.getType() == Type.RESOURCE && !featureTypeInfo.equals(file)) {
        IOUtils.copy(file.in(), destFeatureTypeDir.get(file.name()).out());

代码示例来源:origin: geoserver/geoserver

for (Resource dir : workspaces.list()) {
  if (dir.getType() != Type.DIRECTORY) continue;
for (Resource dir : workspaces.list()) {
  if (dir.getType() != Type.DIRECTORY) continue;

代码示例来源:origin: org.geoserver/gs-platform

@Theory
public void theoryDirectoriesHaveChildren(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(directory()));
  Collection<Resource> result = res.list();
  assertThat(result, notNullValue());
}

代码示例来源:origin: org.geoserver/gs-platform

@Theory
public void theoryParentsKnowTheirChildren(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(directory()));
  Resource parent = res.parent();
  assumeThat(path, parent, notNullValue()); // Make sure this resource has a parent
  Collection<Resource> result = parent.list();
  assertThat(path, result, hasItem(res)); // this assumed equals was written!
}

相关文章