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

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

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

Resource.file介绍

[英]File access to resource contents.

The resource may need to be unpacked into the GeoServer data directory prior to use. Do not assume the file exists before calling this method.
[中]对资源内容的文件访问。
使用前,可能需要将资源解压缩到GeoServer数据目录中。在调用此方法之前,不要假定文件存在。

代码示例

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

@Override
public File file() {
  return delegate.file();
}

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

public File getFile() {
  return resource.file();
}

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

/**
 * Returns the configuration file for the specified workspace, if the file does not exist a file
 * object will still be returned.
 *
 * @deprecated As of GeoServer 2.6, replaced by {@link #config(WorkspaceInfo)}
 */
@Deprecated
public File findOrResolveWorkspaceFile(WorkspaceInfo ws) throws IOException {
  Resource workspaceFile = config(ws);
  return workspaceFile.file();
}

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

/**
 * Returns the configuration file for the specified store, if the file does not exist a file
 * object is still returned.
 *
 * @deprecated As of GeoServer 2.6, replaced by {@link #get(StoreInfo, String...)}
 */
@Deprecated
public File findOrResolveStoreFile(StoreInfo store) throws IOException {
  Resource resource = get(store);
  return resource.file();
}

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

/**
 * If create is true or if a file exists returns resource.file, otherwise it returns null.
 *
 * @see Resource#file()
 * @param resource Resource indicated
 * @param create true to create (if needed)
 * @return file, or null
 */
public static File file(Resource resource, boolean create) {
  final File f;
  if (resource == null) {
    f = null;
  } else if (create) {
    f = resource.file();
  } else {
    if (resource.getType() == Type.RESOURCE) {
      f = resource.file();
    } else {
      f = null;
    }
  }
  return f;
}

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

/**
 * Returns the configuration file for the specified resource, if the file does not exist a file
 * object is still returned.
 *
 * @deprecated As of GeoServer 2.6, replaced by {@link #config(FeatureTypeInfo, String...)},
 *     {@link #config(CoverageInfo, String...)}, {@link #config(WMSLayerInfo, String...)}
 */
@Deprecated
public File findOrResolveResourceFile(ResourceInfo r) throws IOException {
  Resource resource = config(r);
  return resource.file();
}

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

/**
 * Returns the configuration file for the specified style, if the file does not exist a file
 * object is still returned.
 *
 * @deprecated As of GeoServer 2.6, replaced by {@link #config(StyleInfo, String...)}
 */
public File findOrCreateStyleFile(StyleInfo s) throws IOException {
  Resource resource = config(s);
  return resource.file();
}

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

/**
 * Returns the configuration file for the specified layer, if the file does not exist a file
 * object is still returned.
 *
 * @deprecated As of GeoServer 2.6, replaced by {@link #get(LayerInfo, String...)}
 */
public File findOrResolveLayerFile(LayerInfo layer) throws IOException {
  Resource resource = get(layer);
  return resource.file();
}

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

/**
 * Returns the SLD file for the specified style, if the file does not exist a file object is
 * still returned.
 *
 * @deprecated As of GeoServer 2.6, replaced by {@link #style(StyleInfo, String...)}
 */
public File findOrCreateStyleSldFile(StyleInfo s) throws IOException {
  Resource resource = style(s);
  return resource.file();
}

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

public List validateGETMAP(InputSource xml, ServletContext servContext) {
  GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
  Resource schema = loader.get("data/capabilities/sld/GetMap.xsd");
  File schemaFile = schema.file();
  //        File schemaFile = new File(GeoserverDataDirectory.getGeoserverDataDirectory(),
  //                "/data/capabilities/sld/GetMap.xsd");
  try {
    return validateGETMAP(xml, URLs.fileToUrl(schemaFile));
  } catch (Exception e) {
    ArrayList al = new ArrayList();
    al.add(new SAXException(e));
    return al;
  }
}

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

/**
 * Returns a file under the {@link #dataRoot()} directory, if the file does not exist it a file
 * object will still be returned.
 *
 * @deprecated Unused
 */
public File findOrResolveDataFile(String... location) throws IOException {
  Resource resource = get(Paths.path("data", Paths.path(location)));
  return resource.file();
}

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

/**
 * validates against the "normal" location of the schema (ie.
 * ".../capabilities/sld/StyleLayerDescriptor.xsd" uses the geoserver_home patch
 *
 * @param xml
 * @param req
 */
