Example usage for java.lang Exception printStackTrace

List of usage examples for java.lang Exception printStackTrace

Introduction

In this page you can find the example usage for java.lang Exception printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:AddWatermarkImageToAnExistingPDFFile.java

public static void main(String[] args) {
    try {//from w w  w  .  j  a va2s.c  o m
        PdfReader reader = new PdfReader("YourOwnPDF.pdf");
        int n = reader.getNumberOfPages();
        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("NewPDFWithWatermarkImage.pdf"));
        int i = 0;
        PdfContentByte under;
        Image img = Image.getInstance("logo.png");
        img.setAbsolutePosition(200, 400);
        while (i < n) {
            i++;
            under = stamp.getUnderContent(i);
            under.addImage(img);
        }
        stamp.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    try {/*from  w  ww .  j a v a2 s. co  m*/
        Class c = Class.forName("java.util.ArrayList");

        Constructor constructors[] = c.getConstructors();
        for (int i = 0; i < constructors.length; i++) {
            System.out.print(constructors[i].getName() + ": ");
            Class parameters[];
            parameters = constructors[i].getParameterTypes();
            for (int j = 0; j < parameters.length; j++) {
                String s = parameters[j].getName();
                s = s.substring(s.lastIndexOf(".") + 1, s.length());
                System.out.print(s + " ");
            }
            System.out.println("");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:AddExtraPageToExistingPDF.java

public static void main(String[] args) {
    try {/*from   www  .  j a  v a2  s.  com*/
        PdfReader reader = new PdfReader("YourOwnPDF.pdf");
        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("AddExtraPageToExistingPDF.pdf"));

        PdfContentByte over;
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);

        stamp.insertPage(1, PageSize.A4);
        over = stamp.getOverContent(1);
        over.beginText();
        over.setFontAndSize(bf, 18);
        over.showTextAligned(Element.ALIGN_LEFT, "DUPLICATE OF AN EXISTING PDF DOCUMENT", 30, 600, 0);
        over.endText();

        stamp.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:TableSpacingAfterPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {/* w  ww  .j a v a  2s .c om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TableSpacingAfterPDF.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(3);
        PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
        cell.setColspan(3);
        table.addCell(cell);

        table.setSpacingAfter(150f);
        document.add(table);
        document.add(table);
        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:MainClass.java

public static void main(String args[]) {

    try {/*ww  w. j  a  va  2 s  . c o  m*/

        RandomAccessFile raf = new RandomAccessFile(args[0], "r");

        long position = raf.length();

        while (position > 0) {

            position -= 1;

            raf.seek(position);
            byte b = raf.readByte();

            System.out.print((char) b);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:FourColumnTablePDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {//w ww  . ja  va 2  s  .c o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("FourColumnTablePDF.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(4);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(new Phrase(new Chunk("First Page")));
        table.addCell(new Phrase(new Chunk("Prev Page")));
        table.addCell(new Phrase(new Chunk("Next Page")));
        table.addCell(new Phrase(new Chunk("Last Page")));

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:Barcodes39Ext.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {/*from   w ww  .  j  av a 2  s  .  co  m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Barcodes39Ext.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        Barcode39 code39 = new Barcode39();
        code39.setCode("www.java2s.com");
        code39.setStartStopText(false);
        code39.setExtended(true);
        Image image39 = code39.createImageWithBarcode(cb, null, null);

        document.add(new Phrase(new Chunk(image39, 0, 0)));
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:Main.java

public static void main(String[] args) {
    byte[] arrByte = new byte[1024];
    byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' };

    InputStream is = new ByteArrayInputStream(byteArray);
    PushbackInputStream pis = new PushbackInputStream(is, 10);
    try {/*from   w ww .  j  av  a  2 s.  c  om*/
        for (int i = 0; i < byteArray.length; i++) {
            arrByte[i] = (byte) pis.read();
            System.out.println((char) arrByte[i]);
        }
        byte[] b = { 'W', 'o', 'r', 'l', 'd' };

        pis.unread(b, 2, 3);

        for (int i = 0; i < 3; i++) {
            arrByte[i] = (byte) pis.read();
            System.out.println((char) arrByte[i]);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    try {/* ww w.  j  av  a2 s.  co m*/
        DatabaseMetaData dbmd = conn.getMetaData();
        if (dbmd == null) {
            System.out.println("No");
        }
        if (dbmd.supportsStatementPooling()) {
            System.out.println("statement pooling is supported");
        } else {
            System.out.println("No");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        conn.close();
    }
}

From source file:SerializationUtilsTrial.java

public static void main(String[] args) {
    try {/*from w  w  w  .  ja va 2s .co  m*/
        // File to serialize object to
        String fileName = "testSerialization.ser";

        // New file output stream for the file
        FileOutputStream fos = new FileOutputStream(fileName);

        // Serialize String
        SerializationUtils.serialize("SERIALIZE THIS", fos);
        fos.close();

        // Open FileInputStream to the file
        FileInputStream fis = new FileInputStream(fileName);

        // Deserialize and cast into String
        String ser = (String) SerializationUtils.deserialize(fis);
        System.out.println(ser);
        fis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}