List of usage examples for java.net URL getFile
public String getFile()
From source file:CWLClientTest.java
/** * This test demonstrates how to parse a CWL document and populate a * @throws Exception/*from www . ja v a2s . c o m*/ */ @Test public void createToolJavaModel() throws Exception { final URL resource = Resources.getResource("cwl.json"); final CWL cwl = new CWL(); Gson gson = CWL.getTypeSafeCWLToolDocument(); final ImmutablePair<String, String> output = cwl.parseCWL(resource.getFile()); final CommandLineTool commandLineTool = gson.fromJson(output.getLeft(), CommandLineTool.class); assertTrue(commandLineTool != null && commandLineTool.getLabel().equals("BAMStats tool")); }
From source file:com.openteach.diamond.metadata.ServiceURL.java
/** * //from ww w . j a va 2 s .c o m * @throws MalformedURLException */ private void parse() throws MalformedURLException { int index = strURL.indexOf("://"); URL url = new URL(String.format("http%s", strURL.substring(index))); protocol = strURL.substring(0, index); host = url.getHost(); port = url.getPort(); serviceName = url.getFile(); query = url.getQuery(); }
From source file:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java
private void prepareTemplate() throws IOException { // icon/*from ww w . ja v a 2 s .c o m*/ URL iconFileURL = PKPassTemplateInMemoryTest.class.getClassLoader() .getResource("StoreCard.raw/icon@2x.png"); File iconFile = new File(iconFileURL.getFile()); pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, iconFile); // icon for language pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, Locale.ENGLISH, iconFile); }
From source file:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java
@Test public void addFile_asFile() throws IOException { URL iconFileURL = PKPassTemplateInMemoryTest.class.getClassLoader() .getResource("StoreCard.raw/icon@2x.png"); File iconFile = new File(iconFileURL.getFile()); pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, iconFile); Map<String, InputStream> files = pkPassTemplateInMemory.getFiles(); Assert.assertEquals(files.size(), 1); Assert.assertTrue(IOUtils.contentEquals(new FileInputStream(iconFile), files.get(PKPassTemplateInMemory.PK_ICON_RETINA))); }
From source file:de.brendamour.jpasskit.signing.PKPassTemplateInMemoryTest.java
@Test public void addFile_asFile_withLocale() throws IOException { URL iconFileURL = PKPassTemplateInMemoryTest.class.getClassLoader() .getResource("StoreCard.raw/icon@2x.png"); File iconFile = new File(iconFileURL.getFile()); pkPassTemplateInMemory.addFile(PKPassTemplateInMemory.PK_ICON_RETINA, Locale.ENGLISH, iconFile); Map<String, InputStream> files = pkPassTemplateInMemory.getFiles(); Assert.assertEquals(files.size(), 1); Assert.assertTrue(IOUtils.contentEquals(new FileInputStream(iconFile), files.get("en.lproj/" + PKPassTemplateInMemory.PK_ICON_RETINA))); }
From source file:com.netspective.sparx.fileupload.FileUploadFilter.java
/** * This method is called by the server before the filter goes into service, * and here it determines the file upload directory. * * @param <b>config</b> The filter config passed by the servlet engine *///ww w . j a v a2 s. c om public void init(FilterConfig config) throws ServletException { String tryDirectoryNames = config.getInitParameter(FILTERPARAM_UPLOAD_DIRS); // comma-separated list of directories to try if (tryDirectoryNames != null) { // find the first available directory either as a resource or a physical directory String[] tryDirectories = TextUtils.getInstance().split(tryDirectoryNames, ",", true); for (int i = 0; i < tryDirectories.length; i++) { String tryDirectory = tryDirectories[i]; try { // first try the directory as a servlet resource java.net.URL uploadDirURL = config.getServletContext().getResource(tryDirectory); if (uploadDirURL != null && uploadDirURL.getFile() != null) { uploadDir = uploadDirURL.getFile(); break; } File f = new File(tryDirectory); if (f.exists()) { uploadDir = f.getAbsolutePath(); break; } } catch (java.net.MalformedURLException ex) { throw new ServletException(ex.getMessage()); } } } // If upload directory parameter is null, assign a temp directory if (uploadDir == null) { File tempdir = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir"); if (tempdir != null) { uploadDir = tempdir.toString(); } else { throw new ServletException("Error in FileUploadFilter : No upload " + "directory found: set an uploadDir init " + "parameter or ensure the " + "javax.servlet.context.tempdir directory " + "is valid"); } } uploadPrefix = config.getInitParameter(FILTERPARAM_UPLOADED_FILES_PREFIX); if (uploadPrefix == null) uploadPrefix = FILTERPARAMVALUE_DEFAULT_UPLOADED_FILES_PREFIX; log.info("uploadPrefix is: " + uploadPrefix); uploadFileArg = config.getInitParameter(FILTERPARAM_UPLOADED_FILES_REQUEST_ATTR_NAME); if (uploadFileArg == null) uploadFileArg = FILTERPARAMVALUE_DEFAULT_UPLOADED_FILES_REQUEST_ATTR_NAME; log.info("uploadFileArg is: " + uploadFileArg); }
From source file:Main.java
/** * Implements the JDK 1.3 method URL.getPath(). The path is defined * as URL.getFile() minus the (optional) query. * * @param url the URL//from w w w .ja v a 2 s .co m * @return the path */ private String getQuery(final URL url) { final String file = url.getFile(); final int queryIndex = file.indexOf('?'); if (queryIndex == -1) { return null; } return file.substring(queryIndex + 1); }
From source file:Main.java
/** * Implements the JDK 1.3 method URL.getPath(). The path is defined * as URL.getFile() minus the (optional) query. * * @param url the URL/* w w w.j a v a 2 s . co m*/ * @return the path */ private String getPath(final URL url) { final String file = url.getFile(); final int queryIndex = file.indexOf('?'); if (queryIndex == -1) { return file; } return file.substring(0, queryIndex); }
From source file:business.SmallExcerptListTests.java
@Test(groups = "request", dependsOnMethods = "approveRequest") public void uploadExcerptList() throws IOException { UserAuthenticationToken palga = getPalga(); SecurityContext securityContext = SecurityContextHolder.getContext(); securityContext.setAuthentication(palga); RequestRepresentation representation = requestController.getRequestById(palga, processInstanceId); log.info("Status: " + representation.getStatus()); log.info("Activity: " + representation.getActivityId()); if (representation.getActivityId() == null) { for (Task task : taskService.createTaskQuery().list()) { log.info("Task " + task.getId() + ", process instance: " + task.getProcessInstanceId() + ", name: " + task.getName() + ", key: " + task.getTaskDefinitionKey()); }//from w w w. j a va 2 s. c o m } log.info("uploadExcerptList: processInstanceId = " + processInstanceId); representation = requestController.claim(palga, processInstanceId, representation); ClassLoader classLoader = getClass().getClassLoader(); URL resource = classLoader.getResource("test/Example excerptlist.csv"); InputStream input = resource.openStream(); MultipartFile file = new MockMultipartFile(resource.getFile(), input); Integer flowTotalChunks = 1; Integer flowChunkNumber = 1; String flowIdentifier = "flow"; int entryCount = requestController.uploadExcerptList(palga, processInstanceId, resource.getFile(), flowTotalChunks, flowChunkNumber, flowIdentifier, file); assertEquals(3, entryCount); SecurityContextHolder.clearContext(); }
From source file:com.asual.summer.core.faces.FacesResourceResolver.java
public URL resolveUrl(String path) { if (!resources.containsKey(path)) { URL url = ResourceUtils .getClasspathResource("/".equals(path) ? "META-INF/" : path.replaceAll("^/", "")); if (url != null) { try { url = new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile(), new FacesStreamHandler(url)); } catch (AccessControlException e) { } catch (NoClassDefFoundError e) { } catch (MalformedURLException e) { throw new FacesException(e); }//from w w w .j a v a 2 s .c o m } else { logger.warn("The requested resource [" + path + "] cannot be resolved."); } resources.put(path, url); } return resources.get(path); }