List of usage examples for java.lang ClassLoader getResource
public URL getResource(String name)
From source file:com.datatorrent.stram.api.IotDev.java
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { ClassLoader loader = IotDev.class.getClassLoader(); LOG.debug(String.valueOf(loader.getResource("\n\nPATH : \nfoo/Test.class"))); FileInputStream f = new FileInputStream("/home/" + name + "/fileURL"); LinkedHashSet<URL> launchDependencies = read(f); loadDependencies(launchDependencies); LOG.debug("\n\nURLS\n\n"); for (URL l : launchDependencies) { LOG.debug("\n URL " + l); }//from w w w . j a va 2 s .c o m // FileInputStream fis = new FileInputStream("./" + LogicalPlan.SER_FILE_NAME); FileInputStream fis = new FileInputStream("/home/" + name + "/file"); try { lp = LogicalPlan.read(fis); } finally { fis.close(); } StramLocalCluster lc = new StramLocalCluster(lp); lc.run(); }
From source file:com.estafeta.flujos.DemoMain.java
/** * Clase principal del proyecto/*from w ww . j a va 2s . c om*/ * @param args argumentos de linea de comandos */ public static void main(String[] args) { // init spring context ApplicationContext ctx = new ClassPathXmlApplicationContext(APPLOCATION_CONTEXT_FILE); // get bean from context JmsMessageSender jmsMessageSender = (JmsMessageSender) ctx.getBean(JMS_MESSAGE_SENDER_BEAN_NAME); // send to a code specified destination Queue queue = new ActiveMQQueue(JMS_DESTINATION_NAME); try { ClassLoader classLoader = DemoMain.class.getClassLoader(); FileInputStream fileInputStream = new FileInputStream( classLoader.getResource(MOCK_INPUT_FILE).getFile()); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(fileInputStream, Charset.forName(UTF_8_CHARSET))); String line; while ((line = bufferedReader.readLine()) != null) { jmsMessageSender.send(queue, line); } fileInputStream.close(); } catch (Exception e) { e.printStackTrace(); } // close spring application context ((ClassPathXmlApplicationContext) ctx).close(); }
From source file:com.mycompany.kerberosbyip.NewMain.java
public static void main(String[] args) throws Exception { Logger logger = Logger.getLogger("org.apache.http"); logger.setLevel(Level.TRACE); System.setProperty("sun.security.krb5.debug", "true"); System.setProperty("java.security.krb5.realm", REALM); System.setProperty("java.security.krb5.kdc", KDC); ClassLoader classLoader = NewMain.class.getClassLoader(); URL loginConf = classLoader.getResource("login.conf"); System.setProperty("java.security.auth.login.config", loginConf.toString()); NewMain m = new NewMain(); m.runPrivileged();/* www . ja va 2 s .c o m*/ }
From source file:com.tonygalati.sprites.SpriteGenerator.java
public static void main(String[] args) throws IOException { // if (args.length != 3) // {// www .j a v a2 s . com // System.out.print("Usage: com.tonygalati.sprites.SpriteGenerator {path to images} {margin between images in px} {output file}\n"); // System.out.print("Note: The max height should only be around 32,767px due to Microsoft GDI using a 16bit signed integer to store dimensions\n"); // System.out.print("going beyond this dimension is possible with this tool but the generated sprite image will not work correctly with\n"); // System.out.print("most browsers.\n\n"); // return; // } // Integer margin = Integer.parseInt(args[1]); Integer margin = Integer.parseInt("1"); String spriteFile = "icons-" + RandomStringUtils.randomAlphanumeric(10) + ".png"; SpriteCSSGenerator cssGenerator = new SpriteCSSGenerator(); ClassLoader classLoader = SpriteGenerator.class.getClassLoader(); URL folderPath = classLoader.getResource(NAIC_SMALL_ICON); if (folderPath != null) { File imageFolder = new File(folderPath.getPath()); // Read images ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>(); Integer yCoordinate = null; for (File f : imageFolder.listFiles()) { if (f.isFile()) { String fileName = f.getName(); String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); if (ext.equals("png")) { System.out.println("adding file " + fileName); BufferedImage image = ImageIO.read(f); imageList.add(image); if (yCoordinate == null) { yCoordinate = 0; } else { yCoordinate += (image.getHeight() + margin); } // add to cssGenerator cssGenerator.addSpriteCSS(fileName.substring(0, fileName.indexOf(".")), 0, yCoordinate); } } } // Find max width and total height int maxWidth = 0; int totalHeight = 0; for (BufferedImage image : imageList) { totalHeight += image.getHeight() + margin; if (image.getWidth() > maxWidth) maxWidth = image.getWidth(); } System.out.format("Number of images: %s, total height: %spx, width: %spx%n", imageList.size(), totalHeight, maxWidth); // Create the actual sprite BufferedImage sprite = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB); int currentY = 0; Graphics g = sprite.getGraphics(); for (BufferedImage image : imageList) { g.drawImage(image, 0, currentY, null); currentY += image.getHeight() + margin; } System.out.format("Writing sprite: %s%n", spriteFile); ImageIO.write(sprite, "png", new File(spriteFile)); File cssFile = cssGenerator.getFile(spriteFile); System.out.println(cssFile.getAbsolutePath() + " created"); } else { System.err.println("Could not find folder: " + NAIC_SMALL_ICON); } }
From source file:com.adhi.webserver.WebServer.java
public static void main(String[] args) throws Exception { int port = 9999; // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build();/*from w ww. j av a 2 s .c om*/ // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new MessageCommandHandler()); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; if (port == 8443) { // Initialize SSL context ClassLoader cl = WebServer.class.getClassLoader(); URL url = cl.getResource("my.keystore"); if (url == null) { System.out.println("Keystore not found"); System.exit(1); } KeyStore keystore = KeyStore.getInstance("jks"); keystore.load(url.openStream(), "secret".toCharArray()); KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, "secret".toCharArray()); KeyManager[] keymanagers = kmfactory.getKeyManagers(); SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); sf = sslcontext.getServerSocketFactory(); } Thread t = new RequestListenerThread(port, httpService, sf); t.setDaemon(false); t.start(); }
From source file:proxy.NHttpServer.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Please specify document root directory"); System.exit(1);//from w w w . j av a 2 s . co m } // Document root directory File docRoot = new File(args[0]); int port = 8080; if (args.length >= 2) { port = Integer.parseInt(args[1]); } // Create HTTP protocol processing chain HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build(); // Create request handler registry UriHttpAsyncRequestHandlerMapper reqistry = new UriHttpAsyncRequestHandlerMapper(); // Register the default handler for all URIs reqistry.register("*", new HttpFileHandler(docRoot)); // Create server-side HTTP protocol handler HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, reqistry) { @Override public void connected(final NHttpServerConnection conn) { System.out.println(conn + ": connection open"); super.connected(conn); } @Override public void closed(final NHttpServerConnection conn) { System.out.println(conn + ": connection closed"); super.closed(conn); } }; // Create HTTP connection factory NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory; if (port == 8443) { // Initialize SSL context ClassLoader cl = NHttpServer.class.getClassLoader(); URL url = cl.getResource("my.keystore"); if (url == null) { System.out.println("Keystore not found"); System.exit(1); } KeyStore keystore = KeyStore.getInstance("jks"); keystore.load(url.openStream(), "secret".toCharArray()); KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, "secret".toCharArray()); KeyManager[] keymanagers = kmfactory.getKeyManagers(); SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); connFactory = new SSLNHttpServerConnectionFactory(sslcontext, null, ConnectionConfig.DEFAULT); } else { connFactory = new DefaultNHttpServerConnectionFactory(ConnectionConfig.DEFAULT); } // Create server-side I/O event dispatch IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory); // Set I/O reactor defaults IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(1).setSoTimeout(3000) .setConnectTimeout(3000).build(); // Create server-side I/O reactor ListeningIOReactor ioReactor = new DefaultListeningIOReactor(config); try { // Listen of the given port ioReactor.listen(new InetSocketAddress(port)); // Ready to go! ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } System.out.println("Shutdown"); }
From source file:com.bfd.job.testClient.t04.ElementalHttpServer.java
public static void main(String[] args) throws Exception { /**//ww w. ja v a 2 s. c o m * if (args.length < 1) { * System.err.println("Please specify document root directory"); * System.exit(1); } // Document root directory String docRoot = * args[0]; */ String docRoot = "c:/root"; int port = 8080; if (args.length >= 2) { port = Integer.parseInt(args[1]); } // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new HttpFileHandler(docRoot)); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; if (port == 8443) { // Initialize SSL context ClassLoader cl = ElementalHttpServer.class.getClassLoader(); URL url = cl.getResource("my.keystore"); if (url == null) { System.out.println("Keystore not found"); System.exit(1); } KeyStore keystore = KeyStore.getInstance("jks"); keystore.load(url.openStream(), "secret".toCharArray()); KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, "secret".toCharArray()); KeyManager[] keymanagers = kmfactory.getKeyManagers(); SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); sf = sslcontext.getServerSocketFactory(); } Thread t = new RequestListenerThread(port, httpService, sf); t.setDaemon(false); t.start(); }
From source file:yucatan.communication.server.NHttpServer.java
public static void main(String[] args) throws Exception { if (args.length < 1) { System.err.println("Please specify document root directory"); System.exit(1);// w w w. jav a 2 s .c o m } // Document root directory File docRoot = new File(args[0]); int port = 8080; if (args.length >= 2) { port = Integer.parseInt(args[1]); } // HTTP parameters for the server HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpTest/1.1"); // Create HTTP protocol processing chain HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { // Use standard server-side protocol interceptors new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); // Create request handler registry HttpAsyncRequestHandlerRegistry reqistry = new HttpAsyncRequestHandlerRegistry(); // Register the default handler for all URIs reqistry.register("*", new HttpFileHandler(docRoot)); // Create server-side HTTP protocol handler HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, new DefaultConnectionReuseStrategy(), reqistry, params) { @Override public void connected(final NHttpServerConnection conn) { System.out.println(conn + ": connection open"); super.connected(conn); } @Override public void closed(final NHttpServerConnection conn) { System.out.println(conn + ": connection closed"); super.closed(conn); } }; // Create HTTP connection factory NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory; if (port == 8443) { // Initialize SSL context ClassLoader cl = NHttpServer.class.getClassLoader(); URL url = cl.getResource("my.keystore"); if (url == null) { System.out.println("Keystore not found"); System.exit(1); } KeyStore keystore = KeyStore.getInstance("jks"); keystore.load(url.openStream(), "secret".toCharArray()); KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, "secret".toCharArray()); KeyManager[] keymanagers = kmfactory.getKeyManagers(); SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); connFactory = new SSLNHttpServerConnectionFactory(sslcontext, null, params); } else { connFactory = new DefaultNHttpServerConnectionFactory(params); } // Create server-side I/O event dispatch IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory); // Create server-side I/O reactor ListeningIOReactor ioReactor = new DefaultListeningIOReactor(); try { // Listen of the given port ioReactor.listen(new InetSocketAddress(port)); // Ready to go! ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } System.out.println("Shutdown"); }
From source file:httpserver.ElementalHttpServer.java
public static void main(String[] args) throws Exception { // Clay code, adding arguments to simulate command line execution args = new String[2]; args[0] = "C://Users/Clay/Documents"; args[1] = "80"; if (args.length < 1) { System.err.println("Please specify document root directory"); System.exit(1);//from ww w .j av a 2 s . c o m } // Document root directory String docRoot = args[0]; // Setting up port, if port was specified, then use that one int port = 8080; if (args.length >= 2) { port = Integer.parseInt(args[1]); } // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("Test/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new HttpFileHandler(docRoot)); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; if (port == 8443) { // Initialize SSL context ClassLoader cl = ElementalHttpServer.class.getClassLoader(); URL url = cl.getResource("my.keystore"); if (url == null) { System.out.println("Keystore not found"); System.exit(1); } KeyStore keystore = KeyStore.getInstance("jks"); keystore.load(url.openStream(), "secret".toCharArray()); KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, "secret".toCharArray()); KeyManager[] keymanagers = kmfactory.getKeyManagers(); SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); sf = sslcontext.getServerSocketFactory(); } Thread t = new RequestListenerThread(port, httpService, sf); t.setDaemon(false); t.start(); }
From source file:za.co.taung.httpdotserver.main.HttpDotServer.java
public static void main(String[] args) throws Exception { LOG.info("Initialise server"); // The parameter is the Port to listen on. Default is 8080. int port = 8080; if (args.length >= 1) { port = Integer.parseInt(args[0]); }/*from w w w .j a v a 2 s . co m*/ // Set up the HTTP protocol processor. HttpProcessor httpProcessor = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("HttpDotServer/1.1")).add(new ResponseContent()) .add(new ResponseConnControl()).build(); // Set up request handler. This is the method that generates SVG. UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new Dot2SVGHandler()); // Set up the HTTP service. HttpService httpService = new HttpService(httpProcessor, reqistry); // Set up SSL if listening on 8443 for https. SSLServerSocketFactory serverSocketFactory = null; if (port == 8443) { // Get the location of the keystore secrets. ClassLoader cl = HttpDotServer.class.getClassLoader(); URL url = cl.getResource("my.keystore"); if (url == null) { LOG.error("Keystore not found"); System.exit(1); } // Load the secret into a keystore and manage the key material. KeyStore keystore = KeyStore.getInstance("jks"); keystore.load(url.openStream(), "secret".toCharArray()); KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmfactory.init(keystore, "secret".toCharArray()); KeyManager[] keymanagers = kmfactory.getKeyManagers(); // Prepare the socket factory for use by the RequestListenerThread. SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(keymanagers, null, null); serverSocketFactory = sslcontext.getServerSocketFactory(); } LOG.debug("Start the RequestListenerThread"); Thread thread = new RequestListenerThread(port, httpService, serverSocketFactory); thread.setDaemon(false); thread.start(); }