Friday 21 June 2013

Hibernate criteria MatchMode ANYWHERE

0 comments
The MatchMode.ANYWHERE match the pattern anywhere in the string.

criteria.add(Restrictions.like("videotags", "pattern", MatchMode.ANYWHERE));


Hibernate Criteria API (Disjunction and Conjunction)

0 comments

Criteria rootCriteria = createCriteria(entityClass);
    rootCriteria.add(Restrictions.or(
            Restrictions.eq("a","a"),
            Restrictions.and(
                    Restrictions.eq("b","b"),
                    Restrictions.eq("c","c")
            )
    ));

Tuesday 18 June 2013

Contact Us

0 comments
Contacting us

please contact us at:
Spring Java Tutorials
http://springjavatutorial.blogspot.in/

+91 9540040587
haritkumarblog@gmail.com
skype : haritrajput

Privacy Policy

0 comments
This Privacy Policy governs the manner in which Spring Java Tutorials collects, uses, maintains and discloses information collected from users (each, a "User") of the http://springjavatutorial.blogspot.in/ website ("Site"). This privacy policy applies to the Site and all products and services offered by Spring Java Tutorials.

Personal identification information

We may collect personal identification information from Users in a variety of ways, including, but not limited to, when Users visit our site, subscribe to the newsletter, and in connection with other activities, services, features or resources we make available on our Site. Users may be asked for, as appropriate, email address. Users may, however, visit our Site anonymously. We will collect personal identification information from Users only if they voluntarily submit such information to us. Users can always refuse to supply personally identification information, except that it may prevent them from engaging in certain Site related activities.

Non-personal identification information

We may collect non-personal identification information about Users whenever they interact with our Site. Non-personal identification information may include the browser name, the type of computer and technical information about Users means of connection to our Site, such as the operating system and the Internet service providers utilized and other similar information.

Web browser cookies

Our Site may use "cookies" to enhance User experience. User's web browser places cookies on their hard drive for record-keeping purposes and sometimes to track information about them. User may choose to set their web browser to refuse cookies, or to alert you when cookies are being sent. If they do so, note that some parts of the Site may not function properly.

How we use collected information

Spring Java Tutorials may collect and use Users personal information for the following purposes:

- To improve customer service
Information you provide helps us respond to your customer service requests and support needs more efficiently.
- To send periodic emails
We may use the email address to send them information and updates pertaining to their order.

How we protect your information

We adopt appropriate data collection, storage and processing practices and security measures to protect against unauthorized access, alteration, disclosure or destruction of your personal information, username, password, transaction information and data stored on our Site.

Our Site is in compliance with PCI vulnerability standards in order to create as secure of an environment as possible for Users.

Sharing your personal information

We do not sell, trade, or rent Users personal identification information to others. We may share generic aggregated demographic information not linked to any personal identification information regarding visitors and users with our business partners, trusted affiliates and advertisers for the purposes outlined above.

Google Adsense

Some of the ads may be served by Google. Google's use of the DART cookie enables it to serve ads to Users based on their visit to our Site and other sites on the Internet. DART uses "non personally identifiable information" and does NOT track personal information about you, such as your name, email address, physical address, etc. You may opt out of the use of the DART cookie by visiting the Google ad and content network privacy policy at http://www.google.com/privacy_ads.html

Changes to this privacy policy

Spring Java Tutorials has the discretion to update this privacy policy at any time. When we do, we will post a notification on the main page of our Site. We encourage Users to frequently check this page for any changes to stay informed about how we are helping to protect the personal information we collect. You acknowledge and agree that it is your responsibility to review this privacy policy periodically and become aware of modifications.

Your acceptance of these terms

By using this Site, you signify your acceptance of this policy and terms of service. If you do not agree to this policy, please do not use our Site. Your continued use of the Site following the posting of changes to this policy will be deemed your acceptance of those changes.

Contacting us

If you have any questions about this Privacy Policy, the practices of this site, or your dealings with this site, please contact us at:
Spring Java Tutorials
http://springjavatutorial.blogspot.in/
+91 9540040587
haritkumarblog@gmail.com

