Example usage for java.lang StringBuffer append

List of usage examples for java.lang StringBuffer append

Introduction

In this page you can find the example usage for java.lang StringBuffer append.

Prototype

@Override
    public synchronized StringBuffer append(double d) 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("hello.txt");
    FileReader fr = new FileReader(f);

    char[] c = new char[(int) f.length()];
    char[] cnew = new char[(int) f.length()];
    StringBuffer sbuf = new StringBuffer();
    fr.read(c, 0, (int) f.length());

    int len = (int) f.length();

    for (int i = 0, j = len - 1; i < len; i++, j--) {
        cnew[i] = c[j];/*from   www .j  a v a2s  .  c om*/
        sbuf.append(cnew[i]);
    }

    System.out.println(sbuf.toString());
    fr.close();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = new File("Main.java");
    FileReader fr = new FileReader(f);

    char[] c = new char[(int) f.length()];
    char[] cnew = new char[(int) f.length()];
    StringBuffer sbuf = new StringBuffer();
    fr.read(c, 0, (int) f.length());

    int len = (int) f.length();

    for (int i = 0, j = len - 1; i < len; i++, j--) {
        cnew[i] = c[j];//from  w ww  .  j a v  a  2s.co  m
        sbuf.append(cnew[i]);
    }

    System.out.println(sbuf.toString());
    fr.close();

}

From source file:com.gemini.httpclienttest.HttpClientTestMain.java

public static void main(String[] args) {
    //authenticate with the server
    URL url;/*w  w w  . j  a va 2s  .co  m*/
    try {
        url = new URL("http://198.11.209.34:5000/v2.0/tokens");
    } catch (MalformedURLException ex) {
        System.out.printf("Invalid Endpoint - not a valid URL {}", "http://198.11.209.34:5000/v2.0");
        return;
    }
    CloseableHttpClient httpclient = HttpClientBuilder.create().build();
    try {
        HttpPost httpPost = new HttpPost(url.toString());
        httpPost.setHeader("Content-Type", "application/json");
        StringEntity strEntity = new StringEntity(
                "{\"auth\":{\"tenantName\":\"Gemini-network-prj\",\"passwordCredentials\":{\"username\":\"sri\",\"password\":\"srikumar12\"}}}");
        httpPost.setEntity(strEntity);
        //System.out.println("Executing request " + httpget.getRequestLine());
        CloseableHttpResponse response = httpclient.execute(httpPost);
        try {
            //get the response status code 
            String respStatus = response.getStatusLine().getReasonPhrase();

            //get the response body
            int bytes = response.getEntity().getContent().available();
            InputStream body = response.getEntity().getContent();
            BufferedReader in = new BufferedReader(new InputStreamReader(body));
            String line;
            StringBuffer sbJSON = new StringBuffer();
            while ((line = in.readLine()) != null) {
                sbJSON.append(line);
            }
            String json = sbJSON.toString();
            EntityUtils.consume(response.getEntity());

            GsonBuilder gsonBuilder = new GsonBuilder();
            Object parsedJson = gsonBuilder.create().fromJson(json, Object.class);
            System.out.printf("Parsed json is of type %s\n\n", parsedJson.getClass().toString());
            if (parsedJson instanceof com.google.gson.internal.LinkedTreeMap) {
                com.google.gson.internal.LinkedTreeMap treeJson = (com.google.gson.internal.LinkedTreeMap) parsedJson;
                if (treeJson.containsKey("id")) {
                    String s = (String) treeJson.getOrDefault("id", "no key provided");
                    System.out.printf("\n\ntree contained id %s\n", s);
                } else {
                    System.out.printf("\n\ntree does not contain key id\n");
                }
            }
        } catch (IOException ex) {
            System.out.print(ex);
        } finally {
            response.close();
        }
    } catch (IOException ex) {
        System.out.print(ex);
    } finally {
        //lots of exceptions, just the connection and exit
        try {
            httpclient.close();
        } catch (IOException | NoSuchMethodError ex) {
            System.out.print(ex);
            return;
        }
    }
}

