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 {

    URL google = new URL("http://www.google.com/");
    URLConnection googleConnection = google.openConnection();
    DataInputStream dis = new DataInputStream(googleConnection.getInputStream());
    StringBuffer inputLine = new StringBuffer();
    String tmp;//from   w  w w.  j  a  v a2  s .  c o  m
    while ((tmp = dis.readLine()) != null) {
        inputLine.append(tmp);
        System.out.println(tmp);
    }
    // use inputLine.toString(); here it would have whole source
    dis.close();
}

From source file:StringsDemo.java

public static void main(String[] args) {
    String palindrome = "Dot saw I was Tod";
    int len = palindrome.length();
    StringBuffer dest = new StringBuffer(len);

    for (int i = (len - 1); i >= 0; i--) {
        dest.append(palindrome.charAt(i));
    }//w  w w  .  j a v a2  s  . c  o  m
    System.out.println(dest.toString());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File f = new File("C:\\test.txt");
    FileReader fr = new FileReader(f);
    BufferedReader br = new BufferedReader(fr);

    StringBuffer sb = new StringBuffer();
    String eachLine = br.readLine();

    while (eachLine != null) {
        sb.append(eachLine);
        sb.append("\n");
        eachLine = br.readLine();//from www .  j a  v a  2s  .c  om
    }
    System.out.println(sb.toString());
}

From source file:UnicodeChars.java

public static void main(String[] argv) {
    //+//from  w  ww .  ja  va  2  s .co  m
    StringBuffer b = new StringBuffer();
    for (char c = 'a'; c < 'd'; c++) {
        b.append(c);
    }
    b.append('\u00a5'); // Japanese Yen symbol
    b.append('\u01FC'); // Roman AE with acute accent
    b.append('\u0391'); // GREEK Capital Alpha
    b.append('\u03A9'); // GREEK Capital Omega

    for (int i = 0; i < b.length(); i++) {
        System.out.println("Character #" + i + " is " + b.charAt(i));
    }
    System.out.println("Accumulated characters are " + b);
    //-
}

From source file:CreateTableWithAllDataTypesInMySQL.java

