StreamResource generating Jasper Report

final HashMap param = new HashMap();

		System.out.println("No vairable is set");
		StreamResource.StreamSource source;
		System.out.println("Setting resourse null");
		source = null;
		source = new StreamResource.StreamSource() {

			public InputStream getStream() {
				byte[] b = null;
				try {
					System.out.println("Found Input Streammmmmmmm");
					 b = JasperRunManager.runReportToPdf(getClass().getClassLoader().getResourceAsStream("invoice.jasper"), param, conn);
					 System.out.println("returning from b"); 						
				} catch (JRException ex) {
				return new ByteArrayInputStream(b);
		// Finally, creating a com.vaadin.terminal.StreamResource object and
		// opening the pdf in a new browser window.

		StreamResource resource = new StreamResource(source, "invoice.pdf",
		getApplication().getMainWindow().open(resource, "_new");
		// getMainWindow().open(resource, "_new");

	} catch (Exception e) {

sometime the reports comes out fine and most of the times it skips the Found Input Streammmmmmmm print and that time it does not come ok it come up with some wrong output what is the problem i am new to vaadin please help

what is getApplication() in StreamResource resource = new StreamResource(source, “invoice.pdf”,

how to we get the .pdf file from the .jrxml file

probably, should be caching the pdf, try not to cache:
resource.setCacheTime (0);