From source file:CreateTableAllTypesInOracle.java

public static void main(String[] args) {
    PreparedStatement pstmt = null;
    Connection conn = null;//from   ww  w .j  a  v a 2s  .com
    try {
        conn = getConnection();
        pstmt = conn.prepareStatement("CREATE TYPE varray_type is VARRAY(5) OF VARCHAR(10)");
        pstmt.executeUpdate();
        // Create an OBJECT type
        pstmt = conn.prepareStatement(
                "CREATE TYPE oracle_object is OBJECT(column_string VARCHAR(128), column_integer INTEGER)");
        pstmt.executeUpdate();

        StringBuffer allTypesTable = new StringBuffer("CREATE TABLE oracle_all_types(");
        //                    Column Name          Oracle Type              Java Type
        allTypesTable.append("column_short           SMALLINT, "); // short
        allTypesTable.append("column_int             INTEGER, "); // int
        allTypesTable.append("column_float           REAL, "); // float; can also be NUMBER
        allTypesTable.append("column_double          DOUBLE PRECISION, "); // double; can also be FLOAT or NUMBER
        allTypesTable.append("column_bigdecimal      DECIMAL(13,0), "); // BigDecimal
        allTypesTable.append("column_string          VARCHAR2(254), "); // String; can also be CHAR(n)
        allTypesTable.append("column_characterstream LONG, "); // CharacterStream or AsciiStream
        allTypesTable.append("column_bytes           RAW(2000), "); // byte[]; can also be LONG RAW(n)
        allTypesTable.append("column_binarystream    RAW(2000), "); // BinaryStream; can also be LONG RAW(n)
        allTypesTable.append("column_timestamp       DATE, "); // Timestamp
        allTypesTable.append("column_clob            CLOB, "); // Clob
        allTypesTable.append("column_blob            BLOB, "); // Blob; can also be BFILE
        allTypesTable.append("column_bfile           BFILE, "); // oracle.sql.BFILE
        allTypesTable.append("column_array           varray_type, "); // oracle.sql.ARRAY
        allTypesTable.append("column_object          oracle_object)"); // oracle.sql.OBJECT

        pstmt.executeUpdate(allTypesTable.toString());
    } catch (Exception e) {
        // creation of table failed.
        // handle the exception
        e.printStackTrace();
    }
}

From source file:org.wso2.charon3.samples.user.sample01.CreateUserSample.java

