the first commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) DuxTechnica
|
||||
*
|
||||
* Licensed under the DuxTechnica Limited Use Source Code License Agreement (DT-LUSCL); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of the License by
|
||||
* contacting:
|
||||
*
|
||||
* Dux Technica, [email protected]
|
||||
*
|
||||
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package dux.scanpath.v1.support;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* An entry within a JAR file that can be used to read the bytecodes of a Java class.
|
||||
*
|
||||
* @author indroneel
|
||||
*/
|
||||
|
||||
public class JarClassFile implements ClassFile {
|
||||
|
||||
private final JarFile root;
|
||||
private final JarEntry entry;
|
||||
|
||||
/**
|
||||
* Creates a new JAR class file entry.
|
||||
*
|
||||
* @param root the JAR file that contains the class file entry
|
||||
* @param entry the JAR entry that represents the class file
|
||||
*/
|
||||
|
||||
public JarClassFile(JarFile root, JarEntry entry) {
|
||||
this.root = root;
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Methods of interface ClassFile
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
String name = entry.getName();
|
||||
if(name.startsWith("/")) {
|
||||
name = name.substring(1, name.lastIndexOf('.')).replace('/', '.');
|
||||
}
|
||||
else {
|
||||
name = name.substring(0, name.lastIndexOf('.')).replace('/', '.');
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String getSimpleName() {
|
||||
String fqcn = getName();
|
||||
return fqcn.substring(fqcn.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public InputStream openInputStream() throws IOException {
|
||||
return root.getInputStream(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return root.getName() + "!" + java.io.File.separatorChar + entry.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user