public List validateGETMAP(InputStream xml) {
  GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
  Resource schema = loader.get("data/capabilities/sld/GetMap.xsd");
  File schemaFile = schema.file();
  try {
    return validateGETMAP(xml, URLs.fileToUrl(schemaFile));
  } catch (Exception e) {
    ArrayList al = new ArrayList();
    al.add(new SAXException(e));
    return al;
  }
}

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

/**
 * Create a new file for the provided resource (this will only work for {@link
 * Resource.Type#UNDEFINED}).
 *
 * <p>This approach is a reproduction of GeoServerResourceLoader createNewFile logic.
 *
 * @param resource Resource indicated
 * @return newly created file
 * @throws IOException If path indicates a file (or directory) that already exists
 */
public static File createNewFile(Resource resource) throws IOException {
  switch (resource.getType()) {
    case DIRECTORY:
      throw new IOException(
          "New file " + resource.path() + " already exists as DIRECTORY");
    case RESOURCE:
      throw new IOException(
          "New file " + resource.path() + " already exists as RESOURCE");
    case UNDEFINED:
      return resource.file(); // will create directory as needed
    default:
      return null;
  }
}

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

/**
 * Copies a resource located on the classpath to a specified path.
 *
 * <p>The <tt>resource</tt> is obtained from teh context class loader of the current thread.
 * When the <tt>to</tt> parameter is specified as a relative path it is considered to be
 * relative to {@link #getBaseDirectory()}.
 *
 * @param classpathResource The resource to copy.
 * @param location The destination to copy to.
 */
public void copyFromClassPath(String classpathResource, String location) throws IOException {
  Resource resource = get(Paths.convert(location));
  copyFromClassPath(classpathResource, resource.file());
}

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

/**
 * Returns a file under the {@link #dataRoot()} directory.
 *
 * @param create Create file (if required)
 * @param location file location
 * @return File (created if needed) or null if not found
 * @deprecated Unused
 */
private File dataFile(boolean create, String... location) throws IOException {
  Resource resource = get(Paths.path("data", Paths.path(location)));
  if (create) {
    return resource.file();
  } else {
    return Resources.file(resource);
  }
}

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

/**
   * Locate the specified grid file.
   *
   * <p>It will look in GEOSERVER_DATA_DIR/user_projections
   *
   * @param grid the grid name/location
   * @return the fully resolved URL of the grid or null, if the resource cannot be located.
   */
  @Override
  public URL locateGrid(String grid) {
    if (grid == null) return null;

    GeoServerResourceLoader loader = GeoServerExtensions.bean(GeoServerResourceLoader.class);
    if (loader == null) {
      return null; // must be test case still loading
    }
    Resource gridfile = loader.get("user_projections/" + grid);

    if (gridfile.getType() == Type.RESOURCE) {
      return URLs.fileToUrl(gridfile.file());
    } else {
      return null;
    }
  }
}

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

@Theory
public void theoryNonDirectoriesHaveFileWithSameContents(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, not(directory()));
  byte[] test = {42, 29, 32, 120, 69, 0, 1};
  try (OutputStream ostream = res.out()) {
    ostream.write(test);
  }
  byte[] result = new byte[test.length];
  try (InputStream istream = new FileInputStream(res.file())) {
    istream.read(result);
    assertThat(istream.read(), is(-1));
  }
  assertThat(result, equalTo(test));
}

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

@Theory
public void theoryAlteringFileAltersResource(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, not(directory()));
  byte[] testResource = {42, 29, 32, 120, 69, 0, 1};
  byte[] testFile = {27, 3, 5, 90, -120, -3};
  // Write to resource
  try (OutputStream ostream = res.out()) {
    ostream.write(testResource);
  }
  // Write to file
  try (OutputStream ostream = new FileOutputStream(res.file())) {
    ostream.write(testFile);
  }
  // Read from resource
  byte[] result = new byte[testFile.length];
  try (InputStream istream = res.in()) {
    istream.read(result);
    assertThat(istream.read(), is(-1));
  }
  // Should be what was written to the file
  assertThat(result, equalTo(testFile));
}

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

@Theory
public void theoryHaveFile(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, resource());
  File result = res.file();
  assertThat(result, notNullValue());
}

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

@Test
  public void resourcesTest() throws IOException {
    Resource source = getResource();

    Resource directory = getDirectory();

    Resources.copy(source.file(), directory);

    Resource target = directory.get(source.name());

    assertTrue(Resources.exists(target));
    assertEquals(target.name(), source.name());
  }
}

相关文章