<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6505330232874994379</id><updated>2024-09-02T01:03:14.181-07:00</updated><title type='text'>Java</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bajishaik.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://bajishaik.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Baji Shaik</name><uri>http://www.blogger.com/profile/04991693737624125341</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6505330232874994379.post-5296845145093242432</id><published>2011-02-27T20:40:00.000-08:00</published><updated>2011-02-27T20:43:13.567-08:00</updated><title type='text'>Listing the files from FTP order by modification date</title><content type='html'>&lt;html&gt;&lt;br /&gt;
&lt;head&gt;&lt;br /&gt;
&lt;title&gt;Downloading the files from ftp order by modification date&lt;/title&gt;&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
body {
	font-family:&#39;Lucida Grande&#39;,Geneva,Verdana,Arial,sans-serif;
}
body {
	color:#333333;
	font-family:&#39;Lucida Grande&#39;,Geneva,Verdana,Arial,sans-serif;
	font-size:14px;
	line-height:150%;
	text-align:justify;
}
	.keyword
	{
	    font-weight:bold;
	    color:#7F1B55;
	}
	.java {
		line-height:20px;
		margin-bottom:0em;
		vertical-align:top;
	    text-align:left;
	    font-size:13px;
	    color:rgb(0,0,0);
	}
	pre.java{
		background-color:#F5F5F5;
		border:1px solid #CCCCCC;
		font-family:verdana,helvetica,sans-serif;
		padding:5px 15px 5px 25px;
	}
&lt;/style&gt;&lt;br /&gt;
&lt;/head&gt;&lt;br /&gt;
&lt;body&gt;&lt;br /&gt;
&lt;p&gt;Here we are using ftp4j for FTP operations.&lt;/p&gt;&lt;p&gt;Before going to listing FTP files let us see how to list the files from local filesystem.&lt;/p&gt;&lt;p&gt;But before going to do this you must know what is comparable interface and what it will do?&lt;/p&gt;&lt;br /&gt;
&lt;pre style=&quot;background:lightgray;&quot;&gt;The Comparable Interface:

Objects of classes that implement Comparable can be ordered.
The Comparable interface declares one method 
that is used to determine the natural 
ordering of instances of a class.
The signature of the method is shown here:

&lt;span class=&quot;keyword&quot;&gt;int &lt;/span&gt;compareTo(Object obj)

This method compares the invoking object with obj.
It returns 0 if the values are equal.
A negative value is returned if the invoking 
object has a lower value. Otherwise, a positive value is returned.
		
&lt;/pre&gt;&lt;p&gt;This is an example of comparable interface with the modification date of local system files .&lt;/p&gt;&lt;pre class=&quot;java&quot;&gt;	&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; java.io.File;
	&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; FileComparator &lt;span class=&quot;keyword&quot;&gt;implements&lt;/span&gt; Comparable {
	    &lt;span class=&quot;keyword&quot;&gt;public long &lt;/span&gt;time;
	    &lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt; File filename;
	
	    &lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt; FileComparator(File file) {
	    	filename = file;
	    	time = file.lastModified().getTime();
	    }
	
		&lt;span class=&quot;keyword&quot;&gt;public int &lt;/span&gt;compareTo(Object o) {
	        &lt;span class=&quot;keyword&quot;&gt;long &lt;/span&gt;u = ((FileComparator) o).time;
	        &lt;span class=&quot;keyword&quot;&gt;return &lt;/span&gt;time &lt; u ? -1 : time == u ? 0 : 1;
	    }
	};
&lt;/pre&gt;
&lt;p&gt;And this is an example of comparable interface with the modification dates of FTP files .&lt;/p&gt;&lt;pre class=&quot;java&quot;&gt;	
	&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; it.sauronsoftware.ftp4j.FTPFile;		
	&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; FTPFileComparator &lt;span class=&quot;keyword&quot;&gt;implements&lt;/span&gt; Comparable {
	    &lt;span class=&quot;keyword&quot;&gt;public long &lt;/span&gt;time;
	    &lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt; FTPFile filename;
	
	    &lt;span class=&quot;keyword&quot;&gt;public&lt;/span&gt; FTpFileComparator(FTPFile file) {
	    	filename = file;
	    	time = file.getModifiedDate().getTime();
	    }
	
		&lt;span class=&quot;keyword&quot;&gt;public int &lt;/span&gt;compareTo(Object o) {
	        &lt;span class=&quot;keyword&quot;&gt;long &lt;/span&gt;u = ((FTpFileComparator) o).time;
	        &lt;span class=&quot;keyword&quot;&gt;return &lt;/span&gt;time &lt; u ? -1 : time == u ? 0 : 1;
	    }
	};
