Methods Summary |
---|
public static java.lang.String | URLtoCodeBase(java.net.URL classPathElement)Returns a codeBase expression, usable in a policy file, for the specified
URL.
/*
*We can assume the URL specifies a file.
*/
File file = new File(classPathElement.toURI());
if (! file.exists()) {
/*
*If we cannot locate the file, it may be a jar listed in the
*manifest's Class-Path of a top-level archive. The spec does
*not require containers to handle such jars, so just
*return null.
*/
//throw new FileNotFoundException(classPathElement.toURI().toASCIIString());
return null;
}
/*
*The format of the codebase is different for a directory vs. a jar
*file. Also note that the codebase must use the platform-neutral
*"forward-slash" notation.
*/
String result;
if (file.isDirectory()) {
result = classPathElement.getProtocol() + ":" + classPathElement.toURI().getPath() + "-";
} else {
result = classPathElement.getProtocol() + ":" + classPathElement.toURI().getPath();
}
return result;
|
public static java.io.File | copyToTempFile(java.io.File inputFile, java.lang.String prefix, java.lang.String suffix, boolean retainFile)Copy an existing file into a temporary file.
File result = null;
BufferedInputStream is = null;
BufferedOutputStream os = null;
try {
result = File.createTempFile(prefix, suffix);
if ( ! retainFile) {
result.deleteOnExit();
}
os = new BufferedOutputStream(new FileOutputStream(result));
is = new BufferedInputStream(new FileInputStream(inputFile));
byte [] buffer = new byte[BUFFER_SIZE];
int bytesRead = 0;
while ( (bytesRead = is.read(buffer) ) != -1) {
os.write(buffer, 0, bytesRead);
}
return result;
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}
|
public static java.lang.String | getMainClassNameForAppClient(com.sun.enterprise.deployment.util.ModuleDescriptor moduleDescr)Returns the main class name for the app client represented by the module descriptor.
BundleDescriptor bd = moduleDescr.getDescriptor();
ApplicationClientDescriptor acDescr = (ApplicationClientDescriptor) bd;
String mainClassName = acDescr.getMainClassName();
return mainClassName;
|
public static java.lang.String | loadResource(java.lang.Class contextClass, java.lang.String resourcePath)Retrieves a resource as a String.
This method does not save the template in a cache. Use the instance method
getTemplate for that purpose.
String result = null;
InputStream is = null;
try {
is = contextClass.getResourceAsStream(resourcePath);
if (is == null) {
throw new IOException("Could not locate the requested resource relative to class " + contextClass.getName());
}
StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
int charsRead;
char [] buffer = new char [BUFFER_SIZE];
while ((charsRead = reader.read(buffer)) != -1) {
sb.append(buffer, 0, charsRead);
}
result= sb.toString();
return result;
} catch (IOException ioe) {
IOException wrapperIOE = new IOException("Error loading resource " + resourcePath);
wrapperIOE.initCause(ioe);
throw wrapperIOE;
} finally {
if (is != null) {
is.close();
}
}
|
public static java.net.URL | locateClass(java.lang.Class target)Finds the jar file or directory that contains the current class and returns its URI.
return target.getProtectionDomain().getCodeSource().getLocation();
|
public static java.lang.String | replaceTokens(java.lang.String s, java.util.Properties values)Searches for placeholders of the form ${token-name} in the input String, retrieves
the property with name token-name from the Properties object, and (if
found) replaces the token in the input string with the property value.
Matcher m = placeholderPattern.matcher(s);
StringBuffer sb = new StringBuffer();
/*
*For each match, retrieve group 1 - the token - and use its value from
*the Properties object (if found there) to replace the token with the
*value.
*/
while (m.find()) {
String propertyName = m.group(1);
String propertyValue = values.getProperty(propertyName);
if (propertyValue != null) {
/*
*The next line quotes any $ signs in the replacement string
*so they are not interpreted as meta-characters by the regular expression
*processor's appendReplacement. The replaceAll replaces all occurrences
*of $ with \$. The extra slashes are needed to quote the backslash
*for the Java language processor and then again for the regex
*processor (!).
*/
String adjustedPropertyValue = propertyValue.replaceAll("\\$", "\\\\\\$");
String x = s.substring(m.start(),m.end());
try {
m.appendReplacement(sb, adjustedPropertyValue);
} catch (IllegalArgumentException iae) {
System.err.println("**** appendReplacement failed: segment is " + x + "; original replacement was " + propertyValue + " and adj. replacement is " + adjustedPropertyValue + "; exc follows");
throw iae;
}
}
}
/*
*There are no more matches, so append whatever remains of the matcher's input
*string to the output.
*/
m.appendTail(sb);
return sb.toString();
|
public static java.io.File | writeTextToTempFile(java.lang.String content, java.lang.String prefix, java.lang.String suffix, boolean retainFile)Writes the provided text to a temporary file marked for deletion on exit.
BufferedWriter wtr = null;
try {
File result = File.createTempFile(prefix, suffix);
if ( ! retainFile) {
result.deleteOnExit();
}
FileOutputStream fos = new FileOutputStream(result);
wtr = new BufferedWriter(new OutputStreamWriter(fos));
wtr.write(content);
wtr.close();
return result;
} finally {
if (wtr != null) {
wtr.close();
}
}
|
public static java.io.File | writeTextToTempFile(java.lang.String content, java.lang.String prefix, java.lang.String suffix)Writes the provided text to a temporary file marked for deletion on exit.
return writeTextToTempFile(content, prefix, suffix, false);
|