Install Oracle JDeveloper on Mac OS X 10.7.5

Please follow this link
http://www.sebsgarage.com/2009/10/installing-oracle-jdeveloper-11g-mac-osx

Advertisements

Setup Hibernate 3 with Maven in Eclipse (Juno)

Hibernate is an ORM (Object Relational Mapping) tool. Probably you have setup Maven in your Eclipse, as for this I’m using Eclipse Juno. Due to some issues on Maven repositories, it is not that easy to include Hibernate 3 libraries using Maven dependencies in your Eclipse. It is easy if you just add the library using the Java Build Path, but now Im totally using Maven for my new Java Projects.

Continue reading

Manipulating BIG file in JAVA

This was discussed back in 2002 during the early of Java, reading and writing big files has been an issue since and til now. Found this article at

http://www.techrepublic.com/article/handling-large-data-files-efficiently-with-java/1046714
/**
   *  Reads a file storing intermediate data into a list. Fast method.
   *  @param file the file to be read
   *  @return a file data
   */
   public byte[] read2list(String file) throws Exception {
      InputStream in = null;
      byte[] buf             = null; // output buffer
      int    bufLen          = 20000*1024;
      try{
         in = new BufferedInputStream(new FileInputStream(file));
         buf = new byte[bufLen];
         byte[] tmp = null;
         int len    = 0;
         List data  = new ArrayList(24); // keeps peaces of data
         while((len = in.read(buf,0,bufLen)) != -1){
            tmp = new byte[len];
            System.arraycopy(buf,0,tmp,0,len); // still need to do copy
            data.add(tmp);
         }
         /*
            This part os optional. This method could return a List data
            for further processing, etc.
         */
         len = 0;
         if (data.size() == 1) return (byte[]) data.get(0);
         for (int i=0;i<data.size();i++) len += ((byte[]) data.get(i)).length;
         buf = new byte[len]; // final output buffer
         len = 0;
         for (int i=0;i<data.size();i++){ // fill with data
           tmp = (byte[]) data.get(i);
            System.arraycopy(tmp,0,buf,len,tmp.length);
            len += tmp.length;
         }
      }finally{
         if (in != null) try{ in.close();}catch (Exception e){}
      }
      return buf;
   }

 

How to read very BIG text files in Java

I found this on

http://code.hammerpig.com/how-to-read-really-large-files-in-java.html

import java.util.*;
import java.io.*;

public class BigFile implements Iterable<String>
{
    private BufferedReader _reader;

    public BigFile(String filePath) throws Exception
    {
	_reader = new BufferedReader(new FileReader(filePath));
    }

    public void Close()
    {
	try
	{
	    _reader.close();
	}
	catch (Exception ex) {}
    }

    public Iterator<String> iterator()
    {
	return new FileIterator();
    }

    private class FileIterator implements Iterator<String>
    {
	private String _currentLine;

	public boolean hasNext()
	{
	    try
	    {
		_currentLine = _reader.readLine();
	    }
	    catch (Exception ex)
	    {
		_currentLine = null;
		ex.printStackTrace();
	    }

	    return _currentLine != null;
	}

	public String next()
	{
	    return _currentLine;
	}

	public void remove()
	{
	}
    }
}

 

BigFile file = new BigFile("C:\Temp\BigFile.txt");

for (String line : file)
    System.out.println(line)

 

Tomcat – java.lang.OutOfMemoryError: PermGen space

 

Tomcat production server sometime will hit the following java.lang.OutOfMemoryError: PermGen space error.

java.lang.OutOfMemoryError: PermGen space
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)

You should change the “Xms” and “PermSize” value base on your server capability.

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 
-server -Xms1536m -Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m 
-XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"

Timeout in Axis2 Web Services Client

This is how we set timeout when we call a web services.

public static void main(String[] args) {
MyTimeoutSampleMainmain = new MyTimeoutSampleMain();
try {
MyTimeoutSampleStub stub = new MyTimeoutSampleStub(“http://xxxxx/webservices&#8221;);
long soTimeout = 2 * 60 * 1000; //2 minutes
soTimeout = 2 * 1000;

stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(soTimeout);

getResponseFromWebServices(stub);
}
catch (AxisFault ex) {
ex.printStackTrace();
}

}