List of usage examples for java.net URL toURI
public URI toURI() throws URISyntaxException
From source file:de.ks.file.FileStoreTest.java
@Test public void testGetFileReferences() throws Exception { Path path = Files.createTempFile("img", ".jpg"); URL resource = getClass().getResource("/de/ks/idnadrev/entity/img.jpg"); Path src = Paths.get(resource.toURI()); Files.copy(src, path, StandardCopyOption.REPLACE_EXISTING); File file = path.toFile();/*from www . j av a 2 s . c om*/ file.deleteOnExit(); FileReference fileReference = fileStore.getReference(file).get(); PersistentWork.run(em -> { fileStore.scheduleCopy(fileReference, file); em.persist(fileReference); }); assertThat(fileReference.getMimeType(), containsString("image")); List<FileReference> references = fileStore.getFilesByMimeType(MediaType.ANY_IMAGE_TYPE); assertEquals(1, references.size()); references = fileStore.getFilesByMimeType(MediaType.ANY_AUDIO_TYPE); assertEquals(0, references.size()); references = fileStore.getFilesByMimeType(MediaType.ANY_TYPE); assertEquals(1, references.size()); }
From source file:com.enigmastation.ml.bayes.CorpusTest.java
private String expandFile(String fileName) throws URISyntaxException, IOException { URL dataResource = this.getClass().getResource("/src/test/resources/publiccorpus/" + fileName); File inputFile = new File(dataResource.toURI()); File outputDirectory = new File(inputFile + ".data"); outputDirectory.mkdir();/* w w w.ja v a 2 s . co m*/ FileInputStream fis = new FileInputStream(inputFile); BufferedInputStream bis = new BufferedInputStream(fis); BZip2CompressorInputStream bzip2 = new BZip2CompressorInputStream(bis); TarArchive archive = new TarArchive(bzip2); archive.extractContents(outputDirectory); System.out.printf("%s finished expanding into \"%s\".%n", inputFile.getName(), outputDirectory.toString()); bzip2.close(); return "/src/test/resources/publiccorpus/" + inputFile.getName() + ".data"; }
From source file:fr.free.movierenamer.scrapper.impl.image.TMDbImagesScrapper.java
@Override protected List<ImageInfo> fetchImagesInfo(Movie movie) throws Exception { String id = movie.getId().toString(); switch (movie.getId().getIdType()) { case IMDB:// w w w . ja va 2 s . c om id = imdbIDLookUp(id); break; case TMDB: break; default: throw new UnsupportedOperationException( movie.getId().getIdType() + " is not supported by " + getName() + " image scrapper"); } URL searchUrl = new URL("http", host, "/" + version + "/movie/" + id + "/images?api_key=" + apikey); JSONObject json = URIRequest.getJsonDocument(searchUrl.toURI()); List<ImageInfo> images = new ArrayList<ImageInfo>(); for (String section : new String[] { "backdrops", "posters" }) { List<JSONObject> jsonObjs = JSONUtils.selectList(section, json); TmdbImageSize imageSize = section.equals("backdrops") ? TmdbImageSize.backdrop : TmdbImageSize.poster; int count = 0; for (JSONObject jsonObj : jsonObjs) { Map<ImageInfo.ImageProperty, String> imageFields = new EnumMap<ImageInfo.ImageProperty, String>( ImageInfo.ImageProperty.class); String file_path = JSONUtils.selectString("file_path", jsonObj); imageFields.put(ImageInfo.ImageProperty.url, TMDbScrapper.imageUrl + imageSize.getBig() + file_path); imageFields.put(ImageInfo.ImageProperty.urlMid, TMDbScrapper.imageUrl + imageSize.getMedium() + file_path); imageFields.put(ImageInfo.ImageProperty.urlTumb, TMDbScrapper.imageUrl + imageSize.getSmall() + file_path); String lang = JSONUtils.selectString("iso_639_1", jsonObj); if (lang != null && !lang.equals("null")) { imageFields.put(ImageInfo.ImageProperty.language, lang); } imageFields.put(ImageInfo.ImageProperty.width, JSONUtils.selectString("width", jsonObj)); imageFields.put(ImageInfo.ImageProperty.height, JSONUtils.selectString("height", jsonObj)); images.add(new ImageInfo(count++, imageFields, section.equals("posters") ? ImageInfo.ImageCategoryProperty.thumb : ImageInfo.ImageCategoryProperty.fanart)); } } return images; }
From source file:io.cloudslang.lang.compiler.CompileOperationTest.java
@Test public void testCompileOperationWithData() throws Exception { URL resource = getClass().getResource("/operation_with_data.sl"); ExecutionPlan executionPlan = compiler.compile(SlangSource.fromFile(resource.toURI()), null) .getExecutionPlan();/*from w ww. j a va 2 s . c om*/ ExecutionStep startStep = executionPlan.getStep(1L); @SuppressWarnings("unchecked") List<Input> inputs = (List<Input>) startStep.getActionData().get(ScoreLangConstants.EXECUTABLE_INPUTS_KEY); Assert.assertNotNull("inputs doesn't exist", inputs); Assert.assertEquals("there is a different number of inputs than expected", 13, inputs.size()); ExecutionStep actionStep = executionPlan.getStep(2L); String script = (String) actionStep.getActionData().get(ScoreLangConstants.PYTHON_SCRIPT_KEY); Assert.assertNotNull("script doesn't exist", script); Assert.assertTrue("script is different than expected", script.startsWith("# this is python amigos!!")); ExecutionStep endStep = executionPlan.getStep(3L); Object outputs = endStep.getActionData().get(ScoreLangConstants.EXECUTABLE_OUTPUTS_KEY); Object results = endStep.getActionData().get(ScoreLangConstants.EXECUTABLE_RESULTS_KEY); Assert.assertNotNull("outputs don't exist", outputs); Assert.assertNotNull("results don't exist", results); }
From source file:ch.icclab.cyclops.publish.APICaller.java
/** * Perform GET query and return Response * @param endpoint to be called/*from w w w .ja va 2 s . c o m*/ * @return Response object * @throws Exception */ public APICaller.Response get(URL endpoint) throws Exception { // prepare connection HttpClient client = HttpClientBuilder.create().build(); // create request HttpGet request = new HttpGet(endpoint.toURI()); request.addHeader("Accept", "application/json"); request.addHeader("Content-Type", "application/json"); // execute response HttpResponse response = client.execute(request); return new Response(IOUtils.toString(response.getEntity().getContent()), response.getStatusLine().getStatusCode()); }
From source file:it.geosolutions.geobatch.unredd.script.test.utils.ResourceLoader.java
protected File loadFile(String name) { try {/*from w ww. ja v a 2 s.c om*/ URL url = this.getClass().getClassLoader().getResource(name); if (url == null) throw new IllegalArgumentException("Cant get file '" + name + "'"); File file = new File(url.toURI()); return file; } catch (URISyntaxException e) { LOGGER.error("Can't load file " + name + ": " + e.getMessage(), e); return null; } }
From source file:io.cloudslang.lang.compiler.modeller.transformers.JavaActionTransformerTest.java
@SuppressWarnings("unchecked") private Map<String, String> loadJavaActionData(String filePath) throws URISyntaxException { URL resource = getClass().getResource(filePath); ParsedSlang file = yamlParser.parse(SlangSource.fromFile(new File(resource.toURI()))); Map op = file.getOperation(); return (Map<String, String>) op.get(SlangTextualKeys.JAVA_ACTION_KEY); }
From source file:net.oneandone.shared.artifactory.FetchStorageByChecksum.java
public ArtifactoryStorage fetch(final String repositoryName, final Sha1 sha1) throws IOException, NotFoundException, URISyntaxException { final URL checksumURL = searchByChecksum.search(repositoryName, sha1); final JsonResponseHandler<ArtifactoryStorage> handler = new JsonResponseHandler<ArtifactoryStorage>( ArtifactoryStorage.class); final HttpGet httpGet = new HttpGet(checksumURL.toURI()); return client.execute(httpGet, handler); }
From source file:org.atomserver.core.dbstore.RawClientDBSTest.java
@SuppressWarnings("deprecation") public void testNoNamespace() throws Exception { String urlToCall = getServerURL() + "widgets/foobar/24560.en.xml"; HttpClient client = new HttpClient(); PutMethod put = new PutMethod(urlToCall); put.setRequestHeader("Content-type", "text/xml; charset=UTF-8"); URL url = this.getClass().getResource("/noNamespaceEntry.xml"); File file = new File(url.toURI()); FileInputStream fis = new FileInputStream(file); put.setRequestBody(fis);/*w w w . j a v a2 s . co m*/ // Execute the method. int statusCode = client.executeMethod(put); // 422 -- unprocessable Entity log.debug("STATUS CODE= " + statusCode); assertTrue(statusCode == 422); }
From source file:com.omertron.bgg.tools.HttpTools.java
/** * POST content to the URL with the specified body * * @param url URL to use in the request/*from www .j ava 2s . co m*/ * @param jsonBody Body to use in the request * @return String content * @throws BggException Custom exception containing failure code */ public String postRequest(final URL url, final String jsonBody) throws BggException { try { HttpPost httpPost = new HttpPost(url.toURI()); httpPost.addHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON); httpPost.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON); StringEntity params = new StringEntity(jsonBody, ContentType.APPLICATION_JSON); httpPost.setEntity(params); return validateResponse(DigestedResponseReader.postContent(httpClient, httpPost, CHARSET), url); } catch (URISyntaxException | IOException ex) { throw new BggException(ApiExceptionType.CONNECTION_ERROR, null, url, ex); } }