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:net.landora.justintv.JustinTVAPI.java

public static void main(String[] args) throws Exception {
    List<JustinArchive> archives = readArchives("tsmtournaments", 64);
    Map<String, List<JustinArchive>> groups = new HashMap<String, List<JustinArchive>>();
    for (int i = 0; i < archives.size(); i++) {
        JustinArchive archive = archives.get(i);
        List<JustinArchive> group = groups.get(archive.getBroadcastId());
        if (group == null) {
            group = new ArrayList<JustinArchive>(archive.getBroadcastPart());
            groups.put(archive.getBroadcastId(), group);
        }/*from   w  ww  .j a v  a2s .  c o  m*/
        group.add(archive);
    }

    BroadcastSorter sorter = new BroadcastSorter();

    for (List<JustinArchive> group : groups.values()) {
        Collections.sort(group, sorter);

        JustinArchive base = group.get(group.size() - 1);

        StringBuffer cmd = new StringBuffer();
        cmd.append("mkvmerge -o \"");
        cmd.append(base.getBroadcastId());
        cmd.append(" - ");
        cmd.append(base.getTitle());
        cmd.append("\" ");

        for (int i = 0; i < group.size(); i++) {
            JustinArchive archive = group.get(i);
            if (i > 0)
                cmd.append("+ ");

            cmd.append(archive.getId());
            cmd.append(".mkv ");
        }
        System.out.println(cmd);
    }
}

From source file:MethodInspector.java

public static void main(String[] arguments) {
    Class inspect;/*from  w w w.ja  v a2 s  .  c  o  m*/
    try {
        if (arguments.length > 0)
            inspect = Class.forName(arguments[0]);
        else
            inspect = Class.forName("MethodInspector");
        Method[] methods = inspect.getDeclaredMethods();
        for (int i = 0; i < methods.length; i++) {
            Method methVal = methods[i];
            Class returnVal = methVal.getReturnType();
            int mods = methVal.getModifiers();
            String modVal = Modifier.toString(mods);
            Class[] paramVal = methVal.getParameterTypes();
            StringBuffer params = new StringBuffer();
            for (int j = 0; j < paramVal.length; j++) {
                if (j > 0)
                    params.append(", ");
                params.append(paramVal[j].getName());
            }
            System.out.println("Method: " + methVal.getName() + "()");
            System.out.println("Modifiers: " + modVal);
            System.out.println("Return Type: " + returnVal.getName());
            System.out.println("Parameters: " + params + "\n");
        }
    } catch (ClassNotFoundException c) {
        System.out.println(c.toString());
    }
}

