From 959cb5fd4f9586ec3bd265b452fe25fe1db82e3f Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 13 Jan 2015 23:25:04 -0500 Subject: source format change don't hate me too much if you were planning a big merge. =P --- src/cuchaz/enigma/analysis/JarClassIterator.java | 107 +++++++++-------------- 1 file changed, 41 insertions(+), 66 deletions(-) (limited to 'src/cuchaz/enigma/analysis/JarClassIterator.java') diff --git a/src/cuchaz/enigma/analysis/JarClassIterator.java b/src/cuchaz/enigma/analysis/JarClassIterator.java index f65b8e7..8d9947c 100644 --- a/src/cuchaz/enigma/analysis/JarClassIterator.java +++ b/src/cuchaz/enigma/analysis/JarClassIterator.java @@ -30,132 +30,107 @@ import com.google.common.collect.Lists; import cuchaz.enigma.Constants; import cuchaz.enigma.mapping.ClassEntry; -public class JarClassIterator implements Iterator -{ +public class JarClassIterator implements Iterator { + private JarFile m_jar; private Iterator m_iter; - public JarClassIterator( JarFile jar ) - { + public JarClassIterator(JarFile jar) { m_jar = jar; // get the jar entries that correspond to classes List classEntries = Lists.newArrayList(); Enumeration entries = m_jar.entries(); - while( entries.hasMoreElements() ) - { + while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); // is this a class file? - if( entry.getName().endsWith( ".class" ) ) - { - classEntries.add( entry ); + if (entry.getName().endsWith(".class")) { + classEntries.add(entry); } } m_iter = classEntries.iterator(); } @Override - public boolean hasNext( ) - { + public boolean hasNext() { return m_iter.hasNext(); } - + @Override - public CtClass next( ) - { + public CtClass next() { JarEntry entry = m_iter.next(); - try - { - return getClass( m_jar, entry ); - } - catch( IOException | NotFoundException ex ) - { - throw new Error( "Unable to load class: " + entry.getName() ); + try { + return getClass(m_jar, entry); + } catch (IOException | NotFoundException ex) { + throw new Error("Unable to load class: " + entry.getName()); } } - + @Override - public void remove( ) - { + public void remove() { throw new UnsupportedOperationException(); } - public static List getClassEntries( JarFile jar ) - { + public static List getClassEntries(JarFile jar) { List classEntries = Lists.newArrayList(); Enumeration entries = jar.entries(); - while( entries.hasMoreElements() ) - { + while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); // is this a class file? - if( !entry.isDirectory() && entry.getName().endsWith( ".class" ) ) - { - classEntries.add( getClassEntry( entry ) ); + if (!entry.isDirectory() && entry.getName().endsWith(".class")) { + classEntries.add(getClassEntry(entry)); } } return classEntries; } - public static Iterable classes( final JarFile jar ) - { - return new Iterable( ) - { + public static Iterable classes(final JarFile jar) { + return new Iterable() { @Override - public Iterator iterator( ) - { - return new JarClassIterator( jar ); + public Iterator iterator() { + return new JarClassIterator(jar); } }; } - public static CtClass getClass( JarFile jar, ClassEntry classEntry ) - { - try - { - return getClass( jar, new JarEntry( classEntry.getName() + ".class" ) ); - } - catch( IOException | NotFoundException ex ) - { - throw new Error( "Unable to load class: " + classEntry.getName() ); + public static CtClass getClass(JarFile jar, ClassEntry classEntry) { + try { + return getClass(jar, new JarEntry(classEntry.getName() + ".class")); + } catch (IOException | NotFoundException ex) { + throw new Error("Unable to load class: " + classEntry.getName()); } } - private static CtClass getClass( JarFile jar, JarEntry entry ) - throws IOException, NotFoundException - { + private static CtClass getClass(JarFile jar, JarEntry entry) throws IOException, NotFoundException { // read the class into a buffer ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[Constants.KiB]; int totalNumBytesRead = 0; - InputStream in = jar.getInputStream( entry ); - while( in.available() > 0 ) - { - int numBytesRead = in.read( buf ); - if( numBytesRead < 0 ) - { + InputStream in = jar.getInputStream(entry); + while (in.available() > 0) { + int numBytesRead = in.read(buf); + if (numBytesRead < 0) { break; } - bos.write( buf, 0, numBytesRead ); + bos.write(buf, 0, numBytesRead); // sanity checking totalNumBytesRead += numBytesRead; - if( totalNumBytesRead > Constants.MiB ) - { - throw new Error( "Class file " + entry.getName() + " larger than 1 MiB! Something is wrong!" ); + if (totalNumBytesRead > Constants.MiB) { + throw new Error("Class file " + entry.getName() + " larger than 1 MiB! Something is wrong!"); } } // get a javassist handle for the class - String className = Descriptor.toJavaName( getClassEntry( entry ).getName() ); + String className = Descriptor.toJavaName(getClassEntry(entry).getName()); ClassPool classPool = new ClassPool(); - classPool.insertClassPath( new ByteArrayClassPath( className, bos.toByteArray() ) ); - return classPool.get( className ); + classPool.insertClassPath(new ByteArrayClassPath(className, bos.toByteArray())); + return classPool.get(className); } - private static ClassEntry getClassEntry( JarEntry entry ) - { - return new ClassEntry( entry.getName().substring( 0, entry.getName().length() - ".class".length() ) ); + private static ClassEntry getClassEntry(JarEntry entry) { + return new ClassEntry(entry.getName().substring(0, entry.getName().length() - ".class".length())); } } -- cgit v1.2.3