package com.solidcore.as.report; import java.io.FileOutputStream; import java.io.InputStream; import com.crystaldecisions.reports.sdk.PrintOutputController; import com.crystaldecisions.reports.sdk.ReportClientDocument; import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat; public class TestReport { private static String REPORT_NAME_CHANGE_COMPLIANCE_withData = "F:\\JavaProjectes\\ReportTesting\\WithData\\pciexpress.rpt"; public static void main(String[] args) throws Exception { Thread t1 = new Thread(new RunReport()); Thread t2 = new Thread(new RunReport()); Thread t3 = new Thread(new RunReport()); Thread t4 = new Thread(new RunReport()); Thread t5 = new Thread(new RunReport()); Thread t6 = new Thread(new RunReport()); Thread t7 = new Thread(new RunReport()); Thread t8 = new Thread(new RunReport()); Thread t9 = new Thread(new RunReport()); Thread t10 = new Thread(new RunReport()); t1.start(); t2.start(); t3.start(); t4.start(); t5.start(); t6.start(); t7.start(); t8.start(); t9.start(); t10.start(); } private static class RunReport implements Runnable { public void run() { TestReport test = new TestReport(); try { test.testPCIExpress(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } private void testPCIExpress() throws Exception { FileOutputStream outputStream = null; ReportClientDocument reportClientDoc = null; InputStream is = null; try { System.out.println("report testing"); reportClientDoc = new ReportClientDocument(); System.out.println("create the client document"); reportClientDoc.open(REPORT_NAME_CHANGE_COMPLIANCE_withData, 0); System.out.println("opend the reoprt"); PrintOutputController outputcontroller = reportClientDoc.getPrintOutputController(); is = outputcontroller.export(ReportExportFormat.PDF); System.out.println("get the input stream from report output controller"); long timeInMillis = System.currentTimeMillis(); outputStream = new FileOutputStream("F:\\JavaProjectes\\ReportTesting\\pciexpress" + timeInMillis + (Math.random() * 10)+ ".pdf"); byte[] bt = new byte[1024]; int i = 0; while((i = is.read(bt)) != -1) { outputStream.write(bt, 0 , i); outputStream.flush(); } System.out.println("write into the files"); } catch (Exception e) { e.printStackTrace(); } finally { if (reportClientDoc != null && reportClientDoc.isOpen()) { reportClientDoc.close(); } if (outputStream != null) { outputStream.close(); } if (is != null) { is.close(); } } System.out.println("close the streams"); } }