From source file:StyledTextBulletedList.java

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("StyledText Bullet Example");
    shell.setLayout(new FillLayout());
    final StyledText styledText = new StyledText(shell,
            SWT.FULL_SELECTION | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
    StringBuffer text = new StringBuffer();
    text.append("Here is StyledText with some bulleted lists:\n\n");
    for (int i = 0; i < 4; i++)
        text.append("Red Bullet List Item " + i + "\n");
    text.append("\n");
    for (int i = 0; i < 2; i++)
        text.append("Numbered List Item " + i + "\n");
    for (int i = 0; i < 4; i++)
        text.append("Sub List Item " + i + "\n");
    for (int i = 0; i < 2; i++)
        text.append("Numbered List Item " + (2 + i) + "\n");
    text.append("\n");
    for (int i = 0; i < 4; i++)
        text.append("Custom Draw List Item " + i + "\n");
    styledText.setText(text.toString());

    StyleRange style0 = new StyleRange();
    style0.metrics = new GlyphMetrics(0, 0, 40);
    style0.foreground = display.getSystemColor(SWT.COLOR_RED);
    Bullet bullet0 = new Bullet(style0);
    StyleRange style1 = new StyleRange();
    style1.metrics = new GlyphMetrics(0, 0, 50);
    style1.foreground = display.getSystemColor(SWT.COLOR_BLUE);
    Bullet bullet1 = new Bullet(ST.BULLET_NUMBER | ST.BULLET_TEXT, style1);
    bullet1.text = ".";
    StyleRange style2 = new StyleRange();
    style2.metrics = new GlyphMetrics(0, 0, 80);
    style2.foreground = display.getSystemColor(SWT.COLOR_GREEN);
    Bullet bullet2 = new Bullet(ST.BULLET_TEXT, style2);
    bullet2.text = "\u2713";
    StyleRange style3 = new StyleRange();
    style3.metrics = new GlyphMetrics(0, 0, 50);
    Bullet bullet3 = new Bullet(ST.BULLET_CUSTOM, style2);

    styledText.setLineBullet(2, 4, bullet0);
    styledText.setLineBullet(7, 2, bullet1);
    styledText.setLineBullet(9, 4, bullet2);
    styledText.setLineBullet(13, 2, bullet1);
    styledText.setLineBullet(16, 4, bullet3);

    styledText.addPaintObjectListener(new PaintObjectListener() {
        public void paintObject(PaintObjectEvent event) {
            Display display = event.display;
            StyleRange style = event.style;
            Font font = style.font;
            if (font == null)
                font = styledText.getFont();
            TextLayout layout = new TextLayout(display);
            layout.setAscent(event.ascent);
            layout.setDescent(event.descent);
            layout.setFont(font);//from  w  w  w  . j  a v  a2  s.  c om
            layout.setText("\u2023 1." + event.bulletIndex + ")");
            layout.draw(event.gc, event.x + 10, event.y);
            layout.dispose();
        }
    });
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.rest.samples.getTipoCambioBanxico.java

public static void main(String[] args) {
    String url = "http://www.banxico.org.mx/tipcamb/llenarTiposCambioAction.do?idioma=sp";
    try {//from w  w  w  .ja  v a2  s.c o m
        HttpClient hc = HttpClientBuilder.create().build();
        HttpGet request = new HttpGet(url);
        request.setHeader("User-Agent", "Mozilla/5.0");
        request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");

        HttpResponse res = hc.execute(request);
        if (res.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException("Failed : HTTP eror code: " + res.getStatusLine().getStatusCode());
        }

        BufferedReader rd = new BufferedReader(new InputStreamReader(res.getEntity().getContent()));
        StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
        Document doc = Jsoup.parse(result.toString());
        Element tipoCambioFix = doc.getElementById("FIX_DATO");
        System.out.println(tipoCambioFix.text());

    } catch (IOException ex) {
        Logger.getLogger(SamplesUseHttpclient.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ZipDemo.java

public static void main(String[] args) throws Exception {
    for (int i = 0; i < args.length; ++i) {
        String uncompressed = "";
        File f = new File(args[i]);

        if (f.exists()) {
            BufferedReader br = new BufferedReader(new FileReader(f));

            String line = "";
            StringBuffer buffer = new StringBuffer();

            while ((line = br.readLine()) != null)
                buffer.append(line);

            br.close();//from   w  w  w  . j  ava2  s .  com
            uncompressed = buffer.toString();
        } else {
            uncompressed = args[i];
        }

        byte[] compressed = ZipDemo.compress(uncompressed);

        String compressedAsString = new String(compressed);

        byte[] bytesFromCompressedAsString = compressedAsString.getBytes();

        bytesFromCompressedAsString.equals(compressed);
        System.out.println(ZipDemo.uncompress(compressed));
        System.out.println(ZipDemo.uncompress(compressedAsString));
    }
}

From source file:nz.co.jsrsolutions.ds3.DataScraper3.java

public static void main(String[] args) {

    logger.info("Starting application [ ds3 ] ...");

    ClassPathXmlApplicationContext context = null;

    try {//ww w .  jav  a  2s . c  o  m

        CommandLineParser parser = new GnuParser();

        CommandLine commandLine = parser.parse(CommandLineOptions.Options, args);

        if (commandLine.getOptions().length > 0 && !commandLine.hasOption(CommandLineOptions.HELP)) {

            StringBuffer environment = new StringBuffer();
            environment.append(SPRING_CONFIG_PREFIX);
            environment.append(commandLine.getOptionValue(CommandLineOptions.ENVIRONMENT));
            environment.append(SPRING_CONFIG_SUFFIX);

            context = new ClassPathXmlApplicationContext(environment.toString());
            context.registerShutdownHook();

            if (commandLine.hasOption(CommandLineOptions.SCHEDULED)) {

                Scheduler scheduler = context.getBean(SCHEDULER_BEAN_ID, Scheduler.class);
                scheduler.start();

                Object lock = new Object();
                synchronized (lock) {
                    lock.wait();
                }

            } else {
                DataScraper3Controller controller = context.getBean(CONTROLLER_BEAN_ID,
                        DataScraper3Controller.class);
                controller.executeCommandLine(commandLine);
            }

        } else {

            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("ds3", CommandLineOptions.Options);

        }

    } catch (DataScraper3Exception ds3e) {
        logger.error("Failed to execute command", ds3e);
    } catch (ParseException pe) {

        logger.error("Failed to parse command line", pe);

    } catch (Exception e) {

        logger.error("Failed to execute command", e);

    } finally {
        if (context != null) {
            context.close();
        }
    }

    logger.info("Exiting application [ ds3 ] ...");

}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//from  w ww  .j  a va 2 s . co m
    PdfContentByte cb = writer.getDirectContent();
    StringBuffer sb = new StringBuffer(1024);
    BufferedReader reader = new BufferedReader(new FileReader("a.txt"));
    int c;
    while ((c = reader.read()) > -1) {
        sb.append((char) c);
    }
    reader.close();
    ColumnText ct = new ColumnText(cb);
    ct.setSimpleColumn(new Phrase(sb.toString()), 36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36,
            18, Element.ALIGN_JUSTIFIED);
    int status = ColumnText.START_COLUMN;
    while (ColumnText.hasMoreText(status)) {
        status = ct.go();
        ct.setYLine(PageSize.A4.height() - 36);
        document.newPage();
    }
    document.close();
}

From source file:org.wso2.charon3.samples.group.sample01.CreateGroupSample.java

public static void main(String[] args) {
    try {//from ww w. ja  v a  2s .  co  m
        String url = "http://localhost:8080/scim/v2/Groups";
        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:at.treedb.util.Compress.java

/**
 * /*from www .j a  va 2  s  . c  o  m*/
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    StringBuffer buf = new StringBuffer();
    buf.append("7z-compression with following parameters: ");
    for (String s : args) {
        buf.append(s);
        buf.append(' ');
    }
    System.out.println(buf.toString());
    Compress c = new Compress(args[0], args[1], args[2], Arrays.copyOfRange(args, 3, args.length));
    c.compress();
}

From source file:ComputeInitials.java

public static void main(String[] args) {
    String myName = "Fred F. Flintstone";
    StringBuffer myInitials = new StringBuffer();
    int length = myName.length();

    for (int i = 0; i < length; i++) {
        if (Character.isUpperCase(myName.charAt(i))) {
            myInitials.append(myName.charAt(i));
        }//from w  w  w  . j  a  va2s  . c  o m
    }
    System.out.println("My initials are: " + myInitials);
}