This document was last updated on June 18, 2013


Xuggler Video Conversion .mov to .mp4

2 comments
Jars Required
1. commons-cli-1.1
2. logback-classic-1.0.0
3. logback-core-1.0.0
4. slf4j-api-1.6.4
5. xuggle-xuggler-5.4



TranscodingExample.java
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;

public class TranscodingExample {

 private static final String inputFilename ="/home/harry/Portrait.MOV";
 private static final String outputFilename ="/home/harry/sample.mp4";

 public static void main(String[] args) {

  Long st = System.currentTimeMillis();
  
  // create a media reader
  IMediaReader mediaReader = ToolFactory.makeReader(inputFilename);
  
  // create a media writer
  IMediaWriter mediaWriter = ToolFactory.makeWriter(outputFilename, mediaReader);

  // add a writer to the reader, to create the output file
  mediaReader.addListener(mediaWriter);
  
  // create a media viewer with stats enabled
  IMediaViewer mediaViewer = ToolFactory.makeViewer(true);
  
  // add a viewer to the reader, to see the decoded media
  mediaReader.addListener(mediaViewer);

  // read and decode packets from the source file and
  // and dispatch decoded audio and video to the writer
  while (mediaReader.readPacket() == null) ;
  
  Long end = System.currentTimeMillis();
  System.out.println("Time Taken In Milli Seconds: "+ (end-st));

 }

}



Download Working Project Here
Download

Friday 14 June 2013

Find Mime Type Of a file in java

0 comments
import java.io.File;

import javax.activation.MimetypesFileTypeMap;


public class TestMimeType {
public static void main(String[] args) {
 String fileName = "C://bunny.mp4";
 MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();

 // only by file name
 String mimeType = mimeTypesMap.getContentType(fileName);

 // or by actual File instance
 File file = new File(fileName);
 mimeType = mimeTypesMap.getContentType(file);
 
 System.out.println(mimeType);
}
}


Monday 10 June 2013

Creating PDF with Java and iText, Generating PDF Using Java

1 comments
    Inserting Image in PDF
    Inserting Table in PDF
    Inserting List in PDF
    Text formatting in PDF
    Adding new Pages in PDF
    Little Chunk

But before you start this application you must download iTextpdf related jar(s).
package pdf;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;
 
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Image;
import com.itextpdf.text.List;
import com.itextpdf.text.ListItem;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
 
public class PdfGen {
 
