当前位置: 首页>>代码示例>>Java>>正文


Java URLHelper类代码示例

本文整理汇总了Java中com.heliosapm.utils.url.URLHelper的典型用法代码示例。如果您正苦于以下问题:Java URLHelper类的具体用法?Java URLHelper怎么用?Java URLHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


URLHelper类属于com.heliosapm.utils.url包,在下文中一共展示了URLHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: installProps

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Examines the command line arguments to find the admin config arguments
 * @param args The command line args
 */
private static void installProps(final String[] args) {
	for(String s: args) {
		if(s.startsWith(ADMIN_CONFIG_PREFIX)) {
			s = s.replace(ADMIN_CONFIG_PREFIX, "").trim();
		}
		try {
			final URL url = URLHelper.toURL(s);
			try {
				final String propsStr = URLHelper.getTextFromURL(url, 3, 1);
				if(propsStr!=null && !propsStr.trim().isEmpty()) {
					final Properties props = Props.strToProps(propsStr.trim());
					Props.setFromUnless(props, System.getProperties(), true);
				}
			} catch (Exception ex) {
				System.err.println("Failed to read properties from [" + s + "]:" + ex); 
			}
			// Props.setFromUnless(final Properties from, final Properties to, final boolean overrideTo, final Properties...unless)
		} catch (Exception x) {/* No Op */}
		break;
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:26,代码来源:StreamHubAdminServer.java

示例2: deployJMXConnectionPool

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Creates the configuration for a new JMXClient connection pool and writes it to the dynamic data source directory
 * @param endpoint The endpoint to create the pool for
 * @param maxSize The max size (and min size) of the pool 
 * @return The pool name
 */
protected String deployJMXConnectionPool(final AdvertisedEndpoint endpoint, final int maxSize) {
	final JMXServiceURL jmxUrl = JMXHelper.serviceUrl(endpoint.getJmxUrl());
	final int port = jmxUrl.getPort();
	final File dynamicDataSourceDir = new File(scriptFactory.getDataSourceDirectory(), "dynamic" + File.separator + endpoint.getHost() + File.separator + endpoint.getApp() + File.separator + port);
	dynamicDataSourceDir.mkdir();
	final File dsFile = new File(dynamicDataSourceDir, String.format("jmxpool-%s-%s-%s-%s.pool", jmxUrl.getProtocol(), endpoint.getHost(), endpoint.getApp(), port));
	final String poolName = String.format("%s-%s-%s", endpoint.getHost(), endpoint.getApp(), port);
	final String dsConfig = String.format(POOL_CONFIG, "JMXClientPoolBuilder", poolName, endpoint.getJmxUrl(), maxSize, maxSize, maxSize);
	if(dsFile.exists()) dsFile.delete();
	log.info("Deploying dynamic JMXClient ObjectPool [{}]\n\tto [{}]....", poolName, dsFile.getAbsolutePath());
	URLHelper.writeToFile(dsConfig, dsFile, false);
	if(!scriptFactory.getDataSourceManager().awaitDeployment(dsFile)) {
		log.warn("Timed out waiting for pool [{}] file: [{}]", poolName, dsFile);
	} else {
		log.info("Deployed dynamic JMXClient ObjectPool [{}]", poolName);
	}
	return poolName;
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:25,代码来源:EndpointDiscoveryService.java

示例3: main

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	log("LinkedFileTest");
	FileFinder linkedSourceFinder = FileFinder.newFileFinder("/tmp/links")
			.maxDepth(20)
			.filterBuilder()
				.linkedFile(
						FileFilterBuilder.newBuilder()
						.caseInsensitive(false)
						.endsWithMatch(".groovy")
						.fileAttributes(FileMod.READABLE)
						.shouldBeFile()
						.build()
				)
			.fileFinder();
	final File[] files = linkedSourceFinder.find();
	log("Found [" + files.length + "] files");
	for(File f: files) {
		log("File: " + f);
		final LinkFile lf = new LinkFile(f);
		log("\tPoints to: " + lf);
		log("\tContent:" + URLHelper.getTextFromFile(lf));
		
	}

}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:29,代码来源:LinkedFileTest.java

示例4: listLibJarUrls

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
private URL[] listLibJarUrls(final File dir, final Set<URL> accum) {
	final Set<URL> _accum = accum==null ? new HashSet<URL>() : accum;
	for(File f: dir.listFiles()) {
		if(f.isDirectory() && !f.getName().equals(jdbcLibDirectory.getName())) {
			listLibJarUrls(f, _accum);
		} else {
			if(f.getName().toLowerCase().endsWith(".jar")) {
				if(f.getParent().equals(libDirectory)) continue;
				final URL jarUrl = URLHelper.toURL(f.getAbsolutePath());
				_accum.add(jarUrl);
				log.info("Adding [{}] to classpath", jarUrl);
			}
		}
	}
	return _accum.toArray(new URL[_accum.size()]);		
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:17,代码来源:ManagedScriptFactory.java

示例5: getGlobalBindings

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
private Map<String, Object> getGlobalBindings() {
	if(globalBindings.isEmpty()) {
		synchronized(globalBindings) {
			if(globalBindings.isEmpty()) {
				globalBindings.put("globalCache", GlobalCacheService.getInstance());
				globalBindings.put("dsManager", jdbcDataSourceManager);
				globalBindings.put("tunnelManager", SSHTunnelManager.getInstance());
				globalBindings.put("sshconn", SSHConnection.class);
				globalBindings.put("mbs", JMXHelper.getHeliosMBeanServer());
				globalBindings.put("jmxHelper", JMXHelper.class);
				globalBindings.put("urlHelper", URLHelper.class);
				globalBindings.put("stringHelper", StringHelper.class);			
				try {
					globalBindings.put("_perf", PrivateAccessor.invokeStatic("sun.misc.Perf", "getPerf"));
				} catch (Exception x) {/* No Op */}
			}
		}
	}
	return new HashMap<String, Object>(globalBindings);		
	
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:22,代码来源:ManagedScriptFactory.java

示例6: ByteBufReaderSource

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Creates a new ByteBufReaderSource
 * @param sourceFile the original source file
 * @param scriptRootDirectory The script root directory
 */
public ByteBufReaderSource(final File sourceFile, final Path scriptRootDirectory) {
	this.sourceFile = sourceFile;		
   	final Path sourcePath = sourceFile.getAbsoluteFile().toPath().normalize();
   	className = scriptRootDirectory.normalize().relativize(sourcePath).toString().replace(".groovy", "").replace(File.separatorChar, '.');
	scriptProperties = readConfig(sourceFile);
	sourceBuffer = loadSourceFile();
	
	final StringBuilder b = processDependencies();
	if(b.length()==0) {
		prejectedBuffer = sourceBuffer;
		prejected = false;
		sourceURI = sourceFile.toURI();
	} else {
		b.insert(0, EOL + "// ===== Injected Code =====" + EOL);
		b.append(EOL + "// =========================" + EOL);
		prejectedBuffer = BufferManager.getInstance().directBuffer(b.length() + sourceBuffer.readableBytes());
		prejectedBuffer.writeCharSequence(b, UTF8);
		prejectedBuffer.writeBytes(sourceBuffer.duplicate().resetReaderIndex());
		prejected = true;
		sourceURI = URLHelper.toURI(sourceFile.toURI().toString() + "-prejected");
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:28,代码来源:ByteBufReaderSource.java

示例7: deploy

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Deploys the passed data source definition file
 * @param dsDef the data source definition file
 */
protected void deploy(final File dsDef) {
	if(dsDef==null) throw new IllegalArgumentException("The passed file was null");
	final CountDownLatch latch = placeLatch(dsDef);
	try {
		final String ext = URLHelper.getFileExtension(dsDef);
		if(ext==null || ext.trim().isEmpty() || !POOL_EXT.contains(ext.toLowerCase())) {
			throw new IllegalArgumentException("The passed file [" + dsDef + "] does not have a recognized extension [" + ext + "]. Recognized extensions are: " + POOL_EXT);
		}
		if(!dsDef.canRead()) throw new IllegalArgumentException("The passed file [" + dsDef + "] cannot be read");
		final String name = dsDef.getName().toLowerCase(); 
		if(name.endsWith(".ds")) {
			deployJDBCDataSource(dsDef);
		} else if(name.endsWith(".pool")) {
			deployObjectPool(dsDef);
		}
	} finally {
		latch.countDown();
		deploymentLatches.remove(dsDef, latch);
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:25,代码来源:JDBCDataSourceManager.java

示例8: main

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
public static void main(String[] args) {
	try {
		log("SSHConnection Test");
		final int jmxPort = JMXHelper.fireUpJMXMPServer(36636).getAddress().getPort();
		log("JMXMP Port:" + jmxPort);
		
		//SSHConnection conn = SSHConnection.getConnection("localhost", 45803, "fred", "flintstone");
		SSHConnection conn = SSHConnection.getConnection("localhost", 45803, "fred", URLHelper.getCharsFromURL("./src/test/resources/ssh/auth/keys/fred_rsa"), "the moon is a balloon");
		conn.connection.connect(conn);
		log("Connected");
		log("ConnAuths Available:" + Arrays.toString(conn.connection.getRemainingAuthMethods(conn.user)));
		log("Authenticated:" + AuthenticationMethod.auth(conn));
		LocalPortForwarder lpf = conn.connection.createLocalPortForwarder(28374, "127.0.0.1", jmxPort);
		log("LocalPortForwarder Started:" + lpf);
		StdInCommandHandler.getInstance().run();
	} catch (Exception ex) {
		ex.printStackTrace(System.err);
	}
	
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:21,代码来源:SSHConnection.java

示例9: parseConnections

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Parses SSHConnections from the JSON read from the passed URL
 * @param jsonUrl the URL the json is read from
 * @return an array of SSHConnections
 */
public static SSHConnection[] parseConnections(final URL jsonUrl) {
	if(jsonUrl==null) throw new IllegalArgumentException("The passed URL was null");		
	final String jsonText = StringHelper.resolveTokens(
			URLHelper.getStrBuffFromURL(jsonUrl)
	);
	try {			
		final JsonNode rootNode = OBJECT_MAPPER.readTree(jsonText);
		final ArrayNode an = (ArrayNode)rootNode.get("connections");
		if(an.size()==0) return EMPTY_CONN_ARR;
		return OBJECT_MAPPER.convertValue(an, SSHConnection[].class);	
	} catch (Exception ex) {
		ex.printStackTrace(System.err);
		throw new RuntimeException("Failed to load SSHConnections from [" + jsonUrl + "]", ex);
	}		
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:21,代码来源:SSHTunnelManager.java

示例10: parseUrl

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Parses an array of objects from the JSON read from the passed URL
 * @param jsonUrl the URL the json is read from
 * @param type The type of the object to be read
 * @return an array of objects
 * FIXME: this is broken
 */
public static <T> T[] parseUrl(final URL jsonUrl, final Class<? extends T> type) {
	if(jsonUrl==null) throw new IllegalArgumentException("The passed URL was null");		
	final String jsonText = StringHelper.resolveTokens(
			URLHelper.getStrBuffFromURL(jsonUrl)
	);
	try {			
		final JsonNode rootNode = OBJECT_MAPPER.readTree(jsonText);
		final ArrayNode an = (ArrayNode)rootNode.get("connections");
		if(an.size()==0) return (T[])Array.newInstance(type, 0);
		return (T[])OBJECT_MAPPER.convertValue(an, Array.newInstance(type, 0).getClass());	
	} catch (Exception ex) {
		ex.printStackTrace(System.err);
		throw new RuntimeException("Failed to load objects from [" + jsonUrl + "]", ex);
	}		
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:23,代码来源:SSHTunnelManager.java

示例11: testBasicConnUnmarshall

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Tests loading an array of SSHConnections from JSON
 * @throws Exception thrown on any error
 */
@SuppressWarnings("static-method")
@Test
public void testBasicConnUnmarshall() throws Exception {
	try {
		System.setProperty(SSHD_PORT_PROP, "22");
		final URL url = SSHConnectionTest.class.getClassLoader().getResource(TEST_JSON);
		log("Test JSON URL:" + url);
		final SSHConnection[] connections = SSHTunnelManager.parseConnections(url);
		log(Arrays.deepToString(connections));
		final ArrayNode nodes = (ArrayNode)OBJECT_MAPPER.readTree(
			StringHelper.resolveTokens(
				URLHelper.getTextFromURL(url)
			)
		).get("connections");
		Assert.assertEquals("Number of conns != number of json nodes", nodes.size(), connections.length);
		for(int i = 0; i < connections.length; i++) {
			validateConnection(connections[i], nodes.get(i));
		}
	} catch (Throwable ex) {
		ex.printStackTrace(System.err);
		throw new RuntimeException(ex);
	} finally {
		System.clearProperty(SSHD_PORT_PROP);
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:30,代码来源:SSHConnectionTest.java

示例12: buildMap

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
private static Map<String, String> buildMap(final File f, final boolean reverse) {
	final ElapsedTime et = SystemClock.startClock();
	final Number[] stats = computeStats(f);
	final long entries = stats[0].longValue(); 
	final double avgKeySize = stats[1].doubleValue();
	final double avgValueSize = stats[2].doubleValue();
	final ChronicleMap<String, String> map = ChronicleMapBuilder.of(String.class, String.class)
			.averageKeySize(avgKeySize)
			.averageValueSize(avgValueSize)
			.entries(entries)				
			.maxBloatFactor(5.0)
			.create();		
	final String[] lines = URLHelper.getTextFromFile(f).split("\n");
	Arrays.stream(lines)
		.parallel()
		.map(line -> line.split(","))
		.forEach(kv -> {
			if(reverse) {
				map.put(kv[1], kv[0]);
			} else {
				map.put(kv[0], kv[1]);
			}
		});
	final String avg = et.printAvg("Records", entries);
	log.info("Loaded Map from {}. Entries:{}, Size:{},  {}", f.getName(), entries, map.size(), avg);
	return map;
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:28,代码来源:CQ4GenFromTestData.java

示例13: getConfig

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Loads the named TSDB config 
 * @param name The name of the config file
 * @return The named config
 * @throws Exception thrown on any error
 */
public static Config getConfig(String name) throws Exception {
	File tmpFile = null;
	try {
		if(name==null || name.trim().isEmpty()) throw new Exception("File was null or empty");
		name = String.format("configs/%s.cfg", name);
		log("Loading config [%s]", name);
		final URL resourceURL = BaseTest.class.getClassLoader().getResource(name);
		if(resourceURL==null) throw new Exception("Cannot read from the resource [" + name + "]");
		final byte[] content = URLHelper.getBytesFromURL(resourceURL);
		tmpFile = File.createTempFile("config-" + name.replace("/", "").replace("\\", ""), ".cfg");
		URLHelper.writeToURL(URLHelper.toURL(tmpFile), content, false);
		if(!tmpFile.canRead()) throw new Exception("Cannot read from the file [" + tmpFile + "]");
		log("Loading [%s]", tmpFile.getAbsolutePath());
		return new Config(tmpFile.getAbsolutePath());
	} finally {			
		if(tmpFile!=null) tmpFile.deleteOnExit();
	}
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:25,代码来源:BaseTest.java

示例14: transform

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
    if (!instrumentor.shouldInstrument(className)) {
        return null;
    }
    try {
        final byte[] transformed = instrumentor.instrumentClass(className, classfileBuffer);
        File file = new File("/tmp/" + className + ".class");
        file.getParentFile().mkdirs();
        if(!file.exists()) {
        	file.createNewFile();
        }
        
        URLHelper.writeToURL(URLHelper.toURL(file), transformed, false);
        log("Wrote class file [" + file + "]");
        return transformed;
    } catch (Throwable t) {
  	  t.printStackTrace(System.err);
        instrumentor.error("while transforming " + className + ": " + t.getMessage(), t);
        return null;
    }
}
 
开发者ID:nickman,项目名称:JMXMPAgent,代码行数:23,代码来源:Test.java

示例15: getResource

import com.heliosapm.utils.url.URLHelper; //导入依赖的package包/类
/**
 * Returns the app resource for the passed app and resource name
 * @param appname The app name
 * @param resourceName The resource name
 * @return The resource bytes
 */
@RequestMapping(value="/resource/{appname}/{resourceName}", method=RequestMethod.GET, produces={"application/java-archive"})
public byte[] getResource(@PathVariable final String appname, @PathVariable final String resourceName) {
	final String _appname = appname.toLowerCase().trim();
	log.info("Fetching resource for [{}/{}]", _appname, resourceName);
	final File d = new File(new File(appDir, _appname), resourceName);
	return URLHelper.getBytesFromURL(URLHelper.toURL(d));
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:14,代码来源:NodeConfigurationServer.java


注:本文中的com.heliosapm.utils.url.URLHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。