List of usage examples for java.net URI getSchemeSpecificPart
public String getSchemeSpecificPart()
From source file:org.nuxeo.connect.update.standalone.PackageTestCase.java
protected File getTestPackageZip(String name) throws IOException, URISyntaxException { File zip = Framework.createTempFile("nuxeo-" + name + "-", ".zip"); Framework.trackFile(zip, zip);//from w ww .j a v a2s .co m URI uri = getResource(TEST_PACKAGES_PREFIX + name).toURI(); if (uri.getScheme().equals("jar")) { String part = uri.getSchemeSpecificPart(); // file:/foo/bar.jar!/a/b String basePath = part.substring(part.lastIndexOf("!") + 1); try (FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap())) { createZip(zip, fs.getPath(basePath)); } } else { // file: scheme createZip(zip, new File(uri).toPath()); } return zip; }
From source file:de.betterform.connector.file.FileURIResolver.java
/** * Performs link traversal of the <code>file</code> URI and returns the * result as a DOM document.//from w w w. j ava2s .com * * @return a DOM node parsed from the <code>file</code> URI. * @throws XFormsException if any error occurred during link traversal. */ public Object resolve() throws XFormsException { try { // create uri URI uri = new URI(getURI()); // use scheme specific part in order to handle UNC names String fileName = uri.getSchemeSpecificPart(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("loading file '" + fileName + "'"); } // create file File file = new File(fileName); // check for directory if (file.isDirectory()) { return FileURIResolver.buildDirectoryListing(file); } // parse file DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); Document document = factory.newDocumentBuilder().parse(file); /* Document document = CacheManager.getDocument(file); if(document == null) { document = DOMResource.newDocumentBuilder().parse(file); CacheManager.putIntoFileCache(file, document); } */ // check for fragment identifier if (uri.getFragment() != null) { return document.getElementById(uri.getFragment()); } return document; } catch (Exception e) { //todo: improve error handling as files might fail due to missing DTDs or Schemas - this won't be detected very well throw new XFormsException(e); } }
From source file:gov.nih.nci.caarray.dataStorage.fileSystem.FilesystemDataStorage.java
/** * {@inheritDoc}//from ww w.j av a2 s . com */ public StorageMetadata finalizeChunkedFile(URI handle) { String fileHandle = handle.getSchemeSpecificPart(); File uncompressedFile = openFile(handle, false); File compressedFile = compressedFile(fileHandle); try { final FileInputStream fis = Files.newInputStreamSupplier(uncompressedFile).getInput(); compressAndWriteFile(fis, compressedFile(handle.getSchemeSpecificPart())); IOUtils.closeQuietly(fis); final StorageMetadata metadata = new StorageMetadata(); metadata.setHandle(handle); metadata.setUncompressedSize(uncompressedFile.length()); metadata.setCompressedSize(compressedFile.length()); return metadata; } catch (final IOException e) { throw new DataStoreException("Could not add data", e); } }
From source file:com.sina.cloudstorage.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.schemeSpecificPart = uri.getSchemeSpecificPart(); this.authority = uri.getAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.userInfo = uri.getUserInfo(); this.path = uri.getPath(); this.queryParams = parseQuery(uri.getRawQuery(), Consts.UTF_8); this.fragment = uri.getFragment(); }
From source file:org.dita.dost.writer.ImageMetadataFilter.java
private InputStream getInputStream(final URI imgInput) throws IOException { if (imgInput.getScheme().equals("data")) { final String data = imgInput.getSchemeSpecificPart(); final int separator = data.indexOf(','); final String metadata = data.substring(0, separator); if (metadata.endsWith(";base64")) { logger.info("Base-64 encoded data URI"); return new ByteArrayInputStream(Base64.decodeBase64(data.substring(separator + 1))); } else {/*from ww w.ja va 2s. c o m*/ logger.info("ASCII encoded data URI"); return new ByteArrayInputStream(data.substring(separator).getBytes()); } } else { return imgInput.toURL().openConnection().getInputStream(); } }
From source file:gov.nih.nci.caarray.dataStorage.fileSystem.FilesystemDataStorage.java
/** * {@inheritDoc}//w w w .j a va 2 s. c o m */ @Override public void remove(URI handle) { checkScheme(handle); FileUtils.deleteQuietly(compressedFile(handle.getSchemeSpecificPart())); FileUtils.deleteQuietly(uncompressedFile(handle.getSchemeSpecificPart())); }
From source file:de.betterform.connector.file.FileSubmissionHandler.java
/** * Serializes and submits the specified instance data over the * <code>file</code> protocol. * * @param submission the submission issuing the request. * @param instance the instance data to be serialized and submitted. * @return <code>null</code>. * @throws XFormsException if any error occurred during submission. *///from w w w. j a v a 2 s. c o m public Map submit(Submission submission, Node instance) throws XFormsException { if (submission.getMethod().equalsIgnoreCase("get")) { try { // create uri URI uri = new URI(getURI()); // use scheme specific part in order to handle UNC names String fileName = uri.getSchemeSpecificPart(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("getting file '" + fileName + "'"); } // create file File file = new File(fileName); InputStream inputStream; // check for directory if (file.isDirectory()) { // create input stream from directory listing Document document = FileURIResolver.buildDirectoryListing(file); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); if (LOGGER.isDebugEnabled()) { DOMUtil.prettyPrintDOM(document, outputStream); } inputStream = new ByteArrayInputStream(outputStream.toByteArray()); } else { // create file input stream inputStream = new FileInputStream(new File(fileName)); } Map response = new HashMap(); response.put(XFormsProcessor.SUBMISSION_RESPONSE_STREAM, inputStream); return response; } catch (Exception e) { throw new XFormsException(e); } } if (submission.getMethod().equalsIgnoreCase("put")) { if (!submission.getReplace().equals("none")) { throw new XFormsException("submission mode '" + submission.getReplace() + "' not supported"); } try { // create uri URI uri = new URI(getURI()); // use scheme specific part in order to handle UNC names String fileName = uri.getSchemeSpecificPart(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("putting file '" + fileName + "'"); } // create output steam and serialize instance data FileOutputStream stream = new FileOutputStream(new File(fileName)); SerializerRequestWrapper wrapper = new SerializerRequestWrapper(stream); serialize(submission, instance, wrapper); wrapper.getBodyStream().close(); } catch (Exception e) { throw new XFormsException(e); } return new HashMap(); } if (submission.getMethod().equalsIgnoreCase("delete")) { try { // create uri URI uri = new URI(getURI()); // use scheme specific part in order to handle UNC names String fileName = uri.getSchemeSpecificPart(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("getting file '" + fileName + "'"); } // create file File file = new File(fileName); file.delete(); } catch (Exception e) { throw new XFormsException(e); } return new HashMap(); } throw new XFormsException("submission method '" + submission.getMethod() + "' not supported"); }
From source file:org.chiba.xml.xforms.connector.file.FileURIResolver.java
/** * Performs link traversal of the <code>file</code> URI and returns the * result as a DOM document.//from w w w. j a v a2 s . co m * * @return a DOM node parsed from the <code>file</code> URI. * @throws XFormsException if any error occurred during link traversal. */ public Object resolve() throws XFormsException { try { // create uri URI uri = new URI(getURI()); // use scheme specific part in order to handle UNC names String fileName = uri.getSchemeSpecificPart(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("loading file '" + fileName + "'"); } // create file File file = new File(fileName); // check for directory if (file.isDirectory()) { return FileURIResolver.buildDirectoryListing(file); } // parse file DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(false); Document document = factory.newDocumentBuilder().parse(file); // check for fragment identifier if (uri.getFragment() != null) { return document.getElementById(uri.getFragment()); } return document; } catch (Exception e) { throw new XFormsException(e); } }
From source file:com.izforge.izpack.installer.multiunpacker.MultiVolumeUnpacker.java
/** * Tries to return a sensible default media path for multi-volume installations. * <p/>/* w ww. java 2 s. c o m*/ * This returns: * <ul> * <li>the directory the installer is located in; or </li> * <li>the user directory, if the installer location can't be determined</li> * </ul> * * @return the default media path. May be <tt>null</tt> */ private String getDefaultMediaPath() { String result = null; try { CodeSource codeSource = getClass().getProtectionDomain().getCodeSource(); if (codeSource != null) { URI uri = codeSource.getLocation().toURI(); if ("file".equals(uri.getScheme())) { File dir = new File(uri.getSchemeSpecificPart()).getAbsoluteFile(); if (dir.getName().endsWith(".jar")) { dir = dir.getParentFile(); } result = dir.getPath(); } } } catch (URISyntaxException exception) { // ignore } if (result == null) { result = System.getProperty("user.dir"); } return result; }