本文整理汇总了Java中com.sun.squawk.io.connections.ClasspathConnection类的典型用法代码示例。如果您正苦于以下问题:Java ClasspathConnection类的具体用法?Java ClasspathConnection怎么用?Java ClasspathConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClasspathConnection类属于com.sun.squawk.io.connections包,在下文中一共展示了ClasspathConnection类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jarClasses
import com.sun.squawk.io.connections.ClasspathConnection; //导入依赖的package包/类
/**
* Creates a jar file of all the class files from which a given suite was built.
*
* @param file the jar file to create
* @param suite the suite to jar
*/
private void jarClasses(File file, Suite suite, boolean doJava5) {
try {
FileOutputStream fos = new FileOutputStream(file);
ZipOutputStream zos = new JarOutputStream(fos);
ClasspathConnection cp = (ClasspathConnection)Connector.open("classpath://" + (doJava5? this.java5ClassPath:this.classPath));
for (int i = 0; i < suite.getClassCount(); i++) {
Klass klass = suite.getKlass(i);
if (klass == null || klass.isSynthetic()) {
continue;
}
String classFilePath = klass.getName().replace('.', '/') + ".class";
addFileToJar(zos, cp, classFilePath);
}
zos.close();
} catch (IOException e) {
throw new RuntimeException("IO error creating jar file", e);
}
}
示例2: ClassSourcePrinter
import com.sun.squawk.io.connections.ClasspathConnection; //导入依赖的package包/类
/**
* Creates a new instance of ClassSourcePrinter
*
* Attempts to find a source file for the given class by searching the source path
*
* @param klass the klass to display
* @param the sourcepath to search
* @throws IOException if no source file is found.
*/
public ClassSourcePrinter(Klass klass, String sourcePath) throws IOException {
String filename = klass.getSourceFilePath();
if (filename == null) {
throw new IOException(klass + " has no record of it's source file name.");
}
// it turns out that ClasspathConnection works for any kind of file, not just .class Even works on jar files of source?
ClasspathConnection sourcepath = (ClasspathConnection)Connector.open("classpath://" + sourcePath);
InputStream is = sourcepath.openInputStream(filename);
InputStreamReader isr = new InputStreamReader(is);
LineReader lr = new LineReader(isr);
lines = lr.readLines(null);
is.close();
sourcepath.close();
}
示例3: addFileToJar
import com.sun.squawk.io.connections.ClasspathConnection; //导入依赖的package包/类
/**
* Adds a given file to a given jar file stream.
*
* @param zos the jar stream
* @param classPath where to find the file
* @param filePath the path to the file
* @throws IOException if there is an IO error
*/
private void addFileToJar(ZipOutputStream zos, ClasspathConnection classPath, String filePath) throws IOException {
byte[] data = classPath.getBytes(filePath);
ZipEntry e = new ZipEntry(filePath);
e.setTime(System.currentTimeMillis());
zos.putNextEntry(e);
zos.write(data);
zos.closeEntry();
}
示例4: processClassJarOrZipArg
import com.sun.squawk.io.connections.ClasspathConnection; //导入依赖的package包/类
/**
* Processes a single command line argument that specifies a jar or zip
* file of class files.
*
* @param arg the command line argument to process
* @param classes the list of class names to augment
* @param resources the list of resource to augment
*/
public static void processClassJarOrZipArg(String arg, Vector classes, Vector resources) throws HostedPragma {
try {
ClasspathConnection cp = (ClasspathConnection)Connector.open("classpath://" + arg);
processClasspathConnection(cp, classes, resources);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
示例5: processClasspathConnection
import com.sun.squawk.io.connections.ClasspathConnection; //导入依赖的package包/类
/**
* Processes a single command line argument that specifies a jar or zip
* file of class files.
*
* @param cp the command line argument to process
* @param classes the list of class names to augment
* @param resources the list of resource to augment
*/
public static void processClasspathConnection(ClasspathConnection cp, Vector classes, Vector resources) throws HostedPragma {
try {
DataInputStream dis = new DataInputStream(cp.openInputStream("//"));
try {
for (;;) {
String name = dis.readUTF();
if (name.endsWith(".class")) {
name = name.substring(0, name.length() - ".class".length());
name = name.replace('/', '.');
classes.addElement(name);
} else if (nameInSkipList(name)) {
System.out.println("Skipping resource file: " + name);
continue;
} else {
try {
byte[] bytes = cp.getBytes(name);
ResourceFile resource = new ResourceFile(name, bytes);
resources.addElement(resource);
} catch (IOException e) {
}
}
}
} catch (EOFException ex) {
}
dis.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}