&lt;/pre&gt;
&lt;p&gt;This is an example for listing the files order by modification dates .&lt;/p&gt;&lt;pre class=&quot;java&quot;&gt;	&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; java.io.File;
	File inpDir=&lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; File(&quot;/opt/directory&quot;);
	&lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt;(inpDir.isDirectory()){
		File files[]=inpDir.listFiles();
		FileComparator[] comp = new FileComparator[files.length];
		
	      &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;int&lt;/span&gt; i = 0; i &lt; files.length; i++)
	    	  comp[i] = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; FileComparator(files[i]);
	      
	      Arrays.sort(comp);
	      
	      &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;int&lt;/span&gt; i = 0; i &lt; files.length; i++)
	          files[i] = comp[i].filename;  
	      
	      &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;int&lt;/span&gt; i = 0; i &lt; files.length; i++)
	    	  System.out.println(files[i]);
	}
&lt;/pre&gt;
&lt;p&gt;This is an example for listing the FTP files order by modification dates .&lt;/p&gt;&lt;pre class=&quot;java&quot;&gt;	&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; it.sauronsoftware.ftp4j.FTPFile;
		
	FTPClient client=&lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; FTPClient();
	client.connect(inpFtpUrl);
	client.login(inpFtpUserName, inpFtpPassword);
	client.changeDirectory(inpFtpDirPath);
	FTPFile[] files = client.list();                     
	FTpFileComparator[] comp = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; FTpFileComparator[files.length];

	      &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;int&lt;/span&gt; i = 0; i &lt; files.length; i++)
	    	  comp[i] = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; FileComparator(files[i]);
	      
	      Arrays.sort(comp);
	      
	      &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;int&lt;/span&gt; i = 0; i &lt; files.length; i++)
	          files[i] = comp[i].filename;  
	      
	      &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;int&lt;/span&gt; i = 0; i &lt; files.length; i++)
	    	  System.out.println(files[i]);   
    
&lt;/pre&gt;
&lt;/div&gt;&lt;/body&gt;
&lt;/html&gt;</content><link rel='replies' type='application/atom+xml' href='http://bajishaik.blogspot.com/feeds/5296845145093242432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bajishaik.blogspot.com/2011/02/listing-files-from-ftp-order-by.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/5296845145093242432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/5296845145093242432'/><link rel='alternate' type='text/html' href='http://bajishaik.blogspot.com/2011/02/listing-files-from-ftp-order-by.html' title='Listing the files from FTP order by modification date'/><author><name>Baji Shaik</name><uri>http://www.blogger.com/profile/04991693737624125341</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6505330232874994379.post-1715697744612619956</id><published>2011-01-13T00:51:00.000-08:00</published><updated>2011-01-13T00:51:33.038-08:00</updated><title type='text'>ISBN validation In Java</title><content type='html'>&lt;pre&gt;
Use Jakarta-ORO for ISBN validation.

The Jakarta-ORO Java classes are a set of text-processing
 Java classes that provide Perl5 compatible regular
 expressions, AWK-like regular expressions, 
glob expressions, and utility classes 
for performing substitutions, 
splits, filtering filenames, etc.
&lt;/pre&gt;&lt;br /&gt;
&lt;a Style=&quot;color:blue&quot; 
href=&quot;http://apache.opensourceresources.org//jakarta/oro/binaries/jakarta-oro-2.0.8.zip&quot;&gt;Download Jakarta-ORO jar&lt;/a&gt;&lt;br /&gt;
&lt;pre&gt;import org.apache.oro.text.perl.Perl5Util;

public class ISBNValidator {

  private static final String SEP = &quot;(\\-|\\s)&quot;;
  private static final String GROUP = &quot;(\\d{1,5})&quot;;
  private static final String PUBLISHER = &quot;(\\d{1,7})&quot;;
  private static final String TITLE = &quot;(\\d{1,6})&quot;;
  private static final String CHECK_ISBN10 = &quot;([0-9X])&quot;;
  private static final String CHECK_ISBN13 = &quot;(\\d)&quot;;
  private static final String PREFIX = &quot;(978|979)&quot;;

  private static final String ISBN10_PATTERN = &quot;/^&quot; + GROUP
                     + SEP + PUBLISHER + SEP + TITLE + SEP
                     + CHECK_ISBN10 + &quot;$/&quot;;

