public CoordinateReferenceSystem readPrjToCRS() throws IOException { Resource prj = getPrjFile(); if (prj == null || !Resources.exists(prj)) { return null; } try (InputStream is = prj.in()) { return CRS.parseWKT(IOUtils.toString(is)); } catch (Exception e) { throw (IOException) new IOException().initCause(e); } }
void initializeDataSource() throws Exception { Resource monitoringDir = dataDirectory.get("monitoring"); Resource dbprops = monitoringDir.get("db.properties"); if (Resources.exists(dbprops)) { LOGGER.info("Configuring monitoring database from: " + dbprops.path()); // attempt to configure try { configureDataSource(dbprops, monitoringDir); } catch (SQLException e) { // configure failed, try db1.properties dbprops = monitoringDir.get("db1.properties"); if (Resources.exists(dbprops)) { try { configureDataSource(dbprops, monitoringDir); // secondary file worked, return return; } catch (SQLException e1) { // secondary file failed as well, try for third dbprops = monitoringDir.get("db2.properties"); if (Resources.exists(dbprops)) { try { configureDataSource(dbprops, monitoringDir); // third file worked, return return; } catch (SQLException e2) { } } } } throw e; } } else { // no db.properties file, use internal default configureDataSource(null, monitoringDir); } }
/** * Check for the existence of the file, if the file exists do nothing. * * <p>If the file does not exist, check for a template file contained in the jar with the same * name, if found, use it. * * <p>If no template was found, use the default template * * @param fileName target location * @param namedRoot parent dir if fileName is relative * @param defaultResource the standard template * @throws IOException * @return the file to use */ protected Resource checkORCreateJDBCPropertyFile( String fileName, Resource namedRoot, String defaultResource) throws IOException { Resource resource; fileName = fileName != null ? fileName : defaultResource; File file = new File(fileName); if (file.isAbsolute()) { resource = Files.asResource(file); } else { resource = namedRoot.get(fileName); } if (Resources.exists(resource)) { return resource; // we are happy } // try to find a template with the same name InputStream is = this.getClass().getResourceAsStream(fileName); if (is != null) IOUtils.copy(is, resource.out()); else // use the default template FileUtils.copyURLToFile(getClass().getResource(defaultResource), file); return resource; }