    public static void main(String[] args) {
 
        try {
 
              OutputStream file = new FileOutputStream(new File("C:\\custom.pdf"));
              Document document = new Document();
              PdfWriter.getInstance(document, file);
 
            //Inserting Image in PDF
                 Image image = Image.getInstance ("src/pdf/custom.png");
                 image.scaleAbsolute(120f, 60f);//image width,height   
 
            //Inserting Table in PDF
                 PdfPTable table=new PdfPTable(3);
 
                         PdfPCell cell = new PdfPCell (new Paragraph ("Ja.com"));
 
                      cell.setColspan (3);
                      cell.setHorizontalAlignment (Element.ALIGN_CENTER);
                      cell.setPadding (10.0f);
                      cell.setBackgroundColor (new BaseColor (140, 221, 8));                                  
 
                      table.addCell(cell);                                    
 
                      table.addCell("Name");
                      table.addCell("Address");
                      table.addCell("Country");
                      table.addCell("Java");
                      table.addCell("NC");
                      table.addCell("United States");
                      table.setSpacingBefore(30.0f);       // Space Before table starts, like margin-top in CSS
                      table.setSpacingAfter(30.0f);        // Space After table starts, like margin-Bottom in CSS                                        
 
             //Inserting List in PDF
                      List list=new List(true,30);
                      list.add(new ListItem("Java"));
                      list.add(new ListItem("Php"));
                      list.add(new ListItem("Somn..."));     
 
             //Text formating in PDF
                    Chunk chunk=new Chunk("Welecome To Spring Blog...");
                    chunk.setUnderline(+1f,-2f);//1st co-ordinate is for line width,2nd is space between
                    Chunk chunk1=new Chunk("Phps.com");
                    chunk1.setUnderline(+4f,-8f);
                    chunk1.setBackground(new BaseColor (17, 46, 193));     
 
             //Now Insert Every Thing Into PDF Document
                 document.open();//PDF document opened........                
 
                    document.add(image);
 
                    document.add(Chunk.NEWLINE);   
 
                    document.add(new Paragraph("Dear spring.com"));
                    document.add(new Paragraph("Document Generated On - "+new Date().toString())); 
 
                    document.add(table);
 
                    document.add(chunk);
                    document.add(chunk1);
 
                    document.add(Chunk.NEWLINE);                            
 
                    document.newPage();            //Opened new page
                    document.add(list);            //In the new page we are going to add list
 
                 document.close();
 
                         file.close();
 
            System.out.println("Pdf created successfully..");
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Friday 7 June 2013

Integrate JW Player With Amazon Cloud Front

0 comments
Always Run this File After Deploying on server
















Potrait

Loading the player ...

Wednesday 5 June 2013

Spring 3 - Task Scheduling

0 comments
In this tutorial we will explore Spring 3's task scheduling support using annotations. We will be using @Scheduled and @Async annotations. Spring also provides scheduling support using the Quartz Scheduler, and via XML configuration . We will build our application on top of a simple Spring MVC 3 application. Although MVC is not required, I would like to show how easy it is to integrate.

@Scheduled Annotation
@Scheduled annotation  add to a method along with trigger metadata.

To enable this annotation we need to add the annotation-driven element:

You also need to add the component-scan element. We didn't enable it here since it's already added in the applicationContext.xml .

 
 
 
 
 
 
 
 
  
 
 
 
 



spring-scheduler

 
 

 
 
 
 
 
 
  
 
  
                
                

Worker

SyncWorker

This worker is synchronous which means if we have to call this worker 10 times, it will block the other workers. They cannot start immediately until the first one is finished. We didn't do anything to make this implementation synchronous. It's the default.

The class that calls this SyncWorker is a scheduler service.
Notice the @Scheduled annotation in the doSchedule() method. This tells Spring to mark this method for task scheduling. Inside the @Scheduled, there's a metadata that describes when the method should be triggered. The following metadata all have the same value (5 seconds) but they are interpreted differently:

fixedDelay=5000
fixedRate=5000
cron="*/5 * * * * ?"

fixedDelay: An interval-based trigger where the interval is measured from the completion time of the previous task. fixedRate: An interval-based trigger where the interval is measured from the start time of the previous task. cron: A cron-based trigger Running the application gives us the following logs:
Notice how the tasks are run sequentially every 5 seconds.

What if we want to run the workers asynchronously, meaning we don't want to wait for worker 1 to finish before we start worker 2, or worker 3, and so forth? There are valid reasons like efficient use of physical resources and time.

To make a worker asychronous, we add the @Async annotation in the method that needs to be asychronous.

The @Async Annotation

    The @Async annotation can be provided on a method so that invocation of that method will occur asynchronously. In other words, the caller will return immediately upon invocation and the actual execution of the method will occur in a task that has been submitted to a Spring TaskExecutor.

    Source: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html

To enable this annotation we use the same annotation-driven element.

Let's examine an actual example. We'll create a new class AsyncWorker that implements the Worker interface earlier.

AsyncWorker

This worker is asychronous. The caller (the scheduler service) will return immediately upon invocation.

The class that calls this AsyncWorker is the same scheduler service we had earlier. We
just need to change the value of @Qualifier Use Of @Scheduled Annotation
//@Scheduled(fixedDelay=5000)
 //@Scheduled(fixedRate=5000)
 @Scheduled(cron="*/5 * * * * ?")
 public void doSchedule() {
  logger.debug("Start schedule");
  
  for (int i = 0; i < 5; i++) {
   logger.debug("Delegate to worker " + i);
   worker.work();
        }
  
  logger.debug("End schedule");
 }
Related Posts Plugin for WordPress, Blogger...