  private static final String ISBN13_PATTERN = &quot;/^&quot; + 
           PREFIX + SEP + GROUP + SEP + PUBLISHER + SEP
           + TITLE + SEP + CHECK_ISBN13 + &quot;$/&quot;;

  private static final String 
                       EAN13_PATTERN = &quot;/^&quot; + PREFIX + &quot;\\d{10}$/&quot;;

  public ISBNValidator() {
    super();
  }

  public boolean isValid(String isbn) {
    return isValidISBN10(isbn) || isValidISBN13(isbn);
  }

  public boolean isValidISBN10(String isbn) {
    if (isbn == null || isbn.length() &lt; 10 || isbn.length() &gt; 13) {
      return false;
    }

    if (isFormatted(isbn) &amp;&amp; !isValidPatternISBN10(isbn)) {
      return false;
    }

    isbn = cleanISBN10(isbn);
    if (isbn.length() != 10) {
      return false;
    }

    return (sumISBN10(isbn) % 11) == 0;
  }

  public boolean isValidISBN13(String isbn) {
    if (isbn == null || isbn.length() &lt; 13 || isbn.length() &gt; 17) {
      return false;
    }

    if (isFormatted(isbn)) {
      if (!isValidPatternISBN13(isbn)) {
        return false;
      }
      isbn = toEAN13(isbn);
    }
    return isValidEAN13(isbn);
  }

  public boolean isValidEAN13(String ean13) {
    if (ean13 == null || ean13.length() != 13 || !isValidPatternEAN13(ean13)) {
      return false;
    }

    return (sumEAN13(ean13) % 10) == 0;
  }

  private int sumISBN10(String isbn) {
    int total = 0;
    for (int i = 0; i &lt; 9; i++) {
      int weight = 10 - i;
      total += (weight * toInt(isbn.charAt(i)));
    }
    total += toInt(isbn.charAt(9)); // add check digit
    return total;
  }

  private int sumEAN13(String isbn) {
    int total = isbn.charAt(0);
    for (int i = 1; i &lt; 13;) {
      total += (3 * isbn.charAt(i++)) + isbn.charAt(i++);
    }

    return total;
  }