public static void main(String[] args) throws Exception {
    PreparedStatement pstmt = null;
    Connection conn = null;/*from  w  w w  . j a  v  a 2 s  .  c  om*/
    try {
        StringBuffer sql = new StringBuffer("CREATE TABLE tableWithAllTypes(");
        sql.append("column_boolean       BOOL, "); // boolean
        sql.append("column_byte          TINYINT, "); // byte
        sql.append("column_short         SMALLINT, "); // short
        sql.append("column_int           INTEGER, "); // int
        sql.append("column_long          BIGINT, "); // long
        sql.append("column_float         FLOAT, "); // float
        sql.append("column_double        DOUBLE PRECISION, "); // double
        sql.append("column_bigdecimal    DECIMAL(13,0), "); // BigDecimal
        sql.append("column_string        VARCHAR(254), "); // String
        sql.append("column_date          DATE, "); // Date
        sql.append("column_time          TIME, "); // Time
        sql.append("column_timestamp     TIMESTAMP, "); // Timestamp
        sql.append("column_asciistream1  TINYTEXT, "); // Clob ( 2^8 bytes)
        sql.append("column_asciistream2  TEXT, "); // Clob ( 2^16 bytes)
        sql.append("column_asciistream3  MEDIUMTEXT, "); // Clob (2^24 bytes)
        sql.append("column_asciistream4  LONGTEXT, "); // Clob ( 2^32 bytes)
        sql.append("column_blob1         TINYBLOB, "); // Blob ( 2^8 bytes)
        sql.append("column_blob2         BLOB, "); // Blob ( 2^16 bytes)
        sql.append("column_blob3         MEDIUMBLOB, "); // Blob ( 2^24 bytes)
        sql.append("column_blob4         LONGBLOB)"); // Blob ( 2^32 bytes)

        conn = getConnection();
        pstmt = conn.prepareStatement(sql.toString());
        pstmt.executeUpdate();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        conn.close();
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    String hostname = "time.nist.gov";

    try {/*from   ww w  . j a v  a  2  s. c o  m*/
        Socket theSocket = new Socket(hostname, 13);
        InputStream timeStream = theSocket.getInputStream();
        StringBuffer time = new StringBuffer();
        int c;
        while ((c = timeStream.read()) != -1)
            time.append((char) c);
        String timeString = time.toString().trim();
        System.out.println("It is " + timeString + " at " + hostname);
    } // end try
    catch (UnknownHostException ex) {
        System.err.println(ex);
    } catch (IOException ex) {
        System.err.println(ex);
    }

}

From source file:com.bright.utils.rmDuplicateLines.java

public static void main(String args) {
    File monfile = new File(args);

    Set<String> userIdSet = new LinkedHashSet<String>();

    if (monfile.isFile() && monfile.getName().endsWith(".txt")) {
        try {/* w  w  w  .j  a v  a  2  s.c  o  m*/
            List<String> content = FileUtils.readLines(monfile, Charset.forName("UTF-8"));
            userIdSet.addAll(content);

            Iterator<String> itr = userIdSet.iterator();
            StringBuffer output = new StringBuffer();
            while (itr.hasNext()) {

                output.append(itr.next() + System.getProperty("line.separator"));

            }

            BufferedWriter out = new BufferedWriter(new FileWriter(monfile));
            String outText = output.toString();

            out.write(outText);

            out.close();
        } catch (IOException e) {
            e.printStackTrace();

        }
    }

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A6);
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();/*  www .  j a  va 2  s  .c  om*/
    document.add(new Paragraph("Hello World"));
    document.add(new Paragraph("Hello People"));
    document.close();

    PdfReader reader = new PdfReader("2.pdf");
    PdfDictionary page = reader.getPageN(1);
    PRIndirectReference objectReference = (PRIndirectReference) page.get(PdfName.CONTENTS);
    PRStream stream = (PRStream) PdfReader.getPdfObject(objectReference);
    byte[] streamBytes = PdfReader.getStreamBytes(stream);
    String contentStream = new String(streamBytes);
    System.out.println(contentStream);
    PRTokeniser tokenizer = new PRTokeniser(streamBytes);
    while (tokenizer.nextToken()) {
        if (tokenizer.getTokenType() == PRTokeniser.TK_STRING) {
            System.out.println(tokenizer.getStringValue());
        }
    }
    StringBuffer buf = new StringBuffer();
    int pos = contentStream.indexOf("Hello World") + 11;
    buf.append(contentStream.substring(0, pos));
    buf.append("Hello");
    buf.append(contentStream.substring(pos));
    String hackedContentStream = buf.toString();
    document = new Document(PageSize.A6);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("HelloWorldStreamHacked.pdf"));
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    cb.setLiteral(hackedContentStream);
    document.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file = new File("C:/String.txt");
    StringBuffer strContent = new StringBuffer();
    FileInputStream fin = new FileInputStream(file);
    int ch;/*from  ww  w .j  av  a 2 s  .c  o m*/
    while ((ch = fin.read()) != -1) {
        strContent.append((char) ch);
    }
    fin.close();
    System.out.println(strContent);
}

From source file:FileDialogMultipleFileNameSelection.java

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

    FileDialog dlg = new FileDialog(shell, SWT.MULTI);
    Collection files = new ArrayList();
    if (dlg.open() != null) {
        String[] names = dlg.getFileNames();
        for (int i = 0, n = names.length; i < n; i++) {
            StringBuffer buf = new StringBuffer(dlg.getFilterPath());
            if (buf.charAt(buf.length() - 1) != File.separatorChar)
                buf.append(File.separatorChar);
            buf.append(names[i]);/*  ww  w.  j a  v a2s .c  o  m*/
            files.add(buf.toString());
        }
    }
    System.out.println(files);
    display.dispose();

}