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

public static void main(String[] args) {

    String s = "from java2s.com!";

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

        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset());

        FileInputStream in = new FileInputStream("test.txt");

        writer.write(s, 0, 5);

        writer.flush();

        for (int i = 0; i < 5; i++) {
            System.out.print((char) in.read());
        }
        writer.close();
        in.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:CellFixedHeightPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {/*w w w .j a  v  a2s.com*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("CellFixedHeightPDF.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = new PdfPCell(new Paragraph(
                "Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text "));
        table.addCell("wrap");
        cell.setNoWrap(false);
        table.addCell(cell);
        table.addCell("no wrap");
        cell.setFixedHeight(50f);
        cell.setNoWrap(true);
        table.addCell(cell);

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

From source file:ExtendingLastRowPDF.java

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

        PdfPTable table = new PdfPTable(2);
        table.setExtendLastRow(true);
        PdfPCell cell = new PdfPCell(new Paragraph(
                "Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text "));
        table.addCell("wrap");
        cell.setNoWrap(false);
        table.addCell(cell);
        table.addCell("no wrap");
        cell.setNoWrap(true);
        table.addCell(cell);

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

From source file:CellHeightsWarpAndNoWrapPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {//from www  .j  av  a 2s. co  m
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("CellHeightsWarpAndNoWrapPDF.pdf"));
        document.open();

        PdfPTable table = new PdfPTable(2);
        PdfPCell cell = new PdfPCell(new Paragraph(
                "Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text "));
        table.addCell("wrap");
        cell.setNoWrap(false);
        table.addCell(cell);
        table.addCell("no wrap");
        cell.setNoWrap(true);
        table.addCell(cell);

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

From source file:PatternPatternColorPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from w  w  w. jav  a  2  s . c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PatternPatternColorPDF.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();

        PdfPatternPainter p = cb.createPattern(60f, 60f, 60f, 60f);
        p.setColorFill(Color.red);
        p.circle(2, 2, 2);
        p.stroke();

        cb.setPatternFill(p);
        cb.setGrayStroke(0.0f);
        cb.rectangle(20, 20, 280, 120);
        cb.fillStroke();

    } catch (Exception e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:InetAddressTest.java

public static void main(String[] args) {
    try {/*  w  w  w  .  j av a2  s . c om*/
        if (args.length > 0) {
            String host = args[0];
            InetAddress[] addresses = InetAddress.getAllByName(host);
            for (InetAddress a : addresses)
                System.out.println(a);
        } else {
            InetAddress localHostAddress = InetAddress.getLocalHost();
            System.out.println(localHostAddress);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:PatternColorPDF.java

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

        PdfContentByte cb = writer.getDirectContent();

        PdfPatternPainter pat = cb.createPattern(10, 10, null);
        pat.setLineWidth(2);
        pat.moveTo(0, -5);
        pat.lineTo(15, 10);
        pat.stroke();

        cb.setPatternFill(pat, Color.green);
        cb.rectangle(100, 400, 30, 210);
        cb.fillStroke();

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

From source file:MainClass.java

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

        // Get an address
        InetAddress ias[] = InetAddress.getAllByName("www.google.com");
        for (int i = 0; i < ias.length; i++) {
            System.out.println(ias[i].getHostName());
            System.out.println(ias[i].getHostAddress());
            byte bytes[] = ias[i].getAddress();
            for (int j = 0; j < bytes.length; j++) {
                if (j > 0)
                    System.out.print(".");
                if (bytes[j] >= 0)
                    System.out.print(bytes[j]);
                else
                    System.out.print(bytes[j] + 256);
            }
            System.out.println("");
        }

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

From source file:com.titan.main.Invoker.java

public static void main(String... args) {
    try {/*  www. j  a va2 s  .  c om*/
        NotificationsFactory factory = new NotificationsFactory();

        ObjectMapper mapper = new ObjectMapper();
        mapper.addMixInAnnotations(Notifications.class, NotificationsMixin.class);
        mapper.addMixInAnnotations(NotificationsInfo.class, NotificationsInfoMixin.class);

        Notifications notifications = factory.getNotifications();

        mapper.writerWithDefaultPrettyPrinter().writeValue(
                new File("D:/workspace/nbworkspace/jackson-sample/notifications.json"), notifications);

        System.out.println("Done!");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.ebay.recommendations.RecommendationItemIds.java

/**
 * @param args//from  ww  w  .  j av a2 s.  c  o m
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub

    HttpClient client = new HttpClient();
    String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/v1/item/recommendationItemIds?recommendationType=Picture&pageNumber=1&entriesPerPage=5";
    HttpMethod method = new GetMethod(fullUri);
    // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER
    method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>");
    method.addRequestHeader("X-EBAY-GLOBAL-ID", "EBAY-US");

    method.addRequestHeader("Accept", "application/xml");

    try {
        client.executeMethod(method);
        String response = method.getResponseBodyAsString();
        System.out.println(response);
    } catch (Exception e) {
        e.printStackTrace();
    }

}