List of usage examples for java.lang ClassLoader getSystemResource
public static URL getSystemResource(String name)
From source file:com.stratio.decision.service.SolrOperationsService.java
public void createSolrConfig(String confPath) throws URISyntaxException, IOException { FileUtils.copyFile(new File(ClassLoader.getSystemResource("./solr-config/solrconfig.xml").toURI()), new File(confPath + "/solrconfig.xml")); }
From source file:org.n52.sir.IT.DeleteSensorInfoIT.java
@Test public void deleteReference() throws Exception { File f = new File(ClassLoader.getSystemResource("Requests/DeleteSensorInfo_deleteReference.xml").getFile()); DeleteSensorInfoRequestDocument req = DeleteSensorInfoRequestDocument.Factory.parse(f); XmlObject response = client.xSendPostRequest(req); DeleteSensorInfoResponseDocument responseDoc = DeleteSensorInfoResponseDocument.Factory .parse(response.getDomNode()); assertTrue(responseDoc.validate());/*from w w w . j a v a 2 s . c om*/ // FIXME test must check whether the reference was actually deleted }
From source file:org.jboss.pressgang.ccms.contentspec.client.commands.PreviewCommandTest.java
@Before public void setUp() throws IOException { bindStdOut();//from www . j a v a 2s .c om command = spy(new PreviewCommand(parser, cspConfig, clientConfig)); // Only test the preview command and not the build or assemble command content. command.setNoAssemble(true); rootTestDirectory = FileUtils.toFile(ClassLoader.getSystemResource("")); when(cspConfig.getRootOutputDirectory()).thenReturn(rootTestDirectory.getAbsolutePath() + File.separator); // Make the book title directory bookDir = new File(rootTestDirectory, BOOK_TITLE); bookDir.mkdir(); // Make the preview dummy file htmlSingleDir = new File(bookDir.getAbsolutePath() + File.separator + "tmp" + File.separator + "en-US" + File.separator + "html-single"); htmlSingleDir.mkdirs(); previewFile = new File(htmlSingleDir, "index.html"); previewFile.createNewFile(); when(contentSpecWrapper.getLocale()).thenReturn(localeWrapper); }
From source file:dk.dma.aisvirtualnet.Settings.java
public void load(String filename) throws IOException { this.filename = filename; props = new Properties(); URL url = ClassLoader.getSystemResource(filename); if (url == null) { throw new IOException("Could not find properties file: " + filename); }/*from w ww .j ava2s.c om*/ props.load(url.openStream()); // Iterate throgh serial sources String serialSourcesStr = props.getProperty("serial_sources", ""); for (String sourceDescription : StringUtils.split(serialSourcesStr, ",")) { AisSerialReader aisSerialReader = new AisSerialReader(); aisSerialReader.setPortName(props.getProperty("serial_port." + sourceDescription, "")); aisSerialReader.setPortSpeed(getInt("serial_speed." + sourceDescription, "38400")); aisSerialReader.setDataBits(getInt("serial_data_bits." + sourceDescription, "8")); aisSerialReader.setStopBits(getInt("serial_stop_bits." + sourceDescription, "1")); aisSerialReader.setParity(getInt("serial_parity." + sourceDescription, "0")); // Find port try { aisSerialReader.findPort(); } catch (IOException e) { LOG.error("Failed to find serial port " + aisSerialReader.getPortName()); continue; } LOG.info("Adding serial source " + aisSerialReader.getPortName() + " (" + sourceDescription + ")"); AisVirtualNet.getSourceReader().addReader(aisSerialReader); } // Iterate through TCP sources String tcpSourcesStr = props.getProperty("tcp_sources", ""); for (String tcpSourceName : StringUtils.split(tcpSourcesStr, ",")) { AisTcpReader aisTcpReader = new AisTcpReader(); aisTcpReader.setHostname(props.getProperty("tcp_source_host." + tcpSourceName, "localhost")); aisTcpReader.setPort(getInt("tcp_source_port." + tcpSourceName, "4001")); LOG.info("Adding TCP source " + tcpSourceName + " " + aisTcpReader.getHostname() + ":" + aisTcpReader.getPort()); AisVirtualNet.getSourceReader().addReader(aisTcpReader); } // Iterate through transponders String transpondersStr = props.getProperty("transponders", ""); for (String transponderName : StringUtils.split(transpondersStr, ",")) { Transponder transponder = new Transponder(AisVirtualNet.getAisNetwork()); transponder.setMmsi(getInt("transponder_mmsi." + transponderName, "0")); transponder.setTcpPort(getInt("transponder_tcp_port." + transponderName, "0")); transponder.setForceOwnInterval(getInt("transponder_own_message_force." + transponderName, "0")); LOG.info("Adding transponder " + transponderName + " mmsi " + transponder.getMmsi() + " port " + transponder.getTcpPort()); AisVirtualNet.getTransponders().add(transponder); } }
From source file:com.dianping.resource.io.util.ResourceUtils.java
/** * Resolve the given resource location to a {@code java.net.URL}. * <p>Does not check whether the URL actually exists; simply returns * the URL that the given location would correspond to. * @param resourceLocation the resource location to resolve: either a * "classpath:" pseudo URL, a "file:" URL, or a plain file path * @return a corresponding URL object// w w w. ja va 2 s . c om * @throws java.io.FileNotFoundException if the resource cannot be resolved to a URL */ public static URL getURL(String resourceLocation) throws FileNotFoundException { Assert.notNull(resourceLocation, "Resource location must not be null"); if (resourceLocation.startsWith(CLASSPATH_URL_PREFIX)) { String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length()); ClassLoader cl = ClassUtils.getDefaultClassLoader(); URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path)); if (url == null) { String description = "class path resource [" + path + "]"; throw new FileNotFoundException( description + " cannot be resolved to URL because it does not exist"); } return url; } try { // try URL return new URL(resourceLocation); } catch (MalformedURLException ex) { // no URL -> treat as file path try { return new File(resourceLocation).toURI().toURL(); } catch (MalformedURLException ex2) { throw new FileNotFoundException("Resource location [" + resourceLocation + "] is neither a URL not a well-formed file path"); } } }
From source file:org.jodconverter.office.OnlineOfficeManagerPoolEntry.java
private static File getFile(final String resourceLocation) throws FileNotFoundException { Validate.notNull(resourceLocation, "Resource location must not be null"); if (resourceLocation.startsWith("classpath:")) { final String path = resourceLocation.substring("classpath:".length()); final String description = "class path resource [" + path + "]"; final ClassLoader cl = getDefaultClassLoader(); final URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path)); if (url == null) { throw new FileNotFoundException( description + " cannot be resolved to absolute file path because it does not exist"); }//from w ww.jav a 2 s . c o m return getFile(url.toString()); } try { // try URL return getFile(new URL(resourceLocation)); } catch (MalformedURLException ex) { // no URL -> treat as file path return new File(resourceLocation); } }
From source file:org.n52.sir.IT.InsertSensorInfoNewSensorIT.java
@Test public void insertTestSensorFromFile() throws XmlException, IOException, OwsExceptionReport, HttpException { File sensor = new File(ClassLoader.getSystemResource("Requests/sir/testSensor.xml").getFile()); SensorMLDocument DOC = SensorMLDocument.Factory.parse(sensor); InsertSensorInfoRequestDocument req = InsertSensorInfoRequestDocument.Factory.newInstance(); req.addNewInsertSensorInfoRequest().addNewInfoToBeInserted() .setSensorDescription(DOC.getSensorML().getMemberArray(0).getProcess()); XmlObject res = client.xSendPostRequest(req); InsertSensorInfoResponseDocument resp = InsertSensorInfoResponseDocument.Factory.parse(res.getDomNode()); assertThat("one sensor was inserted", resp.getInsertSensorInfoResponse().getNumberOfInsertedSensors(), is(equalTo(1)));/* w w w . jav a 2 s . co m*/ assertThat("no service reference was inserted", resp.getInsertSensorInfoResponse().getNumberOfInsertedServiceReferences(), is(equalTo(0))); this.sensorId = resp.getInsertSensorInfoResponse().getInsertedSensors().getSensorIDInSIRArray(0); }
From source file:org.pentaho.pac.server.common.ConsoleProperties.java
public void init(String pathToConfigResource) { FileInputStream fis = null;/*w w w . j a v a 2s . com*/ try { URL url = ClassLoader.getSystemResource(pathToConfigResource); URI uri = url.toURI(); File file = new File(uri); fis = new FileInputStream(file); } catch (Exception e1) { logger.error(Messages.getErrorString("ConsoleProperties.ERROR_0001_OPEN_PROPS_FAILED", //$NON-NLS-1$ pathToConfigResource)); } if (null != fis) { properties = new Properties(); try { properties.load(fis); } catch (IOException e) { logger.error(Messages.getErrorString("ConsoleProperties.ERROR_0002_LOAD_PROPS_FAILED", //$NON-NLS-1$ DEFAULT_CONSOLE_PROPERTIES_FILE_NAME)); } } }
From source file:org.jboss.pressgang.ccms.contentspec.client.commands.PullSnapshotCommandTest.java
@Before public void setUp() { bindStdOut();/*from w w w. ja v a2 s . co m*/ command = new PullSnapshotCommand(parser, cspConfig, clientConfig); // Authentication is tested in the base implementation so assume all users are valid TestUtil.setUpAuthorisedUser(command, userProvider, users, user, username); when(providerFactory.getRESTManager()).thenReturn(restManager); when(restManager.getRESTClient()).thenReturn(restClient); rootTestDirectory = FileUtils.toFile(ClassLoader.getSystemResource("")); when(cspConfig.getRootOutputDirectory()).thenReturn(rootTestDirectory.getAbsolutePath() + File.separator); }
From source file:org.apache.james.webadmin.routes.SieveScriptRoutesTest.java
@BeforeEach public void setUp(TemporaryFolderExtension.TemporaryFolder temporaryFolder) throws ConfigurationException, IOException, UsersRepositoryException { this.fileSystem = new FileSystem() { @Override/*from w ww .j av a 2 s. c o m*/ public File getBasedir() { return temporaryFolder.getTempDir(); } @Override public InputStream getResource(String url) throws IOException { return new FileInputStream(getFile(url)); } @Override public File getFile(String fileURL) { return new File(getBasedir(), fileURL.substring(FileSystem.FILE_PROTOCOL.length())); } }; sieveRepository = new SieveFileRepository(fileSystem); usersRepository = MemoryUsersRepository.withoutVirtualHosting(); usersRepository.addUser("userA", "password"); URL sieveResource = ClassLoader.getSystemResource("sieve/my_sieve"); sieveContent = IOUtils.toString(sieveResource, StandardCharsets.UTF_8); webAdminServer = WebAdminUtils.createWebAdminServer(new DefaultMetricFactory(), new SieveScriptRoutes(sieveRepository, usersRepository)); webAdminServer.configure(NO_CONFIGURATION); webAdminServer.await(); RestAssured.requestSpecification = WebAdminUtils.buildRequestSpecification(webAdminServer).build(); }