Tuesday, August 7, 2012

List all xml files from the JAR.

Do you want to know which all files are in the jar without extracting it.?

This is a small tutorial where I am listing all the xml files.

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
 * List the name of all xml which is in given jars
 *
 * @author abdul
 */
public class ListXmlFiles {
    /* Stores the xml file name*/
    List<String> list = new ArrayList<String>();

    public List<String> getList() {
        return list;
    }

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        ListXmlFiles xmlFiles = new ListXmlFiles();
        JarFile jarFile = new JarFile("./lib/dummyJar.jar");
        Enumeration<JarEntry> e = jarFile.entries();
        while (e.hasMoreElements()) {
            xmlFiles.process(e.nextElement());
        }
        System.out.println("List:" + xmlFiles.getList());
    }

    private void process(Object obj) {
        JarEntry entry = (JarEntry)obj;
        String name = entry.getName();
        if(name.endsWith(".xml")) {
            list.add(name);      
        }
    }
}

If you want to know all the files name inside,Just removed the if-else filter, It will add all  the filename into the list.
private void process(Object obj) {
        JarEntry entry = (JarEntry)obj;
        String name = entry.getName();
        list.add(name);        

}


Wednesday, August 1, 2012

Windows Command Prompt Tricks You Probably Don’t Know

1. Send a Command’s Output to the Clipboard
Note: This will work for any command.

Without doing copy and paste the output, We can send the output directly to the clipboard.
ipconfig | clip

2. Open Command Prompt From a Folder

Do you want to open the command promp within a folder from explorer ? All you have to do is hold shift while right  clicking on a folder and the option will appear in the context menu.


3. Command History
We can view our past command  i,e using doskey command.
doskey /history

4. Drag and Drop Files to Change the Current Path

Another neat trick if you are not a fan of opening a command prompt from the context menu is the ability to drag and drop folders onto the prompt and have it automatically enter the path of the folder.



5. Run Multiple Commands In One Go
Want to run multiple command at once?  You can do this by linking them with double ampersands.
ipconfig && netstat

Friday, July 27, 2012

How to read properties file using ANT

Suppose You have to access some properties (from a file), which are already defined in my build file. To be able to access the properties We can use the build attribute of the property task. 

build.properties

#Release information 
#Thu Oct 14 16:25:12 CEST 2004
build.number=115
release.version=0.4
release.name=framework
 
Ant Example Target

<target name="read.properties">    
  <!-- Read the properties from the release of the framework -->
  <property file="build.properties" prefix="build"/>
  <echo message="${build.build.number}"/>
  <echo message="${build.release.version}"/>
  <echo message="${build.release.name}"/>    
</target> 
 
Output

Buildfile: C:\build.xml
read.properties:
  [echo] 115
  [echo] 0.4
  [echo] framework
BUILD SUCCESSFUL
Total time: 3 seconds

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...