List of usage examples for java.lang ClassLoader getSystemResource
public static URL getSystemResource(String name)
From source file:org.apache.hadoop.gateway.websockets.BadUrlTest.java
/** * Initialize the configs and components required for this test. * * @param backend//from w w w . j ava2s . c o m * @throws IOException */ private static void setupGatewayConfig(final String backend) throws IOException { services = new DefaultGatewayServices(); topoDir = createDir(); URL serviceUrl = ClassLoader.getSystemResource("websocket-services"); final File descriptor = new File(topoDir, "websocket.xml"); final FileOutputStream stream = new FileOutputStream(descriptor); createKnoxTopology(backend).toStream(stream); stream.close(); final TestTopologyListener topoListener = new TestTopologyListener(); final Map<String, String> options = new HashMap<>(); options.put("persist-master", "false"); options.put("master", "password"); gatewayConfig = EasyMock.createNiceMock(GatewayConfig.class); EasyMock.expect(gatewayConfig.getGatewayTopologyDir()).andReturn(topoDir.toString()).anyTimes(); EasyMock.expect(gatewayConfig.getGatewayServicesDir()).andReturn(serviceUrl.getFile()).anyTimes(); EasyMock.expect(gatewayConfig.getEphemeralDHKeySize()).andReturn("2048").anyTimes(); EasyMock.expect(gatewayConfig.getGatewaySecurityDir()).andReturn(topoDir.toString()).anyTimes(); /* Websocket configs */ EasyMock.expect(gatewayConfig.isWebsocketEnabled()).andReturn(true).anyTimes(); EasyMock.expect(gatewayConfig.getWebsocketMaxTextMessageSize()) .andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_SIZE).anyTimes(); EasyMock.expect(gatewayConfig.getWebsocketMaxBinaryMessageSize()) .andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_SIZE).anyTimes(); EasyMock.expect(gatewayConfig.getWebsocketMaxTextMessageBufferSize()) .andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_TEXT_MESSAGE_BUFFER_SIZE).anyTimes(); EasyMock.expect(gatewayConfig.getWebsocketMaxBinaryMessageBufferSize()) .andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_MAX_BINARY_MESSAGE_BUFFER_SIZE).anyTimes(); EasyMock.expect(gatewayConfig.getWebsocketInputBufferSize()) .andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_INPUT_BUFFER_SIZE).anyTimes(); EasyMock.expect(gatewayConfig.getWebsocketAsyncWriteTimeout()) .andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_ASYNC_WRITE_TIMEOUT).anyTimes(); EasyMock.expect(gatewayConfig.getWebsocketIdleTimeout()) .andReturn(GatewayConfigImpl.DEFAULT_WEBSOCKET_IDLE_TIMEOUT).anyTimes(); EasyMock.replay(gatewayConfig); try { services.init(gatewayConfig, options); } catch (ServiceLifecycleException e) { e.printStackTrace(); } DeploymentFactory.setGatewayServices(services); final TopologyService monitor = services.getService(GatewayServices.TOPOLOGY_SERVICE); monitor.addTopologyChangeListener(topoListener); monitor.reloadTopologies(); }
From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris")); MailboxMessage spamMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/spamMail.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setModSeq(MOD_SEQ);/*from ww w . j av a 2 s . c om*/ assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/spamMail.json"), CHARSET)); }
From source file:desktop.olayinka.file.transfer.model.DerbyJDBCHelper.java
private DerbyJDBCHelper() { try {/*from w w w. j av a2 s . c o m*/ System.out.println(DB_URL); //ensure database is created String dbUrl = "jdbc:derby:" + DB_FILE.getAbsolutePath() + ";create=true;user=" + DB_USER + ";password=" + DB_PWD; System.out.println(dbUrl); Connection mConnection; try { Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); mConnection = DriverManager.getConnection(dbUrl); } catch (Exception e) { e.printStackTrace(); System.exit(1); return; } onStart(mConnection); onUpgrade(mConnection); mConnection.commit(); mConnection.close(); //instantiate persistence unit EntityManagerFactory managerFactory = null; Map<String, String> persistenceMap = new HashMap<String, String>(); persistenceMap.put("javax.persistence.jdbc.url", DB_URL); persistenceMap.put("javax.persistence.jdbc.user", DB_USER); persistenceMap.put("javax.persistence.jdbc.password", DB_PWD); URL resource = ClassLoader.getSystemResource(""); File file = new File(String.valueOf(resource)); managerFactory = Persistence.createEntityManagerFactory("A2PPU", persistenceMap); mManager = managerFactory.createEntityManager(); deviceProvider = new JDBCDeviceProvider(mManager); } catch (Exception except) { except.printStackTrace(); System.exit(1); } }
From source file:com.blackducksoftware.tools.commonframework.core.config.ConfigurationManagerTest.java
@Test public void testConfigFileWithOnlyServerList() { final String fullLocationFileWithList = ClassLoader.getSystemResource(testFileWithOnlyServerList).getFile(); final ConfigurationManager protexCM = new TestConfigurationManagerBean(fullLocationFileWithList); final ServerBean protexServerBean = protexCM.getServerBean(protex); Assert.assertEquals("bla_protex", protexServerBean.getServerName()); }
From source file:Proiect.uploadFTP.java
public uploadFTP() { uploadFTP.setIconImage(//from ww w .j a va2s . com Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("assets/ico.png"))); uploadFTP.setUndecorated(true); uploadFTP.getRootPane().setBorder(BorderFactory.createLineBorder(Encrypter.color_black, 2)); uploadFTP.setSize(400, 240); uploadFTP.setLocationRelativeTo(Encrypter.Center); uploadFTP.setResizable(false); uploadFTP.setVisible(true); cm.registerComponent(uploadFTP); uploadFTP.setLayout(new BorderLayout()); pan1.setLayout(new BorderLayout()); pan2.setLayout(new BorderLayout()); inpan1.setLayout(new GridLayout(6, 2, 0, 10)); inpan2.setLayout(new GridLayout(1, 2, 20, 0)); pan3.setLayout(new BorderLayout()); pan4.setLayout(new FlowLayout()); uploadFTP.add(pan3, BorderLayout.EAST); pan3.add(adv, BorderLayout.SOUTH); uploadFTP.add(pan1, BorderLayout.NORTH); pan1.add(titleFTP, BorderLayout.WEST); pan1.add(exit, BorderLayout.EAST); uploadFTP.add(pan2, BorderLayout.CENTER); pan2.add(inpan1, BorderLayout.NORTH); inpan1.add(adress); inpan1.add(adressf); inpan1.add(user); inpan1.add(userf); inpan1.add(pass); inpan1.add(passf); inpan1.add(folder); inpan1.add(folderf); inpan1.add(filen); inpan1.add(filenf); inpan1.add(status); pan2.add(inpan2, BorderLayout.SOUTH); inpan2.add(browsef); inpan2.add(connect); uploadFTP.add(pan4, BorderLayout.WEST); propFTP(); actionFTP(); /* BOF Load state */ try { FileInputStream fileStream = new FileInputStream( ClassLoader.getSystemResource("upload.prop").getPath()); ObjectInputStream os = new ObjectInputStream(fileStream); adressf.setText(os.readObject().toString()); userf.setText(os.readObject().toString()); passf.setText(os.readObject().toString()); os.close(); fileStream.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } catch (ClassNotFoundException e1) { e1.printStackTrace(); } /* EOF Load state */ }
From source file:org.wso2.iot.integration.device.enrollment.WindowsEnrollment.java
private String readXML(String fileName, String characterEncoding) throws Exception { URL url = ClassLoader.getSystemResource(fileName); File folder = new File(url.toURI()); return FileUtils.readFileToString(folder, characterEncoding); }
From source file:org.apache.rya.jena.jenasesame.JenaReasoningWithRulesTest.java
private static void loadRdfFile(final Repository repo, final String rdfRelativeFileName) throws RepositoryException, RDFParseException, IOException { RepositoryConnection addConnection = null; try {//from w w w. j a v a 2s .c o m // Load some data. addConnection = repo.getConnection(); // Reads files relative from target/test-classes which should have been copied from src/test/resources final URL url = ClassLoader.getSystemResource(rdfRelativeFileName); final File file = ResourceUtils.getFile(url); final String fileName = file.getAbsolutePath(); final RDFFormat rdfFormat = RDFFormat.forFileName(fileName); log.info("Added RDF file with " + rdfFormat.getName() + " format: " + fileName); addConnection.add(file, "http://base/", rdfFormat); addConnection.close(); } finally { if (addConnection != null && addConnection.isOpen()) { addConnection.close(); } } }
From source file:Gouraud.java
/** * Erstellt den Szenegraphen//from w ww. ja v a 2 s.c o m * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { // Laden der Obj Datei mittels jar scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { System.err.println(e); System.exit(1); } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }
From source file:com.joliciel.jochre.JochreServiceLocator.java
private Properties getDataSourceProperties() { if (dataSourceProperties == null && (this.getDataSourcePropertiesResource() != null || this.getDataSourcePropertiesFile() != null)) { dataSourceProperties = new Properties(); try {//from w w w. j a v a 2 s . c om String filePath = null; if (this.getDataSourcePropertiesFile() != null) { filePath = this.getDataSourcePropertiesFile(); } else if (this.getDataSourcePropertiesResource() != null) { LOG.debug("Loading database properties from: " + this.getDataSourcePropertiesResource()); URL url = ClassLoader.getSystemResource(this.getDataSourcePropertiesResource()); filePath = url.getFile(); } FileInputStream fis = new FileInputStream(filePath); dataSourceProperties.load(fis); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } } return dataSourceProperties; }
From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java
@Test public void spamEmailShouldBeWellConvertedToJson() throws IOException { MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson( new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES); MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET, new SharedByteArrayInputStream( IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/spamMail.eml"))), new Flags(), propertyBuilder, MAILBOX_ID); spamMail.setUid(UID);/*w w w . j a v a2 s. co m*/ spamMail.setModSeq(MOD_SEQ); assertThatJson(messageToElasticSearchJson.convertToJson(spamMail, ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER) .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/spamMail.json"), CHARSET)); }