Tabnine Logo
Resource.in
Code IndexAdd Tabnine to your IDE (free)

How to use
in
method
in
org.geoserver.platform.resource.Resource

Best Java code snippets using org.geoserver.platform.resource.Resource.in (Showing top 20 results out of 315)

origin: geoserver/geoserver

@Override
public InputStream getInputStream() throws IOException {
  return resource.in();
}
origin: geoserver/geoserver

@Override
public InputStream in() {
  return delegate.in();
}
origin: geoserver/geoserver

/**
 * Returns a resource full contents as a byte array. Usage is suggested only if the resource is
 * known to be small (e.g. a configuration file).
 *
 * @return
 * @throws IOException
 */
default byte[] getContents() throws IOException {
  try (InputStream in = in()) {
    return org.apache.commons.io.IOUtils.toByteArray(in);
  }
}
origin: geoserver/geoserver

/**
 * Test if the file or directory can be read.
 *
 * @see File#canRead()
 * @param resource Resource indicated
 * @return true If resource is not UNDEFINED
 */
public static boolean canRead(Resource resource) {
  try {
    InputStream is = resource.in();
    is.read();
    is.close();
    return true;
  } catch (IOException | IllegalStateException e) {
    return false;
  }
}
origin: geoserver/geoserver

/**
 * Reads a property file resource.
 *
 * <p>This method delegates to {@link #loadUniversal(InputStream)}.
 */
public static Properties loadPropertyFile(Resource f) throws IOException {
  try (InputStream in = f.in()) {
    return loadUniversal(in);
  }
}
origin: geoserver/geoserver

/** reads a config file from the specified directly using the specified xstream persister */
<T extends SecurityConfig> T loadConfig(Class<T> config, Resource resource, XStreamPersister xp)
    throws IOException {
  InputStream in = resource.in();
  try {
    Object loaded = xp.load(in, SecurityConfig.class).clone(true);
    return config.cast(loaded);
  } finally {
    in.close();
  }
}
/** reads a config file from the specified directly using the specified xstream persister */
origin: geoserver/geoserver

/**
 * Reads a raw style from persistence.
 *
 * @param style The configuration for the style.
 * @return A reader for the style.
 */
public BufferedReader readStyle(StyleInfo style) throws IOException {
  Resource styleResource = dataDir().style(style);
  if (styleResource == null) {
    throw new IOException("No such resource: " + style.getFilename());
  }
  return new BufferedReader(new InputStreamReader(styleResource.in()));
}
origin: geoserver/geoserver

static InputStream input(URL url, Resource configDir) throws IOException {
  // check for a file url
  if ("file".equalsIgnoreCase(url.getProtocol())) {
    File f = URLs.urlToFile(url);
    // check if the file is relative
    if (!f.isAbsolute()) {
      // make it relative to the config directory for this password provider
      Resource res = configDir.get(f.getPath());
      if (res.getType() != Type.RESOURCE) { // file must already exist.
        throw new FileNotFoundException();
      }
      return res.in();
    } else {
      return new FileInputStream(f);
    }
  } else {
    return url.openStream();
  }
}
origin: geoserver/geoserver

/**
 * Parses the catalog.xml file into a DOM.
 *
 * <p>This method *must* be called before any other methods.
 *
 * @param file The catalog.xml file.
 * @throws IOException In event of a parser error.
 */
public void read(Resource file) throws IOException {
  Reader reader = XmlCharsetDetector.getCharsetAwareReader(file.in());
  try {
    catalog = ReaderUtils.parse(reader);
  } finally {
    reader.close();
  }
}
origin: geoserver/geoserver

  private void copyResToDir(Resource r, Resource newDir) throws IOException {
    Resource newR = newDir.get(r.name());
    try (InputStream in = r.in();
        OutputStream out = newR.out()) {
      IOUtils.copy(in, out);
    }
  }
}
origin: geoserver/geoserver

/** reads a config file from the specified directly using the specified xstream persister */
SecurityConfig loadConfigFile(Resource directory, String filename, XStreamPersister xp)
    throws IOException {
  InputStream fin = directory.get(filename).in();
  try {
    return xp.load(fin, SecurityConfig.class).clone(true);
  } finally {
    fin.close();
  }
}
origin: geoserver/geoserver

/**
 * Parses the info.xml file into a DOM.
 *
 * <p>This method *must* be called before any other methods.
 *
 * @param file The info.xml file.
 * @throws IOException In event of a parser error.
 */
