List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:Main.java
public static void main(String[] argv) throws Exception { URL url = new URL("http://java2s.com:80/index.html"); System.out.println(url.toURI()); }
From source file:com.glaf.core.util.AnnotationUtils.java
public static void main(String[] args) throws Exception { System.out.println(System.getProperty("java.class.path")); long start = System.currentTimeMillis(); Collection<String> entities = AnnotationUtils.findMapper("com.glaf"); long time = System.currentTimeMillis() - start; for (String str : entities) { System.out.println(str);//from w w w. j av a 2 s .c o m } System.out.println("time:" + time); URL[] urls = ClasspathUrlFinder.findResourceBases("com/glaf/package.properties", Thread.currentThread().getContextClassLoader()); for (URL url2 : urls) { logger.debug("->scan url:" + url2.toURI().toString()); } }
From source file:MLModelUsageSample.java
public static void main(String[] args) throws Exception { MLModelUsageSample modelUsageSample = new MLModelUsageSample(); // Path to downloaded-ml-model (downloaded-ml-model can be found inside resources folder) URL resource = MLModelUsageSample.class.getClassLoader().getResource("downloaded-ml-model"); String pathToDownloadedModel = new File(resource.toURI()).getAbsolutePath(); // Deserialize MLModel mlModel = modelUsageSample.deserializeMLModel(pathToDownloadedModel); // Predict/*w w w. j a v a 2 s . c om*/ String[] featureValueArray1 = new String[] { "2", "84", "0", "0", "0", "0.0", "0.304", "21" }; String[] featureValueArray2 = new String[] { "0", "101", "80", "40", "0", "26", "0.5", "33" }; ArrayList<String[]> list = new ArrayList<String[]>(); list.add(featureValueArray1); list.add(featureValueArray2); modelUsageSample.predict(list, mlModel); }
From source file:Test.java
public static void main(String[] args) throws Exception { final URL test = Test.class.getResource("/"); System.out.println(test);//from www . j a v a 2 s . co m final URL url = Test.class.getResource("/resources/test.txt"); System.out.println(url); if (url == null) { System.out.println("URL is null"); } else { final File file = new File(url.toURI()); final FileReader reader = new FileReader(file); final char[] buff = new char[20]; final int l = reader.read(buff); System.out.println(new String(buff, 0, l)); reader.close(); } }
From source file:UploadUrlGenerator.java
public static void main(String[] args) throws Exception { Options opts = new Options(); opts.addOption(Option.builder().longOpt(ENDPOINT_OPTION).required().hasArg().argName("url") .desc("Sets the ECS S3 endpoint to use, e.g. https://ecs.company.com:9021").build()); opts.addOption(Option.builder().longOpt(ACCESS_KEY_OPTION).required().hasArg().argName("access-key") .desc("Sets the Access Key (user) to sign the request").build()); opts.addOption(Option.builder().longOpt(SECRET_KEY_OPTION).required().hasArg().argName("secret") .desc("Sets the secret key to sign the request").build()); opts.addOption(Option.builder().longOpt(BUCKET_OPTION).required().hasArg().argName("bucket-name") .desc("The bucket containing the object").build()); opts.addOption(Option.builder().longOpt(KEY_OPTION).required().hasArg().argName("object-key") .desc("The object name (key) to access with the URL").build()); opts.addOption(Option.builder().longOpt(EXPIRES_OPTION).hasArg().argName("minutes") .desc("Minutes from local time to expire the request. 1 day = 1440, 1 week=10080, " + "1 month (30 days)=43200, 1 year=525600. Defaults to 1 hour (60).") .build());/*ww w.ja v a2s .co m*/ opts.addOption(Option.builder().longOpt(VERB_OPTION).hasArg().argName("http-verb").type(HttpMethod.class) .desc("The HTTP verb that will be used with the URL (PUT, GET, etc). Defaults to GET.").build()); opts.addOption(Option.builder().longOpt(CONTENT_TYPE_OPTION).hasArg().argName("mimetype") .desc("Sets the Content-Type header (e.g. image/jpeg) that will be used with the request. " + "Must match exactly. Defaults to application/octet-stream for PUT/POST and " + "null for all others") .build()); DefaultParser dp = new DefaultParser(); CommandLine cmd = null; try { cmd = dp.parse(opts, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar UploadUrlGenerator-xxx.jar", opts, true); System.exit(255); } URI endpoint = URI.create(cmd.getOptionValue(ENDPOINT_OPTION)); String accessKey = cmd.getOptionValue(ACCESS_KEY_OPTION); String secretKey = cmd.getOptionValue(SECRET_KEY_OPTION); String bucket = cmd.getOptionValue(BUCKET_OPTION); String key = cmd.getOptionValue(KEY_OPTION); HttpMethod method = HttpMethod.GET; if (cmd.hasOption(VERB_OPTION)) { method = HttpMethod.valueOf(cmd.getOptionValue(VERB_OPTION).toUpperCase()); } int expiresMinutes = 60; if (cmd.hasOption(EXPIRES_OPTION)) { expiresMinutes = Integer.parseInt(cmd.getOptionValue(EXPIRES_OPTION)); } String contentType = null; if (method == HttpMethod.PUT || method == HttpMethod.POST) { contentType = "application/octet-stream"; } if (cmd.hasOption(CONTENT_TYPE_OPTION)) { contentType = cmd.getOptionValue(CONTENT_TYPE_OPTION); } BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration cc = new ClientConfiguration(); // Force use of v2 Signer. ECS does not support v4 signatures yet. cc.setSignerOverride("S3SignerType"); AmazonS3Client s3 = new AmazonS3Client(credentials, cc); s3.setEndpoint(endpoint.toString()); S3ClientOptions s3c = new S3ClientOptions(); s3c.setPathStyleAccess(true); s3.setS3ClientOptions(s3c); // Sign the URL Calendar c = Calendar.getInstance(); c.add(Calendar.MINUTE, expiresMinutes); GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, key).withExpiration(c.getTime()) .withMethod(method); if (contentType != null) { req = req.withContentType(contentType); } URL u = s3.generatePresignedUrl(req); System.out.printf("URL: %s\n", u.toURI().toASCIIString()); System.out.printf("HTTP Verb: %s\n", method); System.out.printf("Expires: %s\n", c.getTime()); System.out.println("To Upload with curl:"); StringBuilder sb = new StringBuilder(); sb.append("curl "); if (method != HttpMethod.GET) { sb.append("-X "); sb.append(method.toString()); sb.append(" "); } if (contentType != null) { sb.append("-H \"Content-Type: "); sb.append(contentType); sb.append("\" "); } if (method == HttpMethod.POST || method == HttpMethod.PUT) { sb.append("-T <filename> "); } sb.append("\""); sb.append(u.toURI().toASCIIString()); sb.append("\""); System.out.println(sb.toString()); System.exit(0); }
From source file:com.doculibre.constellio.utils.license.ApplyLicenseUtils.java
/** * @param args// w w w.j av a2 s.c o m */ @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { URL licenceHeaderURL = ApplyLicenseUtils.class.getResource("LICENSE_HEADER"); File binDir = ClasspathUtils.getClassesDir(); File projectDir = binDir.getParentFile(); // File dryrunDir = new File(projectDir, "dryrun"); File licenceFile = new File(licenceHeaderURL.toURI()); List<String> licenceLines = readLines(licenceFile); // for (int i = 0; i < licenceLines.size(); i++) { // String licenceLine = licenceLines.get(i); // licenceLines.set(i, " * " + licenceLine); // } // licenceLines.add(0, "/**"); // licenceLines.add(" */"); List<File> javaFiles = (List<File>) org.apache.commons.io.FileUtils.listFiles(projectDir, new String[] { "java" }, true); for (File javaFile : javaFiles) { if (isValidPackage(javaFile)) { List<String> javaFileLines = readLines(javaFile); if (!javaFileLines.isEmpty()) { boolean modified = false; String firstLineTrim = javaFileLines.get(0).trim(); if (firstLineTrim.startsWith("package")) { modified = true; javaFileLines.addAll(0, licenceLines); } else if (firstLineTrim.startsWith("/**")) { int indexOfEndCommentLine = -1; loop2: for (int i = 0; i < javaFileLines.size(); i++) { String javaFileLine = javaFileLines.get(i); if (javaFileLine.indexOf("*/") != -1) { indexOfEndCommentLine = i; break loop2; } } if (indexOfEndCommentLine != -1) { modified = true; int i = 0; loop3: for (Iterator<String> it = javaFileLines.iterator(); it.hasNext();) { it.next(); if (i <= indexOfEndCommentLine) { it.remove(); } else { break loop3; } i++; } javaFileLines.addAll(0, licenceLines); } else { throw new RuntimeException( "Missing end comment for file " + javaFile.getAbsolutePath()); } } if (modified) { // String outputFilePath = javaFile.getPath().substring(projectDir.getPath().length()); // File outputFile = new File(dryrunDir, outputFilePath); // outputFile.getParentFile().mkdirs(); // System.out.println(outputFile.getPath()); // FileOutputStream fos = new FileOutputStream(outputFile); System.out.println(javaFile.getPath()); FileOutputStream fos = new FileOutputStream(javaFile); IOUtils.writeLines(javaFileLines, "\n", fos); IOUtils.closeQuietly(fos); } } } } }
From source file:brainflow.core.ImageBrowser.java
public static void main(String[] args) { com.jidesoft.utils.Lm.verifyLicense("UIN", "BrainFlow", "S5XiLlHH0VReaWDo84sDmzPxpMJvjP3"); //com.jidesoft.plaf.LookAndFeelFactory.installDefaultLookAndFeel(); //LookAndFeelFactory.installJideExtension(LookAndFeelFactory.OFFICE2007_STYLE); URL url1 = BF.getDataURL("data/icbm452_atlas_probability_insula.hdr"); URL url2 = BF.getDataURL("data/icbm452_atlas_probability_white.hdr"); try {//from ww w. ja va2 s . c o m UIManager.setLookAndFeel(new NimbusLookAndFeel()); IImageSource dsource1 = BrainIO.loadDataSource(VFS.getManager().resolveFile(url1.toURI().toString())); IImageSource dsource2 = BrainIO.loadDataSource(VFS.getManager().resolveFile(url2.toURI().toString())); ImageBrowser browser = new ImageBrowser(Arrays.asList(dsource1, dsource2)); JFrame frame = new JFrame(); frame.add(browser, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } //List<IImageDataSource> dsource2 = BrainIO.loadDataSources(new File("/home/brad/data/sub30072/anat/mprage_anonymized.nii.gz"), // new File("/home/brad/data/sub54329/anat/mprage_anonymized.nii.gz")); // List<List<IImageDataSource>> sourceList = Arrays.asList(dsource1, dsource2); // ImageBrowser browser = new ImageBrowser(sourceList); // JFrame frame = new JFrame(); // frame.add(browser, BorderLayout.CENTER); // frame.pack(); // frame.setVisible(true); }
From source file:fr.cs.examples.bodies.Phasing.java
/** Program entry point. * @param args program arguments//from www. j a va 2 s .c om */ public static void main(String[] args) { try { if (args.length != 1) { System.err.println("usage: java fr.cs.examples.bodies.Phasing filename"); System.exit(1); } // configure Orekit Autoconfiguration.configureOrekit(); // input/out URL url = Phasing.class.getResource("/" + args[0]); if (url == null) { System.err.println(args[0] + " not found"); System.exit(1); } File input = new File(url.toURI().getPath()); new Phasing().run(input); } catch (URISyntaxException use) { System.err.println(use.getLocalizedMessage()); System.exit(1); } catch (IOException ioe) { System.err.println(ioe.getLocalizedMessage()); System.exit(1); } catch (IllegalArgumentException iae) { iae.printStackTrace(System.err); System.err.println(iae.getLocalizedMessage()); System.exit(1); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } catch (OrekitException oe) { oe.printStackTrace(System.err); System.err.println(oe.getLocalizedMessage()); System.exit(1); } }
From source file:Main.java
public static boolean isDocumentUrlValid(String str) { try {/* w w w. ja va 2 s . c o m*/ URL url = new URL(str.replaceAll(" ", "%20")); url.toURI(); return true; } catch (MalformedURLException e) { return false; } catch (URISyntaxException e) { return false; } }
From source file:io.github.carlomicieli.footballdb.starter.documents.WebDocumentDownloader.java
private static void validateUrl(String url) { try {//w ww . j a v a2 s. c om URL u = new URL(url); u.toURI(); } catch (MalformedURLException | URISyntaxException e) { throw new IllegalArgumentException("Invalid url value: " + url); } }