本文整理汇总了Java中java.net.URL.setURLStreamHandlerFactory方法的典型用法代码示例。如果您正苦于以下问题:Java URL.setURLStreamHandlerFactory方法的具体用法?Java URL.setURLStreamHandlerFactory怎么用?Java URL.setURLStreamHandlerFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URL
的用法示例。
在下文中一共展示了URL.setURLStreamHandlerFactory方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTheCopyProblem
import java.net.URL; //导入方法依赖的package包/类
public void testTheCopyProblem() throws Exception {
clearWorkDir();
URL.setURLStreamHandlerFactory(new ProxyURLStreamHandlerFactory());
File tempFileSource = new File(getWorkDir(), "source");
tempFileSource.mkdirs();
File tempFile1 = File.createTempFile("test.test1", "", tempFileSource);
tempFile1.delete();
tempFile1.mkdir();
File tempFile2 = File.createTempFile("test.test2", "", tempFileSource);
tempFile2.delete();
tempFile2.mkdir();
File tempFileTarget = new File(getWorkDir(), "target");
tempFileTarget.mkdir();
FileObject sourceFo = FileUtil.toFileObject(tempFileSource);
FileObject targetFo = FileUtil.toFileObject(tempFileTarget);
FileUtil.copyFile(sourceFo, targetFo, "source");
assertNotNull(targetFo.getFileObject("source/" + tempFile1.getName()));
assertNotNull(targetFo.getFileObject("source/" + tempFile2.getName()));
}
示例2: initHttpURLConnection
import java.net.URL; //导入方法依赖的package包/类
private static void initHttpURLConnection(Context context) {
CronetEngine.Builder myBuilder = new CronetEngine.Builder(context);
myBuilder.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_IN_MEMORY, 100 * 1024)
.enableHttp2(true)
.enableQuic(true)
.enableSDCH(true)
.setHostResolver(new HostResolver() {
@Override
public List<InetAddress> resolve(String hostname) throws UnknownHostException {
if (hostname == null)
throw new UnknownHostException("hostname == null");
return Arrays.asList(InetAddress.getAllByName(hostname));
}
})
.enableSDCH(true)
.setLibraryName("cronet");
CronetEngine cronetEngine = myBuilder.build();
CronetURLStreamHandlerFactory cronetURLStreamHandlerFactory = new CronetURLStreamHandlerFactory(cronetEngine);
URL.setURLStreamHandlerFactory(cronetURLStreamHandlerFactory);
}
示例3: registerHandler
import java.net.URL; //导入方法依赖的package包/类
public static void registerHandler(final AssetManager manager) {
URL.setURLStreamHandlerFactory(protocol -> "assets".equals(protocol) ? new URLStreamHandler() {
protected URLConnection openConnection(URL url) throws IOException {
return new URLConnection(url) {
@Override
public void connect() throws IOException {
}
@Override
public InputStream getInputStream() throws IOException {
return manager.open(url.getFile());
}
};
}
} : null);
}
示例4: installGitProtocol
import java.net.URL; //导入方法依赖的package包/类
/**
* Installs the GIT protocol that we use to identify certain file versions.
*/
protected void installGitProtocol() {
// Install protocol.
try {
URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
@Override
public URLStreamHandler createURLStreamHandler(String protocol) {
if (protocol.equals(GitRevisionURLHandler.GIT_PROTOCOL)) {
URLStreamHandler handler = new GitRevisionURLHandler();
return handler;
}
return null;
}
});
} catch (Throwable t) {
if (!t.getMessage().contains("factory already defined")) {
logger.info(t, t);
}
}
}
示例5: testInitializationWithRegisteredStreamFactory
import java.net.URL; //导入方法依赖的package包/类
/**
* Check if FileSystem can be properly initialized if URLStreamHandlerFactory
* is registered.
*/
@Test
public void testInitializationWithRegisteredStreamFactory() {
Configuration conf = new Configuration();
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory(conf));
try {
FileSystem.getFileSystemClass("file", conf);
}
catch (IOException ok) {
// we might get an exception but this not related to infinite loop problem
assertFalse(false);
}
}
示例6: setupApiLayer
import java.net.URL; //导入方法依赖的package包/类
private static void setupApiLayer() {
try {
URL.setURLStreamHandlerFactory(new Util.MatrixMediaURLStreamHandlerFactory());
} catch (Error e) {
return; // Operation only permitted once; catching for harness.
}
}
示例7: update
import java.net.URL; //导入方法依赖的package包/类
@Test
public void update() throws RestfulHTTPException, IOException {
// Required to make URL class accept mxc:// protocol
URL.setURLStreamHandlerFactory(new Util.MatrixMediaURLStreamHandlerFactory());
user.update();
Assert.assertEquals(
"User object did not parse display name",
user.getName(),
"Morpheus"
);
}
示例8: setup
import java.net.URL; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
URL.setURLStreamHandlerFactory(
DirContextURLStreamHandlerFactory.getInstance());
File buildDir = new File(
System.getProperty("tomcat.test.tomcatbuild", "output/build"));
System.setProperty("catalina.base", buildDir.getAbsolutePath());
}
示例9: IDEInitializer
import java.net.URL; //导入方法依赖的package包/类
public IDEInitializer () {
Assert.assertNull (DEFAULT_LOOKUP);
DEFAULT_LOOKUP = this;
URL.setURLStreamHandlerFactory (new MyURLHandlerFactory ());
}
示例10: setUp
import java.net.URL; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
this.clearWorkDir();
try {
URL.setURLStreamHandlerFactory(new ProxyURLStreamHandlerFactory());
} catch (Error ex) {
// nop
}
final File _wd = this.getWorkDir();
final FileObject wd = FileUtil.toFileObject(_wd);
assertNotNull("No masterfs",wd);
srcRoot1 = wd.createFolder("src1");
assertNotNull(srcRoot1);
srcRoot2 = wd.createFolder("src2");
assertNotNull(srcRoot2);
srcRoot3 = wd.createFolder("src3");
assertNotNull (srcRoot3);
compRoot1 = wd.createFolder("comp1");
assertNotNull (compRoot1);
compRoot2 = wd.createFolder("comp2");
assertNotNull (compRoot2);
bootRoot1 = wd.createFolder("boot1");
assertNotNull (bootRoot1);
bootRoot2 = wd.createFolder("boot2");
assertNotNull (bootRoot2);
compSrc1 = wd.createFolder("cs1");
assertNotNull (compSrc1);
compSrc2 = wd.createFolder("cs2");
assertNotNull (compSrc2);
bootSrc1 = wd.createFolder("bs1");
assertNotNull (bootSrc1);
unknown1 = wd.createFolder("uknw1");
assertNotNull (unknown1);
unknown2 = wd.createFolder("uknw2");
assertNotNull (unknown2);
unknownSrc2 = wd.createFolder("uknwSrc2");
assertNotNull(unknownSrc2);
SFBQImpl.register (bootRoot1,bootSrc1);
SFBQImpl.register (compRoot1,compSrc1);
SFBQImpl.register (compRoot2,compSrc2);
SFBQImpl.register (unknown2,unknownSrc2);
}
示例11: IDEInitializer
import java.net.URL; //导入方法依赖的package包/类
public IDEInitializer() {
Assert.assertNull(DEFAULT_LOOKUP);
DEFAULT_LOOKUP = this;
URL.setURLStreamHandlerFactory(new MyURLHandlerFactory());
}
示例12: setup
import java.net.URL; //导入方法依赖的package包/类
@BeforeClass
public static void setup() {
URL.setURLStreamHandlerFactory(DirContextURLStreamHandlerFactory.getInstance());
}