public void read(Resource file) throws IOException {
  parentDirectory = file.parent();
  Reader reader = XmlCharsetDetector.getCharsetAwareReader(file.in());
  try {
    featureType = ReaderUtils.parse(reader);
  } finally {
    reader.close();
  }
}
origin: geoserver/geoserver

private Version getSecurityVersion() throws IOException {
  Resource security = security();
  if (security.getType() == Type.UNDEFINED) {
    return BASE_VERSION;
  }
  Resource properties = security.get(VERSION_PROPERTIES);
  if (properties.getType() == Type.UNDEFINED) {
    return BASE_VERSION;
  }
  Properties p = new Properties();
  try (InputStream is = properties.in()) {
    p.load(is);
  }
  String version = p.getProperty(VERSION);
  if (version != null) {
    return new Version(version);
  } else {
    return BASE_VERSION;
  }
}
origin: geoserver/geoserver

@Theory
public void theoryNonDirectoriesPersistData(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 = res.in()) {
    istream.read(result);
    assertThat(istream.read(), is(-1));
  }
  assertThat(result, equalTo(test));
}
origin: geoserver/geoserver

@Theory
public void theoryLeavesHaveIstream(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(resource()));
  try (InputStream result = res.in()) {
    assertThat(result, notNullValue());
  }
}
origin: geoserver/geoserver

@Theory
public void theoryDirectoriesHaveNoIstreams(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(directory()));
  exception.expect(IllegalStateException.class);
  res.in().close();
}
origin: geoserver/geoserver

@Theory
public void theoryUndefinedHaveIstreamAndBecomeResource(String path) throws Exception {
  Resource res = getResource(path);
  assumeThat(res, is(undefined()));
  try (InputStream result = res.in()) {
    assertThat(result, notNullValue());
    assertThat(res, is(resource()));
  }
}
origin: geoserver/geoserver

@Theory
public void theoryRenamedResourcesAreEquivalent(String path) throws Exception {
  final Resource res = getResource(path);
  assumeThat(res, resource());
  final byte[] expectedContent;
  try (InputStream in = res.in()) {
    expectedContent = IOUtils.toByteArray(in);
  }
  final Resource target = getUndefined();
  assertThat(res.renameTo(target), is(true));
  assertThat(target, resource());
  final byte[] resultContent;
  try (InputStream in = target.in()) {
    resultContent = IOUtils.toByteArray(in);
  }
  assertThat(resultContent, equalTo(expectedContent));
}
origin: geoserver/geoserver

@Override
protected void onSetUp(SystemTestData testData) throws Exception {
  super.onSetUp(testData);
  LayerInfo li = getCatalog().getLayerByName(getLayerId(SystemTestData.BUILDINGS));
  Resource resource = getDataDirectory().config(li);
  Document dom;
  try (InputStream is = resource.in()) {
    dom = dom(resource.in());
  }
  Element defaultStyle = (Element) dom.getElementsByTagName("defaultStyle").item(0);
  Element defaultStyleId = (Element) defaultStyle.getElementsByTagName("id").item(0);
  defaultStyleId.setTextContent("danglingReference");
  try (OutputStream os = resource.out()) {
    print(dom, os);
  }
  getGeoServer().reload();
}
origin: geoserver/geoserver

public final T load(GeoServer gs, Resource directory) throws Exception {
  // look for file matching classname
  Resource file;
  if (Resources.exists(file = directory.get(getFilename()))) {
    // xstream it in
    try (BufferedInputStream in = new BufferedInputStream(file.in())) {
      XStreamPersister xp = xpf.createXMLPersister();
      initXStreamPersister(xp, gs);
      return initialize(xp.load(in, getServiceClass()));
    }
  } else {
    // create an 'empty' object
    ServiceInfo service = createServiceFromScratch(gs);
    return initialize((T) service);
  }
}
org.geoserver.platform.resourceResourcein

Javadoc

Steam access to resource contents.

Popular methods of Resource

  • out
  • getType
  • get
  • dir
  • file
  • path
  • delete
  • name
  • list
  • lastmodified
  • parent
  • addListener
  • parent,
  • addListener,
  • renameTo,
  • getContents,
  • removeListener,
  • load,
  • lock,
  • save,
  • setContents

Popular in Java

  • Making http requests using okhttp
  • requestLocationUpdates (LocationManager)
  • getContentResolver (Context)
  • getResourceAsStream (ClassLoader)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • Option (scala)
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now