  private String cleanISBN10(String isbn) {
    StringBuffer buf = new StringBuffer(10);

    for (int i = 0; i &lt; isbn.length(); i++) {
      char digit = isbn.charAt(i);
      if (Character.isDigit(digit) || (digit == &#39;X&#39;)) {
        buf.append(digit);
      }
    }

    return buf.toString();
  }

  private String toEAN13(String isbn) {
    StringBuffer buf = new StringBuffer(13);

    for (int i = 0; i &lt; isbn.length(); i++) {
      char digit = isbn.charAt(i);
      if (Character.isDigit(digit)) {
        buf.append(digit);
      }
    }

    return buf.toString();
  }

  private int toInt(char ch) {
    return (ch == &#39;X&#39;) ? 10 : Character.getNumericValue(ch);
  }

  private boolean isFormatted(String isbn) {
    return ((isbn.indexOf(&#39;-&#39;) != -1) || (isbn.indexOf(&#39; &#39;) != -1));
  }


  private boolean isValidPatternISBN10(String isbn) {
    return new Perl5Util().match(ISBN10_PATTERN, isbn);
  }

  private boolean isValidPatternISBN13(String isbn) {
    return new Perl5Util().match(ISBN13_PATTERN, isbn);
  }


  private boolean isValidPatternEAN13(String isbn) {
    return new Perl5Util().match(EAN13_PATTERN, isbn);
  }

}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bajishaik.blogspot.com/feeds/1715697744612619956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bajishaik.blogspot.com/2011/01/isbn-validation-in-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/1715697744612619956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/1715697744612619956'/><link rel='alternate' type='text/html' href='http://bajishaik.blogspot.com/2011/01/isbn-validation-in-java.html' title='ISBN validation In Java'/><author><name>Baji Shaik</name><uri>http://www.blogger.com/profile/04991693737624125341</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6505330232874994379.post-7095741861277744986</id><published>2011-01-13T00:25:00.000-08:00</published><updated>2011-01-13T00:25:28.618-08:00</updated><title type='text'>ISBN-10 to ISBN-13 Conversion in Java</title><content type='html'>&lt;pre&gt;public class ISBNConvertor {

  private static String CheckDigits = new String(&quot;0123456789X0&quot;);

  ///////////////////////////////// Main /////////////////////
  public static void main(String[] args) {
    String ISBN = new String();
    if (args.length==1) {
      ISBN = args[0];
      if (ISBN.length()==10) 
                System.out.println(ISBN1013(ISBN));
      else if (ISBN.length()==13) 
                 System.out.println(ISBN1310(ISBN));
      else ISBN = &quot;Invalid ISBN&quot;;
    }
  }

  /////////////// Change a character to its integer value ///////
  static int CharToInt(char a) {
    switch (a) {
      case &#39;0&#39;:   return 0;
      case &#39;1&#39;:   return 1;  
      case &#39;2&#39;:   return 2;
      case &#39;3&#39;:   return 3;  
      case &#39;4&#39;:   return 4;
      case &#39;5&#39;:   return 5;
      case &#39;6&#39;:   return 6;
      case &#39;7&#39;:   return 7;
      case &#39;8&#39;:   return 8;
      case &#39;9&#39;:   return 9;
      default:    return -1;
    }
  }

  ////////////////////// Convert ISBN-13 to ISBN-10 //////
  public static String ISBN1310(String ISBN) {
    String s9;
    int i, n, v;
    boolean ErrorOccurred;
    ErrorOccurred = false;
    s9 = ISBN.substring(3, 12);
    n = 0;
    for (i=0; i&lt;9; i++) {
      if (!ErrorOccurred) {
        v = CharToInt(s9.charAt(i));
        if (v==-1) ErrorOccurred = true;
        else n = n + (10 - i) * v; 
      }
    }
    if (ErrorOccurred) return &quot;ERROR&quot;;
    else {
      n = 11 - (n % 11);
      return s9 + CheckDigits.substring(n, n+1); 
    }
  }

  ////////////////////// Convert ISBN-10 to ISBN-13 //////
  public static String ISBN1013(String ISBN) {
    String s12;
    int i, n, v;
    boolean ErrorOccurred;
    ErrorOccurred = false;
    s12 = &quot;978&quot; + ISBN.substring(0, 9);
    n = 0;
    for (i=0; i&lt;12; i++) {
      if (!ErrorOccurred) {
        v = CharToInt(s12.charAt(i));
        if (v==-1) ErrorOccurred = true;
        else {
          if ((i % 2)==0) n = n + v;
          else n = n + 3*v;
        }
      }
    }
    if (ErrorOccurred) return &quot;ERROR&quot;;
    else {
      n = n % 10;
      if (n!=0) n = 10 - n;
      return s12 + CheckDigits.substring(n, n+1);
    }
  }
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bajishaik.blogspot.com/feeds/7095741861277744986/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bajishaik.blogspot.com/2011/01/isbn-10-to-isbn-13-conversion-in-java.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/7095741861277744986'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/7095741861277744986'/><link rel='alternate' type='text/html' href='http://bajishaik.blogspot.com/2011/01/isbn-10-to-isbn-13-conversion-in-java.html' title='ISBN-10 to ISBN-13 Conversion in Java'/><author><name>Baji Shaik</name><uri>http://www.blogger.com/profile/04991693737624125341</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6505330232874994379.post-5473482858262142153</id><published>2011-01-07T06:02:00.000-08:00</published><updated>2011-01-08T05:51:13.030-08:00</updated><title type='text'>How to replace Doctype of xml using sax ?</title><content type='html'>Using SAX Entity Resolver you can change the DOCTYPE of xml .&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Example :&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;String OnixFile=onixfilename; 
   
XMLReader readers = XMLReaderFactory.createXMLReader();
   
readers.setContentHandler(this);
readers.setErrorHandler(this);

readers.setEntityResolver(new Resolver()); 
FileReader filereader=new FileReader(OnixFile);
InputSource is=new InputSource(filereader);
is.setEncoding(&quot;UTF-8&quot;);
readers.parse(is);


class Resolver implements EntityResolver{

@Override
public InputSource resolveEntity(String publicId,String systemId)
   throws SAXException, IOException {
  if(systemId.equalsIgnoreCase(
    &quot;http://www.editeur.org/onix/2.1/short
                     /onix-international.dtd&quot;)){

   String path=&quot;/ONIX 2.1 Revision 03 
                        reference/onix-international.dtd&quot;;
       return new InputSource(path);
 }
  return null;
 }
 
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bajishaik.blogspot.com/feeds/5473482858262142153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bajishaik.blogspot.com/2011/01/how-to-replace-doctype-of-xml-using-sax.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/5473482858262142153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/5473482858262142153'/><link rel='alternate' type='text/html' href='http://bajishaik.blogspot.com/2011/01/how-to-replace-doctype-of-xml-using-sax.html' title='How to replace Doctype of xml using sax ?'/><author><name>Baji Shaik</name><uri>http://www.blogger.com/profile/04991693737624125341</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6505330232874994379.post-5187766028473342255</id><published>2011-01-07T05:39:00.000-08:00</published><updated>2011-01-07T05:42:50.193-08:00</updated><title type='text'>How to get currently executing jobs In Quartz Schedular ?</title><content type='html'>&lt;font color=&quot;red&quot;&gt;&lt;b&gt;Example:&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.quartz.impl.StdSchedulerFactory;

Scheduler sch=new StdSchedulerFactory().getScheduler();
List jobsList=sch.getCurrentlyExecutingJobs();
Iterator jobsIterator=jobsList.listIterator();

while(jobsIterator.hasNext()){
 JobExecutionContext context = 
                 (JobExecutionContext) jobsIterator.next();
 System.out.println(context.getJobDetail().getName());
}
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bajishaik.blogspot.com/feeds/5187766028473342255/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bajishaik.blogspot.com/2011/01/how-to-get-currently-executing-jobs-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/5187766028473342255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/5187766028473342255'/><link rel='alternate' type='text/html' href='http://bajishaik.blogspot.com/2011/01/how-to-get-currently-executing-jobs-in.html' title='How to get currently executing jobs In Quartz Schedular ?'/><author><name>Baji Shaik</name><uri>http://www.blogger.com/profile/04991693737624125341</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6505330232874994379.post-3503364255487090411</id><published>2010-10-12T07:46:00.000-07:00</published><updated>2010-11-22T02:40:54.166-08:00</updated><title type='text'>Read CSV File Using Regular Expressions in Java</title><content type='html'>&lt;font color=&quot;red&quot;&gt;&lt;b&gt;Example 2:&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font color=&quot;green&quot;&gt;&lt;b&gt;Reading CSV File and Storing it in Database with Regular Expressions&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font color=&quot;blue&quot;&gt;&lt;b&gt;Step 1:&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;File CsvFile =new File(&quot;File Path&quot;);
FileReader inpFile = new FileReader(CsvFile);
BufferedReader inpReader = new BufferedReader(inpFile);

String inpLine;
&lt;/pre&gt;&lt;pre&gt;&lt;font color=&quot;blue&quot;&gt;&lt;b&gt;Step 2:&lt;/b&gt;&lt;/font&gt;

//Reading Line By Line
while ((inpLine = inpReader.readLine()) != null)
{
  List&lt;string&gt; result = &lt;b&gt;parseCSV(inpLine, &quot;,&quot;);&lt;/b&gt;
  String Fields[] = (String[]) result.toArray(new String[0]);
  &lt;b&gt;DoInsertIntoDB(Feilds);&lt;/b&gt;
}
&lt;/pre&gt;&lt;pre&gt;&lt;font color=&quot;blue&quot;&gt;&lt;b&gt;Step 3:&lt;/b&gt;&lt;/font&gt;

//Using Regular Expression
public List&lt;string&gt; parseCSV(String csv, String delim)
{
  final Pattern NEXT_COLUMN = &lt;b&gt;nextColumnRegex(delim);&lt;/b&gt;
  final List&lt;string&gt; strings = new ArrayList&lt;string&gt;();
  final Matcher matcher = NEXT_COLUMN.matcher(csv);
  while (!matcher.hitEnd() &amp;&amp; matcher.find()) 
  {
    String match = matcher.group(1);
    if (match.matches(quoted)) 
    {
      match = match.substring(1, match.length() - 1);
    }
    match = match.replaceAll(&quot;\&quot;\&quot;&quot;, &quot;\&quot;&quot;);
    strings.add(match);
  }
return strings;
}
&lt;/pre&gt;&lt;pre&gt;private Pattern nextColumnRegex(String comma) 
{
  String unquoted = &quot;(:?[^\&quot;&quot; + comma + &quot;]|\&quot;\&quot;)*&quot;;
  String ending = &quot;(:?&quot; + comma + &quot;|$)&quot;;
return Pattern.compile(&#39;(&#39; + quoted + &#39;|&#39; + unquoted + &#39;)&#39;
                                               + ending);
}
&lt;/pre&gt;&lt;pre&gt;&lt;font color=&quot;blue&quot;&gt;&lt;b&gt;Step 4:&lt;/b&gt;&lt;/font&gt;

//Inserting Into Database
public void DoInsertIntoDB(String[] inpFeilds)
{
  String Query=&quot;insert into emp(id,name)values(?,?)&quot;;
  PreparedStatement InsST=connetion.prepareStatement(Query);
  for (int i = 0; i &lt; inpFeilds.length; i++)
  {
    inpFeilds[i] = inpFeilds[i].replace(&quot;\&quot;&quot;, &quot;&quot;);
  }

  InsST.setString(1, inpFeilds[0]);
  InsST.setString(1, inpFeilds[2]);
  InsST.executeUpdate();
}

&lt;/pre&gt;
&lt;pre&gt;//This is what you need to do when 
                 reading .csv file.&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bajishaik.blogspot.com/feeds/3503364255487090411/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bajishaik.blogspot.com/2010/10/reading-csv-file-and-storing-it-in_12.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/3503364255487090411'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/3503364255487090411'/><link rel='alternate' type='text/html' href='http://bajishaik.blogspot.com/2010/10/reading-csv-file-and-storing-it-in_12.html' title='Read CSV File Using Regular Expressions in Java'/><author><name>Baji Shaik</name><uri>http://www.blogger.com/profile/04991693737624125341</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6505330232874994379.post-8923131985132549760</id><published>2010-10-12T07:26:00.000-07:00</published><updated>2010-11-22T02:41:17.722-08:00</updated><title type='text'>Reading CSV File using StringTokenizer</title><content type='html'>&lt;b&gt;There are two ways to read a .csv file and store it in the database.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
1)Reading the file line by line and split that line using &lt;br /&gt;
StringTokenizer and insert  into database.&lt;br /&gt;
&lt;br /&gt;
2)using regular expressions in Java .&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;font color=&quot;red&quot;&gt;&lt;b&gt;Example 1:&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font color=&quot;blue&quot;&gt;&lt;b&gt;Step 1:&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;
&lt;pre&gt;File CsvFile =new File(&quot;File Path&quot;);
FileReader inpFile = new FileReader(CsvFile);
BufferedReader inpReader = new BufferedReader(inpFile);
String inpLine; 
&lt;/pre&gt;&lt;br /&gt;
&lt;font color=&quot;blue&quot;&gt;&lt;b&gt;Step 2:&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;
&lt;pre&gt;//Reading file line by line
while ((inpLine = inpReader.readLine()) != null) 
{
  String[] Feilds = inpLine.split(&quot;,\\s*&quot;); //Specify delimiter
  DoInsertIntoDB(Feilds); //Calling method to insert in Database
}
&lt;/pre&gt;&lt;br /&gt;
&lt;font color=&quot;blue&quot;&gt;&lt;b&gt;Step 3:&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;
&lt;pre&gt;//Inserting In Database
public void DoInsertIntoDB(String[] inpFeilds)
{
  String Query=&quot;insert into emp(id,name)values(?,?)&quot;;  
  PreparedStatement InsST=connection.prepareStatement(Query);
  for (int i = 0; i &lt; inpFeilds.length; i++) 
  {
     inpFeilds[i] = inpFeilds[i].replace(&quot;\&quot;&quot;, &quot;&quot;);
  }
  InsST.setString(1, inpFeilds[0]);
  InsST.setString(1, inpFeilds[2]);
  InsST.executeUpdate();
}

&lt;/pre&gt;
&lt;font color=&quot;green&quot;&gt;&lt;b&gt;Explanation:&lt;/b&gt;&lt;/font&gt;
&lt;pre&gt;In this example i have read the csv file line by line and 
     split the line using StringTokenizer
  In StringTokenizer i have specified , as my delimeter.
      so you can specify whatever delimiter you want.
&lt;/pre&gt;&lt;font color=&quot;green&quot;&gt;&lt;b&gt;Disadvantages:&lt;/b&gt;&lt;/font&gt;
&lt;pre&gt;1) If the data in the csv file like &quot;author1,author2&quot; 
     then the above example will read the line and split it 
       into two strings and inserts it into two different columns.
         but you need these full string to be in single column.
           so you can achieve this using regular expression.

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://bajishaik.blogspot.com/feeds/8923131985132549760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bajishaik.blogspot.com/2010/10/reading-csv-file-and-storing-it-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/8923131985132549760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6505330232874994379/posts/default/8923131985132549760'/><link rel='alternate' type='text/html' href='http://bajishaik.blogspot.com/2010/10/reading-csv-file-and-storing-it-in.html' title='Reading CSV File using StringTokenizer'/><author><name>Baji Shaik</name><uri>http://www.blogger.com/profile/04991693737624125341</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>