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 www .j  a va  2  s.co m
        String url = "jdbc:odbc:databaseName";
        String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
        String user = "guest";
        String password = "guest";
        FileInputStream fis = new FileInputStream("somefile.txt");
        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement createTable = connection.createStatement();

        createTable.executeUpdate("CREATE TABLE source_code (name CHAR(20), source LONGTEXT)");

        String ins = "INSERT INTO source_code VALUES(?,?)";
        PreparedStatement statement = connection.prepareStatement(ins);

        statement.setString(1, "TryInputStream"); // Set first field
        statement.setAsciiStream(2, fis, fis.available()); // Stream is source

        int rowsUpdated = statement.executeUpdate();
        System.out.println("Rows affected: " + rowsUpdated);
        connection.close();
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:gcm.play.android.samples.com.gcmquickstart.GcmSender.java

public static void main(String[] args) throws JSONException {
    if (args.length < 1 || args.length > 2 || args[0] == null) {
        System.err.println("usage: ./gradlew run -Pargs=\"MESSAGE[,DEVICE_TOKEN]\"");
        System.err.println("");
        System.err.println(//  w  w  w  .  j  av a 2s  .c o  m
                "Specify a test message to broadcast via GCM. If a device's GCM registration token is\n"
                        + "specified, the message will only be sent to that device. Otherwise, the message \n"
                        + "will be sent to all devices subscribed to the \"global\" topic.");
        System.err.println("");
        System.err.println(
                "Example (Broadcast):\n" + "On Windows:   .\\gradlew.bat run -Pargs=\"<Your_Message>\"\n"
                        + "On Linux/Mac: ./gradlew run -Pargs=\"<Your_Message>\"");
        System.err.println("");
        System.err.println("Example (Unicast):\n"
                + "On Windows:   .\\gradlew.bat run -Pargs=\"<Your_Message>,<Your_Token>\"\n"
                + "On Linux/Mac: ./gradlew run -Pargs=\"<Your_Message>,<Your_Token>\"");
        System.exit(1);
    }
    try {
        // Prepare JSON containing the GCM message content. What to send and where to send.
        JSONObject jGcmData = new JSONObject();
        JSONObject jData = new JSONObject();
        jData.put("message", args[0].trim());
        // Where to send GCM message.
        if (args.length > 1 && args[1] != null) {
            jGcmData.put("to", args[1].trim());
        } else {
            jGcmData.put("to", "/topics/global");
        }
        // What to send in GCM message.
        jGcmData.put("data", jData);

        // Create connection to send GCM Message request.
        URL url = new URL("https://android.googleapis.com/gcm/send");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestProperty("Authorization", "key=" + API_KEY);
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);

        // Send GCM message content.
        OutputStream outputStream = conn.getOutputStream();
        outputStream.write(jGcmData.toString().getBytes());

        // Read GCM response.
        InputStream inputStream = conn.getInputStream();
        String resp = IOUtils.toString(inputStream);
        System.out.println(resp);
        System.out.println("Check your device/emulator for notification or logcat for "
                + "confirmation of the receipt of the GCM message.");
    } catch (IOException e) {
        System.out.println("Unable to send GCM message.");
        System.out.println("Please ensure that API_KEY has been replaced by the server "
                + "API key, and that the device's registration token is correct (if specified).");
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" },
            { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" },
            { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" },

    };/*from   w  ww .j a  v  a  2 s.c o  m*/
    final Object headers[] = { "English", "#" };

    JFrame frame = new JFrame("Table Printing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    JButton button = new JButton("Print");
    ActionListener printAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                table.print();
            } catch (PrinterException pe) {
                System.err.println("Error printing: " + pe.getMessage());
            }
        }
    };
    button.addActionListener(printAction);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:SettingPageSize11X17A9A10ARCHA.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*  www.  j  a  v  a  2  s .  c  om*/
        PdfWriter.getInstance(document, new FileOutputStream("SettingPageSize11X17A9A10ARCHA.pdf"));
        document.open();
        document.add(new Paragraph("First Page."));

        document.setPageSize(PageSize._11X17);
        document.newPage();
        document.add(new Paragraph("This PageSize is _11X17."));

        document.setPageSize(PageSize.A9);
        document.newPage();
        document.add(new Paragraph("This PageSize is A9."));

        document.setPageSize(PageSize.A10);
        document.newPage();
        document.add(new Paragraph("This PageSize is A10."));

        document.setPageSize(PageSize.ARCH_A);
        document.newPage();
        document.add(new Paragraph("This PageSize is ARCH_A."));
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:com.googlecode.jcasockets.perf.Client.java

