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:ViewerPreferencesDisplayDocTitle.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A6);
    try {//from   ww w .java2  s .  c o  m
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("ViewerPreferencesDisplayDocTitle.pdf"));

        writer.setViewerPreferences(PdfWriter.DisplayDocTitle);
        document.addTitle("This is the title.");
        document.open();

        document.add(new Paragraph(
                "text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text ",
                new Font(Font.HELVETICA, 12)));
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:Main.java

public static void main(String s[]) throws Exception {
    try {//from  w ww  .j  a va2  s  .c  o m
        Properties systemSettings = System.getProperties();
        systemSettings.put("proxySet", "true");
        systemSettings.put("http.proxyHost", "proxy.mycompany.local");
        systemSettings.put("http.proxyPort", "80");

        URL u = new URL("http://www.java.com");
        HttpURLConnection con = (HttpURLConnection) u.openConnection();
        sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
        String encodedUserPwd = encoder.encode("domain\\username:password".getBytes());
        con.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd);
        con.setRequestMethod("HEAD");
        System.out.println(con.getResponseCode() + " : " + con.getResponseMessage());
        System.out.println(con.getResponseCode() == HttpURLConnection.HTTP_OK);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(false);
    }
}

From source file:ViewerPreferencesHideMenubarHideToolbar.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A6);
    try {/* w w  w.j  ava 2  s . c o m*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("ViewerPreferencesHideMenubarHideToolbar.pdf"));

        writer.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideToolbar);
        document.addTitle("This is the title.");
        document.open();

        document.add(new Paragraph(
                "text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text ",
                new Font(Font.HELVETICA, 12)));
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:ViewerPreferencesPageLayoutTwoColumnLeft.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A6);
    try {/* ww  w  . j ava 2  s  . c o  m*/
        PdfWriter writer1 = PdfWriter.getInstance(document,
                new FileOutputStream("ViewerPreferencesPageLayoutTwoColumnLeft.pdf"));

        writer1.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);
        document.addTitle("This is the title.");
        document.open();

        document.add(new Paragraph(
                "text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text ",
                new Font(Font.HELVETICA, 12)));
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:Main.java

public static void main(String args[]) {
    try {//from w  w w.j a v a  2 s  .  co  m

        InetAddress ia = InetAddress.getByName("www.java2s.com");

        DatagramSocket ds = new DatagramSocket(8080, ia);

        byte buffer[] = "hello".getBytes();
        DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, 80);
        ds.connect(InetSocketAddress.createUnresolved("google.com", 8080));

        DatagramChannel channel = ds.getChannel();

        ds.send(dp);
        ds.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ViewerPreferencesPrintScalingNone.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A6);
    try {/*from ww w . jav a 2  s . co m*/
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("ViewerPreferencesPrintScalingNone.pdf"));

        writer.setViewerPreferences(PdfWriter.PrintScalingNone);
        document.addTitle("This is the title.");
        document.open();

        document.add(new Paragraph(
                "text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text ",
                new Font(Font.HELVETICA, 12)));
    } catch (Exception de) {
        de.printStackTrace();
    }
    document.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String dsn = args[0];/*from  w w  w  . j  a va  2s.  co m*/
    System.out.println("Attempting to connect to " + dsn);

    try {
        System.out.println("Initializing the naming context...");
        InitialContext init = new InitialContext();

        System.out.println("Looking up " + dsn);
        DataSource source = (DataSource) init.lookup(dsn);

        System.out.println("Establishing a connection...");
        Connection connection = source.getConnection();

        System.out.println("Connect to " + connection.getCatalog() + " a success!");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:SimpleAnnotationsWithHyperLinkPDF.java

public static void main(String[] args) {
    Document document1 = new Document(PageSize.A4, 10, 10, 10, 10);
    try {/*  w w w .  j a v  a2s .  c  om*/
        PdfWriter writer1 = PdfWriter.getInstance(document1,
                new FileOutputStream("SimpleAnnotationsWithHyperLinkPDF.pdf"));
        writer1.setPdfVersion(PdfWriter.VERSION_1_5);
        document1.open();

        Annotation a = new Annotation(250f, 550f, 350f, 650f, new URL("http://www.java2s.com"));

        document1.add(a);
    } catch (Exception de) {
        de.printStackTrace();
    }
    document1.close();
}

From source file:Barcodes39.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    try {// ww w.java  2s .c  om
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Barcodes39.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        Barcode39 code39 = new Barcode39();
        code39.setCode("CODE39-1234567890");
        code39.setStartStopText(false);
        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);

    try {//w ww . j a  v a2s .c o  m
        for (int i = 0; i < byteArray.length; i++) {

            arrByte[i] = (byte) pis.read();

            System.out.println((char) arrByte[i]);
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}