Example usage for java.lang System err

List of usage examples for java.lang System err

Introduction

In this page you can find the example usage for java.lang System err.

Prototype

PrintStream err

To view the source code for java.lang System err.

Click Source Link

Document

The "standard" error output stream.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    try {//from ww w  .  ja v  a  2  s. c  o m
        Connection conn = getConnection();
        Statement st = conn.createStatement();

        st.executeUpdate("create table survey (id int,myDate DATE );");
        String INSERT_RECORD = "insert into survey(id, myDate) values(?, ?)";

        PreparedStatement pstmt = conn.prepareStatement(INSERT_RECORD);
        pstmt.setString(1, "1");
        java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
        pstmt.setDate(2, sqlDate);

        pstmt.executeUpdate();

        ResultSet rs = st.executeQuery("SELECT * FROM survey");

        rs.close();
        st.close();
        conn.close();
    } catch (SQLException e) {
        while (e != null) {
            String errorMessage = e.getMessage();
            System.err.println("sql error message:" + errorMessage);

            // This vendor-independent string contains a code.
            String sqlState = e.getSQLState();
            System.err.println("sql state:" + sqlState);

            int errorCode = e.getErrorCode();
            System.err.println("error code:" + errorCode);
            // String driverName = conn.getMetaData().getDriverName();
            // System.err.println("driver name:"+driverName);
            // processDetailError(drivername, errorCode);
            e = e.getNextException();
        }

    }
}

From source file:WidthHeightPDF.java

