List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:com.fluke.application.EODReader.java
public static void main(String[] args) throws IOException, ParseException, SQLException { List<String> list = IOUtils.readLines(ClassLoader.getSystemResourceAsStream("config/stocks")); new EODDao().deleteLastData(); for (String eq : new EquityDao().getAllEquity()) { System.out.println("" + eq); YahooEODParser parser = new YahooEODParser(eq); parser.process();/*from w ww .j a va 2 s. c o m*/ } }
From source file:com.fluke.application.IEODReader.java
public static void main(String[] args) throws IOException { String location = "/home/arshed/Pictures/sample"; list = IOUtils.readLines(ClassLoader.getSystemResourceAsStream("config/stocks")); File folder = new File(location); processFolder(Arrays.asList(folder)); }
From source file:net.minder.httpcap.HttpCap.java
public static void main(String[] args) throws Exception { PropertyConfigurator.configure(ClassLoader.getSystemResourceAsStream("log4j.properties")); int port = DEFAULT_PORT; if (args.length > 0) { try {//from w ww. java2s . co m port = Integer.parseInt(args[0]); } catch (NumberFormatException nfe) { port = DEFAULT_PORT; } } HttpProcessor httpproc = HttpProcessorBuilder.create().add(new ResponseDate()) .add(new ResponseServer("HttpCap/1.1")).add(new ResponseContent()).add(new ResponseConnControl()) .build(); UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new HttpCapHandler()); // Set up the HTTP service HttpService httpService = new HttpService(httpproc, reqistry); SSLServerSocketFactory sf = null; // if (port == 8443) { // // Initialize SSL context // ClassLoader cl = HttpCap.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:de.uzk.hki.da.main.SIPBuilder.java
public static void main(String[] args) { TTCCLayout layout = new TTCCLayout(); layout.setDateFormat("yyyy'-'MM'-'dd' 'HH':'mm':'ss"); layout.setThreadPrinting(false);/* w w w . j a va 2 s . c o m*/ ConsoleAppender consoleAppender = new ConsoleAppender(layout); logger.addAppender(consoleAppender); logger.setLevel(Level.DEBUG); properties = new Properties(); try { properties.load(new InputStreamReader( (ClassLoader.getSystemResourceAsStream("configuration/config.properties")))); } catch (FileNotFoundException e1) { System.exit(Feedback.GUI_ERROR.toInt()); } catch (IOException e2) { System.exit(Feedback.GUI_ERROR.toInt()); } try { if (SystemUtils.IS_OS_WINDOWS) System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "CP850")); else System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "UTF-8")); } catch (UnsupportedEncodingException e) { return; } String mainFolderPath = SIPBuilder.class.getProtectionDomain().getCodeSource().getLocation().getPath(); String confFolderPath, dataFolderPath; try { mainFolderPath = URLDecoder.decode(mainFolderPath, "UTF-8"); confFolderPath = new File(mainFolderPath).getParent() + File.separator + "conf"; dataFolderPath = new File(mainFolderPath).getParent() + File.separator + "data"; } catch (UnsupportedEncodingException e) { confFolderPath = "conf"; dataFolderPath = "data"; } System.out.println("ConfFolderPath:" + confFolderPath); if (args.length == 0) startGUIMode(confFolderPath, dataFolderPath); else startCLIMode(confFolderPath, dataFolderPath, args); }
From source file:org.apache.zeppelin.example.app.horizontalbar.HorizontalBar.java
/** * Development mode/*w w w.j a va 2 s . c om*/ */ public static void main(String[] args) throws Exception { LocalResourcePool pool = new LocalResourcePool("dev"); InputStream ins = ClassLoader .getSystemResourceAsStream("example/app/horizontalbar/horizontalbar_mockdata.txt"); InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, InterpreterResult.Type.TABLE, IOUtils.toString(ins)); pool.put(WellKnownResourceName.ZeppelinTableResult.name(), result); ZeppelinApplicationDevServer devServer = new ZeppelinApplicationDevServer(HorizontalBar.class.getName(), pool.getAll()); devServer.start(); devServer.join(); }
From source file:org.smurn.jply.lwjgldemo.LWJGLDemo.java
public static void main(String[] args) throws LWJGLException, IOException { // Open a openGL enabled window. Display.setTitle("jPLY LWJGL Demo"); Display.setDisplayMode(new DisplayMode(600, 600)); Display.create();/* w w w. j a v a 2 s. co m*/ // Open the PLY file PlyReader plyReader = new PlyReaderFile(ClassLoader.getSystemResourceAsStream("bunny.ply")); // Normalize the data in the PLY file to ensure that we only get // triangles and that the vertices have normal vectors assigned. plyReader = new NormalizingPlyReader(plyReader, TesselationMode.TRIANGLES, NormalMode.ADD_NORMALS_CCW, TextureMode.PASS_THROUGH); // We can get the number of vertices and triangles before // reading it. We will use this to allocate buffers of the right size. int vertexCount = plyReader.getElementCount("vertex"); int triangleCount = plyReader.getElementCount("face"); // Number of bytes we need per vertex. // Three position coordinates and three normal vector coordinates // all stored as 32-bit float. int vertexSize = 3 * 4 + 3 * 4; // Number of bytes we need per triangle. // Three indices to vertices stored as 32-bit integer. int triangleSize = 3 * 4; // A bit of opengl magic to allocate a vertex-buffer-object to // store the vertices. int vertexBufferId = glGenBuffersARB(); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBufferId); glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertexCount * vertexSize, GL_STATIC_DRAW_ARB); FloatBuffer vertexBuffer = glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB, null).asFloatBuffer(); // The same magic again for the index buffer storing the triangles. int indexBufferId = glGenBuffersARB(); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexBufferId); glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, triangleCount * triangleSize, GL_STATIC_DRAW_ARB); IntBuffer indexBuffer = glMapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB, null).asIntBuffer(); // Now we READ THE PLY DATA into the buffers. // We also measure the size of the model so that we can later fit // arbitrary models into the screen. RectBounds bounds = fillBuffers(plyReader, vertexBuffer, indexBuffer); // Tell openGL that we filled the buffers. glUnmapBufferARB(GL_ARRAY_BUFFER_ARB); glUnmapBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB); // Create the vertex and fragment shader for nice phong shading. int programId = createShaders(); // The shaders have a few parameters to configure the three lights. // Each parameter has an identifier which we query here. // Vector in the direction towards the light. int[] lightDirection = new int[] { glGetUniformLocationARB(programId, "lightDir[0]"), glGetUniformLocationARB(programId, "lightDir[1]"), glGetUniformLocationARB(programId, "lightDir[2]") }; // Color of the diffuse part of the light. int[] diffuseColor = new int[] { glGetUniformLocationARB(programId, "diffuseColor[0]"), glGetUniformLocationARB(programId, "diffuseColor[1]"), glGetUniformLocationARB(programId, "diffuseColor[2]") }; // Color of the specular (high-lights) part of the light. int[] specularColor = new int[] { glGetUniformLocationARB(programId, "specularColor[0]"), glGetUniformLocationARB(programId, "specularColor[1]"), glGetUniformLocationARB(programId, "specularColor[2]") }; // Exponent controlling the size of the specular light. int[] shininess = new int[] { glGetUniformLocationARB(programId, "shininess[0]"), glGetUniformLocationARB(programId, "shininess[1]"), glGetUniformLocationARB(programId, "shininess[2]") }; // Configure the three light sources. glUseProgramObjectARB(programId); glUniform3fARB(lightDirection[0], -0.9f, 0.9f, 1f); glUniform4fARB(diffuseColor[0], 0.7f, 0.7f, 0.7f, 1.0f); glUniform4fARB(specularColor[0], 1.0f, 1.0f, 1.0f, 1.0f); glUniform1fARB(shininess[0], 50.0f); glUniform3fARB(lightDirection[1], 0.6f, 0.1f, 1f); glUniform4fARB(diffuseColor[1], 0.1f, 0.1f, 0.1f, 1.0f); glUniform4fARB(specularColor[1], 0.0f, 0.0f, 0.0f, 1.0f); glUniform1fARB(shininess[1], 50.0f); glUniform3fARB(lightDirection[2], 0.0f, 0.8f, -1f); glUniform4fARB(diffuseColor[2], 0.8f, 0.8f, 0.8f, 1.0f); glUniform4fARB(specularColor[2], 0.0f, 0.0f, 0.0f, 1.0f); glUniform1fARB(shininess[2], 50.0f); // Some more openGL setup. glFrontFace(GL_CCW); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-1, 1, -1, 1, -100, 100); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); // Tell openGL to use the buffers we filled with the data from // the PLY file. glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexBufferId); glVertexPointer(3, GL11.GL_FLOAT, 24, 0); glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexBufferId); glNormalPointer(GL11.GL_FLOAT, 24, 12); // Find out to where we need to move the object and how we need // to scale it such that it fits into the window. double scale = bounds.getScaleToUnityBox() * 1.5; double[] center = bounds.getCenter(); // Some state variables to let the model rotate via mouse double yawStart = 0; double pitchStart = 0; boolean mouseMoves = false; int mouseStartX = 0; int mouseStartY = 0; // See if we've run into a problem so far. Util.checkGLError(); // Rendering loop until the window is clsoed. while (!Display.isCloseRequested()) { // Empty the buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Mouse handling for the model rotation double yaw = yawStart; double pitch = pitchStart; if (mouseMoves) { double deltaX = Mouse.getX() - mouseStartX; double deltaY = Mouse.getY() - mouseStartY; double deltaYaw = deltaX * 0.3; double deltaPitch = -deltaY * 0.3; yaw += deltaYaw; pitch += deltaPitch; if (!Mouse.isButtonDown(0)) { mouseMoves = false; yawStart += deltaYaw; pitchStart += deltaPitch; } } else if (!mouseMoves && Mouse.isButtonDown(0)) { mouseStartX = Mouse.getX(); mouseStartY = Mouse.getY(); mouseMoves = true; } // Build the model matrix that fits the model into the // screen and does the rotation. glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotated(pitch, 1, 0, 0); glRotated(yaw, 0, 1, 0); glScaled(scale, scale, scale); glTranslated(-center[0], -center[1], -center[2]); // Finally we can draw the model! glDrawElements(GL_TRIANGLES, triangleCount * 3, GL_UNSIGNED_INT, 0); // See if we've run into a problem. Util.checkGLError(); // Lets show what we just have drawn. Display.update(); } // Cleanup opengl. Display.destroy(); }
From source file:sanghoon.flickr.photos.Search.java
public static void main(String[] args) { if (args.length < 1) { String header = "\n" + "Return a list of photos matching some criteria. " + "\n" + "https://www.flickr.com/services/api/flickr.photos.search.html" + "\n\n"; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java " + Search.class.getName() + " [OPTIONS]...", header, createOptions(), ""); return;/*w ww . j ava 2 s.c om*/ } CommandLineParser parser = new DefaultParser(); CommandLine line; try { line = parser.parse(createOptions(), args); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); return; } String tags = line.hasOption("tags") ? line.getOptionValue("tags") : null; String machineTags = line.hasOption("machine-tags") ? line.getOptionValue("machine-tags") : null; String minUploadDate = line.hasOption("min-upload-date") ? line.getOptionValue("min-upload-date") : null; String maxUploadDate = line.hasOption("max-upload-date") ? line.getOptionValue("max-upload-date") : null; String minTakenDate = line.hasOption("min-taken-date") ? line.getOptionValue("min-taken-date") : null; String maxTakenDate = line.hasOption("max-taken-date") ? line.getOptionValue("max-taken-date") : null; String bbox = line.hasOption("bounding-box") ? line.getOptionValue("bounding-box") : null; String woeID = line.hasOption("woe-id") ? line.getOptionValue("woe-id") : null; String placeID = line.hasOption("place-id") ? line.getOptionValue("place-id") : null; int page = line.hasOption("page") ? Integer.parseInt(line.getOptionValue("page")) : 1; OutputFormat outputFormat = line.hasOption("format") ? OutputFormat.valueOf(line.getOptionValue("format").toUpperCase()) : OutputFormat.XML; File outputFile = line.hasOption("output-file") ? new File(line.getOptionValue("output-file")) : null; ApiKey key = ApiKey.load(ClassLoader.getSystemResourceAsStream("flickr_api_key.properties")); long beginTime = System.currentTimeMillis(); List<Photo> photoList = run(key, tags, machineTags, minUploadDate, maxUploadDate, minTakenDate, maxTakenDate, bbox, woeID, placeID, page, outputFormat, outputFile); System.err.println( photoList.size() + " photos are retrieved (" + (System.currentTimeMillis() - beginTime) + "ms)."); }
From source file:mx.unam.fesa.mss.MSSMain.java
/** * @param args/*from www . j a v a 2s. c o m*/ */ @SuppressWarnings("static-access") public static void main(String[] args) { // // managing command line options using commons-cli // Options options = new Options(); // help option // options.addOption( OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP)); // port option // options.addOption(OptionBuilder.withDescription("The port in which the MineSweeperServer will listen to.") .hasArg().withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT)); // parsing options // int port = DEFAULT_PORT; try { // using GNU standard // CommandLine line = new GnuParser().parse(options, args); if (line.hasOption(OPT_HELP)) { new HelpFormatter().printHelp("mss [options]", options); return; } if (line.hasOption(OPT_PORT)) { try { port = (Integer) line.getOptionObject(OPT_PORT); } catch (Exception e) { } } } catch (ParseException e) { System.err.println("Could not parse command line options correctly: " + e.getMessage()); return; } // // configuring logging services // try { LogManager.getLogManager() .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE)); } catch (Exception e) { throw new Error("Could not load logging properties file", e); } // // setting up UDP server // try { new MSServer(port); } catch (Exception e) { LoggerFactory.getLogger(MSSMain.class).error("Could not execute MineSweeper server: ", e); } }
From source file:mx.unam.fesa.isoo.msp.MSPMain.java
/** * @param args/*from ww w .j a v a 2 s . c o m*/ * @throws Exception */ @SuppressWarnings("static-access") public static void main(String[] args) { // // creating options // Options options = new Options(); // help option // options.addOption( OptionBuilder.withDescription("Prints this message.").withLongOpt("help").create(OPT_HELP)); // server option // options.addOption(OptionBuilder.withDescription("The server this MineSweeperPlayer will connect to.") .hasArg().withArgName("SERVER").withLongOpt("server").create(OPT_SERVER)); // port option // options.addOption(OptionBuilder.withDescription("The port this MineSweeperPlayer will connect to.").hasArg() .withType(new Integer(0)).withArgName("PORT").withLongOpt("port").create(OPT_PORT)); // parsing options // String hostname = DEFAULT_SERVER; int port = DEFAULT_PORT; try { // using GNU standard // CommandLine line = new GnuParser().parse(options, args); if (line.hasOption(OPT_HELP)) { new HelpFormatter().printHelp("msc [options]", options); return; } if (line.hasOption(OPT_PORT)) { try { port = (Integer) line.getOptionObject(OPT_PORT); } catch (Exception e) { } } if (line.hasOption(OPT_SERVER)) { hostname = line.getOptionValue(OPT_PORT); } } catch (ParseException e) { System.err.println("Could not parse command line options correctly: " + e.getMessage()); return; } // // configuring logging services // try { LogManager.getLogManager() .readConfiguration(ClassLoader.getSystemResourceAsStream(DEFAULT_LOGGING_CONFIG_FILE)); } catch (Exception e) { throw new Error("Could not load logging properties file.", e); } // // setting up Mine Sweeper client // try { new MSClient(hostname, port); } catch (Exception e) { System.err.println("Could not execute MineSweeper client: " + e.getMessage()); } }
From source file:sanghoon.flickr.photos.Dump.java
public static void main(String[] args) throws FileNotFoundException { // args = new String[] { "-b", "-122.373971375,47.55575575,-122.3455185,47.585350625000004" }; if (args.length < 1) { String header = "\n" + "Download all photos matching some criteria, using flickr.photos.search API." + "\n\n"; HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java " + Dump.class.getName() + " [OPTIONS]...", header, createOptions(), ""); return;//from w w w . j a v a2 s . c o m } CommandLineParser parser = new DefaultParser(); CommandLine line; try { line = parser.parse(createOptions(), args); } catch (ParseException exp) { System.err.println("Parsing failed. Reason: " + exp.getMessage()); return; } String tags = line.hasOption("tags") ? line.getOptionValue("tags") : null; String minTakenDate = line.hasOption("min-taken-date") ? line.getOptionValue("min-taken-date") : null; String maxTakenDate = line.hasOption("max-taken-date") ? line.getOptionValue("max-taken-date") : null; String bbox = line.hasOption("bounding-box") ? line.getOptionValue("bounding-box") : null; if (bbox == null) { System.err.println("bounding box parameter is required"); return; } // TODO: places.find places.getInfo ? id bounding box // String woeID = line.hasOption("woe-id") ? line.getOptionValue("woe-id") : null; // String placeID = line.hasOption("place-id") ? line.getOptionValue("place-id") : null; String outputFilePrefix = line.hasOption("output-file-prefix") ? line.getOptionValue("output-file-prefix") : "output"; ApiKey key = ApiKey.load(ClassLoader.getSystemResourceAsStream("flickr_api_key.properties")); Map<String, String> outputs = new HashMap<>(); String[] coords = bbox.split(","); double minimum_longitude = Double.parseDouble(coords[0]); double minimum_latitude = Double.parseDouble(coords[1]); double maximum_longitude = Double.parseDouble(coords[2]); double maximum_latitude = Double.parseDouble(coords[3]); LinkedList<BoundingBox> bboxes = new LinkedList<>(); bboxes.add(new BoundingBox(minimum_longitude, minimum_latitude, maximum_longitude, maximum_latitude)); int index = 0; while (bboxes.isEmpty() == false) { BoundingBox box = bboxes.pollFirst(); int page = 1; System.out.print("searching for " + box.toString() + " ."); Integer total = search(key, box, tags, minTakenDate, maxTakenDate, page, outputs); if (total == null) { bboxes.addLast(box); System.out.println(" failed, retry later"); continue; } else if (MAX_PHOTOS_IN_A_BBOX < total) { // Please note that Flickr will return at most the first 4,000 results for any given search query. // If this is an issue, we recommend trying a more specific query. // List<BoundingBox> splitBoxes = box.split(); for (BoundingBox splitBox : splitBoxes) bboxes.addLast(splitBox); System.out.print(" " + total + " photos (>" + MAX_PHOTOS_IN_A_BBOX + "), split "); System.out.print("{"); for (int i = 0; i < splitBoxes.size(); i++) { if (0 < i) System.out.print(","); System.out.print("["); System.out.print(splitBoxes.get(i).toString()); System.out.print("]"); } System.out.print("}"); System.out.println(); continue; } else if (PER_PAGE < total) { // ? search box ? ? ? ? // (? ? PER_PAGE ?), // page ? while (page * PER_PAGE < total) { page++; search(key, box, tags, minTakenDate, maxTakenDate, page, outputs); System.out.print("."); } System.out.println(" " + total + " photos in " + page + " pages"); } if (MAX_PHOTOS_IN_AN_OUTPUT < outputs.size()) { // ? ? ? ? ? String filename = outputFilePrefix + "_" + index++ + ".json"; write(outputs, filename); outputs.clear(); } } String filename = outputFilePrefix + "_" + index++ + ".json"; write(outputs, filename); System.out.println("finished"); }