本文整理汇总了Java中java.util.jar.JarEntry.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java JarEntry.getSize方法的具体用法?Java JarEntry.getSize怎么用?Java JarEntry.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.jar.JarEntry
的用法示例。
在下文中一共展示了JarEntry.getSize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findClassInJarFile
import java.util.jar.JarEntry; //导入方法依赖的package包/类
protected Class<?> findClassInJarFile(String qualifiedClassName) throws ClassNotFoundException {
URI classUri = URIUtil.buildUri(StandardLocation.CLASS_OUTPUT, qualifiedClassName);
String internalClassName = classUri.getPath().substring(1);
JarFile jarFile = null;
try {
for (int i = 0; i < jarFiles.size(); i++) {
jarFile = jarFiles.get(i);
JarEntry jarEntry = jarFile.getJarEntry(internalClassName);
if (jarEntry != null) {
InputStream inputStream = jarFile.getInputStream(jarEntry);
try {
byte[] byteCode = new byte[(int) jarEntry.getSize()];
ByteStreams.read(inputStream, byteCode, 0, byteCode.length);
return defineClass(qualifiedClassName, byteCode, 0, byteCode.length);
} finally {
Closeables.closeQuietly(inputStream);
}
}
}
} catch (IOException e) {
throw new IllegalStateException(String.format("Failed to lookup class %s in jar file %s", qualifiedClassName, jarFile), e);
}
return null;
}
示例2: getFromJarFile
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/**
* Browse a jar file for the desired class.
* @param jarFile The jar file to browse.
* @param name The full name of the class to find.
* @return A ClassFile in case of success, null otherwise.
* @throws ClassFileException Thrown on fatal errors loading or parsing a class file.
* @throws IOException Thrown on fatal problems reading or writing to the file system.
*/
private ClassFile getFromJarFile(JarFile jarFile, String name) throws ClassFileException, IOException {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
/*
* Just browse trough all entries, they probably will not be shown hierarchically or in
* a sorted order.
*/
JarEntry entry = entries.nextElement();
if (entry != null && entry.getName().equals(name)) {
// Construct the full path to the class file.
String fullPath = jarFile.getName() + "|" + entry.getName();
// Return the ClassFile.
try {
return new ClassFile(this, jarFile.getInputStream(entry), jarFile
.getInputStream(entry), entry.getSize(), fullPath);
} catch(Exception e) {
e.printStackTrace();
return null;
}
}
}
return null;
}
示例3: findClass
import java.util.jar.JarEntry; //导入方法依赖的package包/类
protected Class<?> findClass(String name) throws ClassNotFoundException {
try {
byte[] b;
String entryName = name.replace(".", "/") + ".class";
JarEntry je = jf.getJarEntry(entryName);
if (je != null) {
try (InputStream is = jf.getInputStream(je)) {
b = new byte[(int) je.getSize()];
is.read(b);
}
return defineClass(name, b, 0, b.length);
}
throw new ClassNotFoundException(name);
} catch (IOException x) {
throw new ClassNotFoundException(x.getMessage());
}
}
示例4: testUnusualFileSize
import java.util.jar.JarEntry; //导入方法依赖的package包/类
/** Too large or too small (empty) files are suspicious.
* There should be just couple of them: splash image
*/
public void testUnusualFileSize() throws Exception {
SortedSet<Violation> violations = new TreeSet<Violation>();
for (File f: org.netbeans.core.startup.Main.getModuleSystem().getModuleJars()) {
// check JAR files only
if (!f.getName().endsWith(".jar"))
continue;
JarFile jar = new JarFile(f);
Enumeration<JarEntry> entries = jar.entries();
JarEntry entry;
BufferedImage img;
while (entries.hasMoreElements()) {
entry = entries.nextElement();
if (entry.isDirectory())
continue;
long len = entry.getSize();
if (len >= 0 && len < 10) {
violations.add(new Violation(entry.getName(), jar.getName(), " is too small ("+len+" bytes)"));
}
if (len >= 200 * 1024) {
violations.add(new Violation(entry.getName(), jar.getName(), " is too large ("+len+" bytes)"));
}
}
}
if (!violations.isEmpty()) {
StringBuilder msg = new StringBuilder();
msg.append("Some files have extreme size ("+violations.size()+"):\n");
for (Violation viol: violations) {
msg.append(viol).append('\n');
}
fail(msg.toString());
}
}
示例5: processDownloadedFile
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public void processDownloadedFile(File downloadedFile) throws UpdateException {
InputStream indexInputStream = null;
try {
if (downloadedFile == null || !downloadedFile.exists()) {
throw new UpdateException(repo, downloadedFile + " does not exist!");
}
// Due to a bug in Android 5.0 Lollipop, the inclusion of spongycastle causes
// breakage when verifying the signature of the downloaded .jar. For more
// details, check out https://gitlab.com/fdroid/fdroidclient/issues/111.
FDroidApp.disableSpongyCastleOnLollipop();
JarFile jarFile = new JarFile(downloadedFile, true);
JarEntry indexEntry = (JarEntry) jarFile.getEntry("index.xml");
indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
processIndexListener, new URL(repo.address), (int) indexEntry.getSize());
// Process the index...
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
final SAXParser parser = factory.newSAXParser();
final XMLReader reader = parser.getXMLReader();
final RepoXMLHandler repoXMLHandler = new RepoXMLHandler(repo, createIndexReceiver());
reader.setContentHandler(repoXMLHandler);
reader.parse(new InputSource(indexInputStream));
long timestamp = repoDetailsToSave.getAsLong(RepoTable.Cols.TIMESTAMP);
if (timestamp < repo.timestamp) {
throw new UpdateException(repo, "index.jar is older that current index! "
+ timestamp + " < " + repo.timestamp);
}
signingCertFromJar = getSigningCertFromJar(indexEntry);
// JarEntry can only read certificates after the file represented by that JarEntry
// has been read completely, so verification cannot run until now...
assertSigningCertFromXmlCorrect();
commitToDb();
} catch (SAXException | ParserConfigurationException | IOException e) {
throw new UpdateException(repo, "Error parsing index", e);
} finally {
FDroidApp.enableSpongyCastleOnLollipop();
Utils.closeQuietly(indexInputStream);
if (downloadedFile != null) {
if (!downloadedFile.delete()) {
Log.w(TAG, "Couldn't delete file: " + downloadedFile.getAbsolutePath());
}
}
}
}
示例6: processDownloadedIndex
import java.util.jar.JarEntry; //导入方法依赖的package包/类
private void processDownloadedIndex(File outputFile, String cacheTag)
throws IOException, RepoUpdater.UpdateException {
JarFile jarFile = new JarFile(outputFile, true);
JarEntry indexEntry = (JarEntry) jarFile.getEntry(DATA_FILE_NAME);
InputStream indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
processIndexListener, new URL(repo.address), (int) indexEntry.getSize());
processIndexV1(indexInputStream, indexEntry, cacheTag);
}
示例7: reloadJar
import java.util.jar.JarEntry; //导入方法依赖的package包/类
public void reloadJar(String fileName) throws IOException {
JarFile jarFile = new JarFile(path + File.separator + fileName);
Enumeration<JarEntry> entries = jarFile.entries();
InputStream input = null;
BufferedInputStream fileInputStream = null;
while (entries.hasMoreElements()) {
try {
JarEntry jarEntry = (JarEntry) entries.nextElement();
if (jarEntry.isDirectory()) {
continue;
}
if (jarEntry.getName().endsWith("package-info.class")) {
continue;
}
if (!jarEntry.getName().endsWith(".class")) {
continue;
}
input = jarFile.getInputStream(jarEntry);
long size = jarEntry.getSize();
byte[] bs = new byte[(int) size];
fileInputStream = new BufferedInputStream(input);
fileInputStream.read(bs);
String clazzName = jarEntry.getName().replaceAll("/", ".");
// System.out.println(clazzName + " " + bs.length);
hotSwapper.reload(clazzName, bs);
} catch (Exception e) {
logger.error("reloadJar error", e);
} finally {
input.close();
fileInputStream.close();
}
}
}
示例8: find
import java.util.jar.JarEntry; //导入方法依赖的package包/类
@Override
public Resource find(String name) throws IOException {
JarEntry entry = jf.getJarEntry(name);
if (entry == null)
return null;
return new Resource() {
@Override
public String getName() {
return name;
}
@Override
public URL getURL() {
String encodedPath = ParseUtil.encodePath(name, false);
try {
return new URL("jar:" + csURL + "!/" + encodedPath);
} catch (MalformedURLException e) {
return null;
}
}
@Override
public URL getCodeSourceURL() {
return csURL;
}
@Override
public ByteBuffer getByteBuffer() throws IOException {
byte[] bytes = getInputStream().readAllBytes();
return ByteBuffer.wrap(bytes);
}
@Override
public InputStream getInputStream() throws IOException {
return jf.getInputStream(entry);
}
@Override
public int getContentLength() throws IOException {
long size = entry.getSize();
return (size > Integer.MAX_VALUE) ? -1 : (int) size;
}
};
}