public static void main(String[] args) {
    Document document = new Document();

    try {//from w  ww.ja v  a  2 s  .c om
        PdfWriter.getInstance(document, new FileOutputStream("WidthHeightPDF.pdf"));
        document.open();

        BaseFont bfComic = BaseFont.createFont("c:\\windows\\fonts\\arial.ttf", BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);
        document.add(new Paragraph("width: " + bfComic.getWidthPoint("a", 12)));
        document.add(new Paragraph("ascent: " + bfComic.getAscentPoint("A", 12)));
        document.add(new Paragraph("descent: " + bfComic.getDescentPoint("aaa", 12)));
        document.add(new Paragraph(
                "height: " + (bfComic.getAscentPoint("AAA", 12) - bfComic.getDescentPoint("AAA", 12))));
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:CreatingAnchorForRTF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  ww w .j  a  va 2  s  .  co  m*/
        RtfWriter2 rtf = RtfWriter2.getInstance(document, new FileOutputStream("CreatingAnchorForRTF.rtf"));

        document.open();
        document.add(new Paragraph("Some text"));

        Anchor pdfRef = new Anchor("http://www.java2s.com");
        pdfRef.setReference("http://www.java2s.com");
        Anchor rtfRef = new Anchor("http://www.java2s.com/aFile.htm");
        rtfRef.setReference("http://www.java2s.com/aFile.htm");

        document.add(pdfRef);
        document.add(Chunk.NEWLINE);
        document.add(rtfRef);

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:CompressIt.java

public static void main(String[] args) {
    String filename = args[0];//from w w  w  .j  a va 2s .c o m
    try {
        File file = new File(filename);
        int length = (int) file.length();
        FileInputStream fis = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fis);
        ByteArrayOutputStream baos = new ByteArrayOutputStream(length);
        GZIPOutputStream gos = new GZIPOutputStream(baos);
        byte[] buffer = new byte[1024];
        int bytesRead;
        while ((bytesRead = bis.read(buffer)) != -1) {
            gos.write(buffer, 0, bytesRead);
        }
        bis.close();
        gos.close();
        System.out.println("Input Length: " + length);
        System.out.println("Output Length: " + baos.size());
    } catch (FileNotFoundException e) {
        System.err.println("Invalid Filename");
    } catch (IOException e) {
        System.err.println("I/O Exception");
    }
}

From source file:net.kolola.msgparsercli.MsgParseCLI.java

public static void main(String[] args) {

    // Parse options

    OptionParser parser = new OptionParser("f:a:bi?*");
    OptionSet options = parser.parse(args);

    // Get the filename
    if (!options.has("f")) {
        System.err.print("Specify a msg file with the -f option");
        System.exit(0);//from   w w  w  . ja  va 2 s .  c  om
    }

    File file = new File((String) options.valueOf("f"));

    MsgParser msgp = new MsgParser();
    Message msg = null;

    try {
        msg = msgp.parseMsg(file);
    } catch (UnsupportedOperationException | IOException e) {
        System.err.print("File does not exist or is not a valid msg file");
        //e.printStackTrace();
        System.exit(1);
    }

    // Show info (as JSON)
    if (options.has("i")) {
        Map<String, Object> data = new HashMap<String, Object>();

        String date;

        try {
            Date st = msg.getClientSubmitTime();
            date = st.toString();
        } catch (Exception g) {
            try {
                date = msg.getDate().toString();
            } catch (Exception e) {
                date = "[UNAVAILABLE]";
            }
        }

        data.put("date", date);
        data.put("subject", msg.getSubject());
        data.put("from", "\"" + msg.getFromName() + "\" <" + msg.getFromEmail() + ">");
        data.put("to", "\"" + msg.getToRecipient().toString());

        String cc = "";
        for (RecipientEntry r : msg.getCcRecipients()) {
            if (cc.length() > 0)
                cc.concat("; ");

            cc.concat(r.toString());
        }

        data.put("cc", cc);

        data.put("body_html", msg.getBodyHTML());
        data.put("body_rtf", msg.getBodyRTF());
        data.put("body_text", msg.getBodyText());

        // Attachments
        List<Map<String, String>> atts = new ArrayList<Map<String, String>>();
        for (Attachment a : msg.getAttachments()) {
            HashMap<String, String> info = new HashMap<String, String>();

            if (a instanceof FileAttachment) {
                FileAttachment fa = (FileAttachment) a;

                info.put("type", "file");
                info.put("filename", fa.getFilename());
                info.put("size", Long.toString(fa.getSize()));
            } else {
                info.put("type", "message");
            }

            atts.add(info);
        }

        data.put("attachments", atts);

        JSONObject json = new JSONObject(data);

        try {
            System.out.print(json.toString(4));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    // OR return an attachment in BASE64
    else if (options.has("a")) {
        Integer anum = Integer.parseInt((String) options.valueOf("a"));

        Encoder b64 = Base64.getEncoder();

        List<Attachment> atts = msg.getAttachments();

        if (atts.size() <= anum) {
            System.out.print("Attachment " + anum.toString() + " does not exist");
        }

        Attachment att = atts.get(anum);

        if (att instanceof FileAttachment) {
            FileAttachment fatt = (FileAttachment) att;
            System.out.print(b64.encodeToString(fatt.getData()));
        } else {
            System.err.print("Attachment " + anum.toString() + " is a message - That's not implemented yet :(");
        }
    }
    // OR print the message body
    else if (options.has("b")) {
        System.out.print(msg.getConvertedBodyHTML());
    } else {
        System.err.print(
                "Specify either -i to return msg information or -a <num> to print an attachment as a BASE64 string");
    }

}

From source file:G2DDrawStringPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  w  w  w  . j  av a  2  s .com*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("G2DDrawStringPDF.pdf"));
        document.open();
        DefaultFontMapper mapper = new DefaultFontMapper();
        FontFactory.registerDirectories();
        mapper.insertDirectory("c:\\windows\\fonts");

        int w = 150;
        int h = 150;
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(w, h);
        Graphics2D g2 = tp.createGraphics(w, h, mapper);

        g2.drawString("text", 20, 20);

        g2.dispose();
        cb.addTemplate(tp, 50, 400);

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:TransformationsPDF.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {/* w  ww.j  a v  a2s.  c  om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TransformationsPDF.pdf"));
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate template = cb.createTemplate(120, 120);

        template.moveTo(30, 10);
        template.lineTo(90, 10);
        template.lineTo(10, 80);
        template.lineTo(30, 80);
        template.closePath();
        template.stroke();

        cb.addTemplate(template, 0, 0);
        cb.addTemplate(template, 0, 1, -1, 0, 200, 600);
        cb.addTemplate(template, .5f, 0, 0, .5f, 100, 400);
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}

From source file:PdfContentByteColor.java

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

        BaseFont bf = FontFactory.getFont(FontFactory.COURIER).getCalculatedBaseFont(false);

        PdfContentByte cb = writer.getDirectContent();
        cb.beginText();
        cb.setColorFill(new Color(0x00, 0xFF, 0x00));
        cb.setFontAndSize(bf, 12);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "Grass is green", 50, 70, 0);
        cb.endText();

    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:SubSupScriptPDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from  ww w  . ja v  a 2s .co m
        PdfWriter.getInstance(document, new FileOutputStream("SubSupScriptPDF.pdf"));
        document.open();
        String s = "Text Text Text Text Text Text Text Text Text Text Text Text Text Text ";
        StringTokenizer st = new StringTokenizer(s, " ");
        float textrise = 6.0f;
        Chunk c;
        while (st.hasMoreTokens()) {
            c = new Chunk(st.nextToken());
            c.setTextRise(textrise);
            c.setUnderline(new Color(0xC0, 0xC0, 0xC0), 0.2f, 0.0f, 0.0f, 0.0f, PdfContentByte.LINE_CAP_BUTT);
            document.add(c);
            textrise -= 2.0f;
        }
    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:ListWithLongTextLinePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//  w w  w.  ja  v  a 2 s . c o m
        PdfWriter.getInstance(document, new FileOutputStream("ListWithLongTextLinePDF.pdf"));

        document.open();

        List list = new List(true, 20);
        list.add(new ListItem("First line"));
        list.add(new ListItem(
                "Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text Long text "));
        list.add(new ListItem("Third line"));

        document.add(list);
    } catch (Exception ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}