public static void main(String[] args) throws Exception {
    Client client = new Client(args);
    if (client.clientOptions.isHelpRequested()) {
        client.clientOptions.printHelp(System.err);
        return;//from w ww  . j  a  v a  2  s  . c  om
    }

    client.execute();
    ExecutionStatistics executionStatistics = client.getExecutionStatistics();
    printStatisticsHeaderAsCSV(System.out);
    printStatisticsAsCSV(System.out, executionStatistics);
}

From source file:com.nokia.dempsy.spring.RunAppInVm.java

public static void main(String[] args) {
    try {//from   w w  w . j  a v  a2 s  .  c  o m
        run(args);
    } catch (Throwable e) {
        e.printStackTrace(System.err);
        System.err.flush();
        System.exit(1);
    }
    System.exit(0);
}

From source file:org.camunda.bpm.RestDeployment.java

public static void main(String[] args) throws IOException {
    if (args.length == 0) {
        System.err.println("No process files specified");
        System.exit(1);/*from ww  w .  j a v  a  2 s . c o  m*/
    }

    CloseableHttpClient httpClient = HttpClients.createDefault();

    HttpPost httpPost = new HttpPost("http://localhost:8080/engine-rest/deployment/create");

    StringBody deploymentName = new StringBody("myDeployment", ContentType.TEXT_PLAIN);
    StringBody enableDuplicateFiltering = new StringBody("true", ContentType.TEXT_PLAIN);
    StringBody deployChangedOnly = new StringBody("true", ContentType.TEXT_PLAIN);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create().addPart("deployment-name", deploymentName)
            .addPart("enable-duplicate-filtering", enableDuplicateFiltering)
            .addPart("deploy-changed-only", deployChangedOnly);

    for (String resource : args) {
        File resourceFile = new File(resource);
        FileBody fileBody = new FileBody(resourceFile);
        builder.addPart(resourceFile.getName(), fileBody);
    }

    HttpEntity httpEntity = builder.build();
    httpPost.setEntity(httpEntity);

    HttpResponse response = httpClient.execute(httpPost);

    logResponse(response);
}

From source file:Logging.java

public static void main(String args[]) throws Exception {
    FileOutputStream errors = new FileOutputStream("StdErr.txt", true);
    PrintStream stderr = new PrintStream(errors);
    PrintWriter errLog = new PrintWriter(errors, true);
    System.setErr(stderr);/*from w  w  w  .  j  a  va2 s .c  om*/

    String query = "SELECT Name,Description,Qty,Cost,Sell_Price FROM Stock";

    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:Inventory");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            String name = rs.getString("Name");
            String desc = rs.getString("Description");
            int qty = rs.getInt("Qty");
            float cost = rs.getFloat("Cost");
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace(errLog);
    } catch (SQLException e) {
        System.err.println((new GregorianCalendar()).getTime());
        System.err.println("Thread: " + Thread.currentThread());
        System.err.println("ErrorCode: " + e.getErrorCode());
        System.err.println("SQLState:  " + e.getSQLState());
        System.err.println("Message:   " + e.getMessage());
        System.err.println("NextException: " + e.getNextException());
        e.printStackTrace(errLog);
        System.err.println();
    }
    stderr.close();
}

From source file:OutlineActionsJavaScriptCodePDF.java

public static void main(String[] args) {
    Document document = new Document();
    try {//from w  ww  .  j  ava2s .c  o  m
        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream("OutlineActionsJavaScriptCodePDF.pdf"));
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        document.open();
        document.add(new Paragraph("Outline action example"));

        PdfContentByte cb = writer.getDirectContent();
        PdfOutline root = cb.getRootOutline();
        PdfOutline links = new PdfOutline(root, new PdfAction("http://www.java2s.com"), "Useful links");
        PdfOutline other = new PdfOutline(root, new PdfDestination(PdfDestination.FIT), "other actions", false);
        other.setStyle(Font.ITALIC);
        new PdfOutline(other, PdfAction.javaScript("app.alert('Hello');\r", writer), "Say Hello");

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

From source file:Main.java

public static void main(String args[]) {
    final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" },
            { "two", "2" }, { "three", "3" }, { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" },
            { "four", "4" }, { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" },

    };/* w  ww . ja v a  2  s  .c o  m*/
    final Object headers[] = { "English", "#" };

    JFrame frame = new JFrame("Table Printing");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    JButton button = new JButton("Print");
    ActionListener printAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                table.print(JTable.PrintMode.NORMAL);
            } catch (PrinterException pe) {
                System.err.println("Error printing: " + pe.getMessage());
            }
        }
    };
    button.addActionListener(printAction);
    frame.add(button, BorderLayout.SOUTH);
    frame.setSize(300, 150);
    frame.setVisible(true);
}