下面列出了java.net.URL#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public String uploadFile(String bucketName, String s3KeyName, File file) {
if (!(s3Client.doesBucketExist(bucketName))) {
s3Client.createBucket(new CreateBucketRequest(bucketName));
}
if (fileExists(bucketName, s3KeyName)) {
throw new WecubeCoreException(String.format("File[%s] already exists", s3KeyName));
}
s3Client.putObject(new PutObjectRequest(bucketName, s3KeyName, file).withCannedAcl(CannedAccessControlList.Private));
GeneratePresignedUrlRequest urlRequest = new GeneratePresignedUrlRequest(bucketName, s3KeyName);
URL url = s3Client.generatePresignedUrl(urlRequest);
log.info("uploaded File [{}] to S3. url = [{}]", file.getAbsolutePath(), url);
return url.toString();
}
/**
* load a single svg icon from a file
*
* @param url of the svg icon
* @return SVGGLyph node
* @throws IOException
*/
public static SVGGlyph loadGlyph(URL url) throws IOException {
String urlString = url.toString();
String filename = urlString.substring(urlString.lastIndexOf('/') + 1);
int startPos = 0;
int endPos = 0;
while (endPos < filename.length() && filename.charAt(endPos) != '-') {
endPos++;
}
int id = Integer.parseInt(filename.substring(startPos, endPos));
startPos = endPos + 1;
while (endPos < filename.length() && filename.charAt(endPos) != '.') {
endPos++;
}
String name = filename.substring(startPos, endPos);
return new SVGGlyph(id, name, extractSvgPath(getStringFromInputStream(url.openStream())), Color.BLACK);
}
public boolean accept(URL link) {
String url = link.toString();
String domain = LinkRelevance.getTopLevelDomain(link.getHost());
TextMatcher hostWhitelist = hostsWhitelists.get(domain);
if (hostWhitelist != null && !hostWhitelist.matches(url)) {
return false;
}
TextMatcher hostBlacklist = hostsBlacklists.get(domain);
if (hostBlacklist != null && !hostBlacklist.matches(url)) {
return false;
}
if (whitelist != null && !whitelist.matches(url)) {
return false;
}
if (blacklist != null && !blacklist.matches(url)) {
return false;
}
return true;
}
@NonNull
@Override
public String process(@NonNull String destination) {
String out = destination;
if (base != null) {
try {
final URL u = new URL(base, destination);
out = u.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return out;
}
private Object parseURL(URL url, Map params, String charset) {
Reader reader = null;
try {
if (params == null || params.isEmpty()) {
reader = ResourceGroovyMethods.newReader(url, charset);
} else {
reader = ResourceGroovyMethods.newReader(url, params, charset);
}
return parse(reader);
} catch (IOException ioe) {
throw new JsonException("Unable to process url: " + url.toString(), ioe);
} finally {
if (reader != null) {
DefaultGroovyMethodsSupport.closeWithWarning(reader);
}
}
}
@NonNull
private static String getDisplayName(@NonNull final URL root) {
final File f = FileUtil.archiveOrDirForURL(root);
return f == null ?
root.toString() :
f.isFile() ?
f.getName() :
f.getAbsolutePath();
}
Request(Session session, URL overriddenURL) {
this.session = session;
this.overriddenURL = overriddenURL.toString();
setHttpMethod(HttpMethod.GET);
this.parameters = new Bundle();
}
protected String getWebAppsPath(String name) throws FileNotFoundException {
URL url = getClass().getClassLoader().getResource("webapps/" + name);
if (url == null) {
throw new FileNotFoundException("webapps/" + name + " not found in CLASSPATH");
}
String urlString = url.toString();
return urlString.substring(0, urlString.lastIndexOf('/'));
}
@Override
protected URLConnection openConnection(URL url) throws IOException {
String s = url.toString();
int index = s.indexOf("!/");
if (index == -1)
throw new MalformedURLException("no !/ found in url spec:" + s);
throw new IOException("Can't connect to jmod URL");
}
private Test(URL base, String spec) {
testCount++;
try {
url = new URL(base, spec);
} catch (Exception x) {
exc = x;
}
if (url != null)
input = url.toString();
originalURL = url;
}
/**
* Tests with the same file than {@link #testNetCDF()}, but producing a XML output.
*
* @throws Exception if an error occurred while creating the command.
*/
@Test
@Ignore("Requires GeoAPI 3.1")
@DependsOnMethod("testNetCDF")
public void testFormatXML() throws Exception {
final URL url = new URL("Cube2D_geographic_packed.nc") ; // TestData.NETCDF_2D_GEOGRAPHIC.location();
final MetadataCommand test = new MetadataCommand(0, CommandRunner.TEST, url.toString(), "--format", "XML");
test.run();
verifyNetCDF("<?xml", test.outputBuffer.toString());
}
public static Permission getConnectPermission(URL url) throws IOException {
String urlStringLowerCase = url.toString().toLowerCase();
if (urlStringLowerCase.startsWith("http:") || urlStringLowerCase.startsWith("https:")) {
return getURLConnectPermission(url);
} else if (urlStringLowerCase.startsWith("jar:http:") || urlStringLowerCase.startsWith("jar:https:")) {
String urlString = url.toString();
int bangPos = urlString.indexOf("!/");
urlString = urlString.substring(4, bangPos > -1 ? bangPos : urlString.length());
URL u = new URL(urlString);
return getURLConnectPermission(u);
// If protocol is HTTP or HTTPS than use URLPermission object
} else {
return url.openConnection().getPermission();
}
}
@Test
public void testGenerateGetAgreement() throws Exception {
server.enqueue(new MockResponse().
setBody(readFile("/eu/seaclouds/planner/core/application/agreements/sla-create-agreement-response.xml")));
server.start();
URL url = server.url("/").url();
AgreementGenerator generator = new AgreementGenerator(url.toString());
String result = generator.getAgreement("templateId");
assertNotNull(result);
}
public InputSource resolveEntity(String publicId, String systemId) {
// return a proper input source
String resource;
if ("http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd".equals(systemId)) {
resource = "/org/netbeans/modules/j2ee/dd/impl/resources/ejb-jar_2_1.xsd"; //NOI18N
} else if ("http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd".equals(systemId)) {
resource = "/org/netbeans/modules/j2ee/dd/impl/resources/ejb-jar_3_0.xsd"; //NOI18N
} else {
return null;
}
URL url = this.getClass().getResource(resource);
return new InputSource(url.toString());
}
public static URL addParameter(URL url, String paramName, String paramValue) throws MalformedURLException {
String urlString = url.toString();
if(urlString.contains("?")) {
if(urlString.endsWith("&"))
urlString = urlString + paramName + "=" + paramValue;
else
urlString = urlString + "&" + paramName + "=" + paramValue;
} else {
urlString = urlString + "?" + paramName + "=" + paramValue;
}
return new URL(urlString);
}
protected static void initContentEngineFromSpringResource(URL resource) {
try {
Class<?> springConfigurationHelperClass = ReflectUtil.loadClass("org.flowable.content.spring.SpringContentConfigurationHelper");
Method method = springConfigurationHelperClass.getDeclaredMethod("buildContentEngine", new Class<?>[] { URL.class });
ContentEngine contentEngine = (ContentEngine) method.invoke(null, new Object[] { resource });
String contentEngineName = contentEngine.getName();
EngineInfo contentEngineInfo = new EngineInfo(contentEngineName, resource.toString(), null);
contentEngineInfosByName.put(contentEngineName, contentEngineInfo);
contentEngineInfosByResourceUrl.put(resource.toString(), contentEngineInfo);
} catch (Exception e) {
throw new FlowableException("couldn't initialize content engine from spring configuration resource " + resource + ": " + e.getMessage(), e);
}
}
public static String getUrl(Bundle bundle, String page) {
File file = getFile(bundle, page);
if (file == null)
return null;
try {
URL url = file.toURI().toURL();
return url.toString();
} catch (Exception e) {
log.error("failed to get URL for page " + bundle + "/" + page, e);
return null;
}
}
public RestfulGet(Class<T> clazz, URL url) {
HttpGet request = new HttpGet(url.toString());
request.addHeader("content-type", "application/json");
this.request = request;
this.httpResponseCallbackHandler = new
HttpResponseCallbackHandlerJsonHandler<T>(clazz);
}
static Image getImageFromHash(Toolkit tk, URL url) {
checkPermissions(url);
synchronized (urlImgCache) {
String key = url.toString();
Image img = (Image)urlImgCache.get(key);
if (img == null) {
try {
img = tk.createImage(new URLImageSource(url));
urlImgCache.put(key, img);
} catch (Exception e) {
}
}
return img;
}
}
/**
* Creates a resource from a {@code URL}.
*
* @param url the URL to wrap
* @return the resource locator
*/
public static ResourceLocator ofClasspathUrl(URL url) {
ArgChecker.notNull(url, "url");
String locator = CLASSPATH_URL_PREFIX + url.toString();
return new ResourceLocator(locator, UriByteSource.of(url));
}