public static void main(String[] args) {
    try {//  w w w  . j  av  a 2  s .c  o m
        String url = "http://localhost:8080/scim/v2/Users";
        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        // Setting basic post request
        con.setRequestMethod("POST");
        con.setRequestProperty("Content-Type", "application/scim+json");

        // Send post request
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(createRequestBody);
        wr.flush();
        wr.close();

        int responseCode = con.getResponseCode();

        BufferedReader in;
        if (responseCode == HttpURLConnection.HTTP_CREATED) { // success
            in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        } else {
            in = new BufferedReader(new InputStreamReader(con.getErrorStream()));
        }
        String inputLine;
        StringBuffer response = new StringBuffer();

        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();

        //printing result from response
        System.out.println("Response Code : " + responseCode);
        System.out.println("Response Message : " + con.getResponseMessage());
        System.out.println("Response Content : " + response.toString());

    } catch (ProtocolException e) {
        e.printStackTrace();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.thinkbiganalytics.util.PartitionSpec.java

public static void main(String[] args) {
    PartitionKey key1 = new PartitionKey("country", "string", "country");
    PartitionKey key2 = new PartitionKey("year", "int", "year(hired)");
    PartitionKey key3 = new PartitionKey("month", "int", "month(hired)");

    PartitionSpec spec = new PartitionSpec(key1, key2, key3);
    String[] selectFields = new String[] { "id", "name", "company", "zip", "phone", "email", "hired" };
    String selectSQL = StringUtils.join(selectFields, ",");

    String[] values = new String[] { "USA", "2015", "4" };

    String targetSqlWhereClause = spec.toTargetSQLWhere(values);
    String sourceSqlWhereClause = spec.toSourceSQLWhere(values);
    String partitionClause = spec.toPartitionSpec(values);

    /*//from w  w w.  j  av  a  2 s  . com
     insert overwrite table employee partition (year=2015,month=10,country='USA')
     select id, name, company, zip, phone, email, hired from employee_feed
     where year(hired)=2015 and month(hired)=10 and country='USA'
     union distinct
     select id, name, company, zip, phone, email, hired from employee
     where year=2015 and month=10 and country='USA'
     */

    String targetTable = "employee";
    String sourceTable = "employee_feed";
    String sqlWhere = "employee_feed";

    StringBuffer sb = new StringBuffer();
    sb.append("insert overwrite table ").append(targetTable).append(" ").append(partitionClause)
            .append(" select ").append(selectSQL).append(" from ").append(sourceTable).append(" ")
            .append(" where ").append(sourceSqlWhereClause).append(" union distinct ").append(" select ")
            .append(selectSQL).append(" from ").append(targetTable).append(" ").append(" where ")
            .append(targetSqlWhereClause);

    log.info(sb.toString());
}

From source file:MainClass.java

public static void main(String[] a) {

    final Display display = new Display();
    final Shell shell = new Shell(display);

    shell.setSize(250, 200);//from  w  ww.jav a  2 s . co m

    shell.setLayout(new FillLayout());

    Table table = new Table(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };

    DragSource source = new DragSource(table, DND.DROP_MOVE | DND.DROP_COPY);
    source.setTransfer(types);
    source.addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            DragSource ds = (DragSource) event.widget;
            Table table = (Table) ds.getControl();
            TableItem[] selection = table.getSelection();

            StringBuffer buff = new StringBuffer();
            for (int i = 0, n = selection.length; i < n; i++) {
                buff.append(selection[i].getText());
            }
            event.data = buff.toString();
        }
    });

    DropTarget target = new DropTarget(table, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT) {
                event.detail = (event.operations & DND.DROP_COPY) != 0 ? DND.DROP_COPY : DND.DROP_NONE;
            }
            for (int i = 0, n = event.dataTypes.length; i < n; i++) {
                if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
                    event.currentDataType = event.dataTypes[i];
                }
            }
        }

        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
        }

        public void drop(DropTargetEvent event) {
            if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                DropTarget target = (DropTarget) event.widget;
                Table table = (Table) target.getControl();
                String data = (String) event.data;

                TableItem item = new TableItem(table, SWT.NONE);
                item.setText(new String[] { data });
                table.redraw();
            }
        }
    });

    TableColumn column = new TableColumn(table, SWT.NONE);

    TableItem item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "A" });
    item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "B" });
    item = new TableItem(table, SWT.BORDER);
    item.setText(new String[] { "C" });

    column.pack();

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:org.berlin.crawl.util.ListSeedsMain.java

public static void main(final String[] args) {
    logger.info("Running");
    final ApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/org/berlin/batch/batch-databot-context.xml");
    final BotCrawlerDAO dao = new BotCrawlerDAO();
    final SessionFactory sf = (SessionFactory) ctx.getBean("sessionFactory");
    Session session = sf.openSession();//from   w  w  w.  ja v a  2 s.co  m

    final StringBuffer buf = new StringBuffer();
    final List<String> seeds = dao.findHosts(session);
    final String nl = System.getProperty("line.separator");
    buf.append(nl);
    for (final String seed : seeds) {
        buf.append(PREFIX);
        buf.append(seed);
        buf.append(POST1);
        buf.append("/");
        buf.append(POST2);
        buf.append(nl);
    } // End of the for //
    logger.info(buf.toString());

    // Now print the number of links //
    final List<Long> ii = dao.countLinks(session);
    logger.warn("Count of Links : " + ii);

    // Also print top hosts //
    final List<Object[]> hosts = dao.findTopHosts(session);
    Collections.reverse(hosts);
    for (final Object[] oo : hosts) {
        System.out.println(oo[0] + " // " + oo[1].getClass());
    }

    if (session != null) {
        // May not need to close the session
        session.close();
    } // End of the if //
    logger.info("Done");
}

From source file:com.interacciones.mxcashmarketdata.driver.util.AppropriateFormat.java

public static void main(String[] args) throws Throwable {
    init(args);// ww  w. ja  va 2s .c  o m

    long time = System.currentTimeMillis();
    //for (;;) {
    try {
        //read
        file = new File(source);
        is = new FileInputStream(file);
        isr = new InputStreamReader(is);
        br = new BufferedReader(isr);
        //write
        filewrite = new File(destination);
        fos = new FileOutputStream(filewrite);
        bos = new BufferedOutputStream(fos);

        int data = 0;
        int count = 0;

        StringBuffer message = new StringBuffer();
        while (data != -1) {
            data = br.read();
            message.append((char) data);
            count++;
            if (data == 10) {
                transform(message);
                count = 0;
                message.delete(INIT_ASCII, message.length());
            }
        }
    } catch (Exception e) {
        LOGGER.error("Warning " + e.getMessage());
        e.printStackTrace();
    } finally {
        close();
    }
    //}
    time = System.currentTimeMillis() - time;
    LOGGER.info("Time " + time);
}

From source file:DragDropTable.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Table table = new Table(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);

    Transfer[] types = new Transfer[] { TextTransfer.getInstance() };
    DragSource source = new DragSource(table, DND.DROP_MOVE | DND.DROP_COPY);
    source.setTransfer(types);//from   w ww .ja v  a  2s. co  m

    source.addDragListener(new DragSourceAdapter() {
        public void dragSetData(DragSourceEvent event) {
            // Get the selected items in the drag source
            DragSource ds = (DragSource) event.widget;
            Table table = (Table) ds.getControl();
            TableItem[] selection = table.getSelection();

            StringBuffer buff = new StringBuffer();
            for (int i = 0, n = selection.length; i < n; i++) {
                buff.append(selection[i].getText());
            }

            event.data = buff.toString();
        }
    });

    // Create the drop target
    DropTarget target = new DropTarget(table, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
    target.setTransfer(types);
    target.addDropListener(new DropTargetAdapter() {
        public void dragEnter(DropTargetEvent event) {
            if (event.detail == DND.DROP_DEFAULT) {
                event.detail = (event.operations & DND.DROP_COPY) != 0 ? DND.DROP_COPY : DND.DROP_NONE;
            }

            // Allow dropping text only
            for (int i = 0, n = event.dataTypes.length; i < n; i++) {
                if (TextTransfer.getInstance().isSupportedType(event.dataTypes[i])) {
                    event.currentDataType = event.dataTypes[i];
                }
            }
        }

        public void dragOver(DropTargetEvent event) {
            event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
        }

        public void drop(DropTargetEvent event) {
            if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
                // Get the dropped data
                DropTarget target = (DropTarget) event.widget;
                Table table = (Table) target.getControl();
                String data = (String) event.data;

                // Create a new item in the table to hold the dropped data
                TableItem item = new TableItem(table, SWT.NONE);
                item.setText(new String[] { data });
                table.redraw();
            }
        }
    });
    TableColumn column = new TableColumn(table, SWT.NONE);

    // Seed the table
    TableItem item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "A" });
    item = new TableItem(table, SWT.NONE);
    item.setText(new String[] { "B" });
    item = new TableItem(table, SWT.BORDER);
    item.setText(new String[] { "C" });

    column.pack();
    shell.open();

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}