java.lang.StringBuffer Java Examples

The following examples show how to use java.lang.StringBuffer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExampleResource.java    From example-health-jee-openshift with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/v1/getInfo/prescription")
@Produces(MediaType.APPLICATION_JSON)
public Response getPrescriptionsCount() {

    List<Object[]> results = entityManager.createNamedQuery("Prescription.countScripts").getResultList();
    
    StringBuffer sb = new StringBuffer();

    sb.append("[");
    for (Object[] o : results) {
        sb.append("{\"DRUG_NAME\":\"" + o[0] + "\", \"TOTAL_PATIENTS\":\"" + o[1] + "\"},");
    }
    sb.deleteCharAt(sb.lastIndexOf(","));
    sb.append("]");

    return Response.ok(sb.toString()).build();
}
 
Example #2
Source File: generateDataset.java    From ecosys with Apache License 2.0 6 votes vote down vote up
public static String sendPostRequest(String requestUrl, String payload) {
  StringBuffer sb = new StringBuffer();
  try {
    URL url = new URL(requestUrl);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Accept", "application/json");
    connection.setRequestProperty("Content-Type", "application/json; charset = UTF-8");
    OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
    writer.write(payload);
    writer.close();
    BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String line = null;
    while ((line = br.readLine()) != null) {
      sb.append(line);
    }
    br.close();
  } catch (Exception e) {
    throw new RuntimeException(e.getMessage());
  }
  return sb.toString();
}
 
Example #3
Source File: SmsSenderUtil.java    From qcloudsms_java with MIT License 6 votes vote down vote up
public static String calculateSignature(String appkey, long random, long time,
        String[] phoneNumbers) {

    StringBuffer buffer = new StringBuffer("appkey=")
        .append(appkey)
        .append("&random=")
        .append(random)
        .append("&time=")
        .append(time)
        .append("&mobile=");

    if (phoneNumbers.length > 0) {
        buffer.append(phoneNumbers[0]);
        for (int i = 1; i < phoneNumbers.length; i++) {
            buffer.append(",");
            buffer.append(phoneNumbers[i]);
        }
    }

    return sha256(buffer.toString());
}
 
Example #4
Source File: Gnuplotter.java    From act with GNU General Public License v3.0 6 votes vote down vote up
public void plot3D(String dataFile, String outFile, String srcNcFile, Double mz) {

    // Gnuplot assumes LaTeX style for text, so when we put
    // the file name in the label it get mathified. Escape _ 
    // so that they dont get interpretted as subscript ops
    String srcNcEsc = sanitize(srcNcFile);

    StringBuffer cmd = new StringBuffer();

    cmd.append(" set terminal pdf; set output \"" + outFile + "\";");
    cmd.append(" set hidden3d; set dgrid 200,200; set xlabel \"m/z\";");
    cmd.append(" set ylabel \"time in seconds\" offset -4,-1;");
    cmd.append(" set zlabel \"intensity\" offset 2,7;");
    cmd.append(" splot \"" + dataFile + "\" u 2:1:3 with lines");
    cmd.append(" title \"" + srcNcEsc + " around mass " + mz + "\";");

    String[] plot3DSurface = new String[] { "gnuplot", "-e", cmd.toString() };

    exec(plot3DSurface);
  }
 
Example #5
Source File: SmsSenderUtil.java    From qcloudsms_java with MIT License 5 votes vote down vote up
public static String calculateSignature(String appkey, long random, long time,
        String phoneNumber) {

    StringBuffer buffer = new StringBuffer("appkey=")
        .append(appkey)
        .append("&random=")
        .append(random)
        .append("&time=")
        .append(time)
        .append("&mobile=")
        .append(phoneNumber);

    return sha256(buffer.toString());
}
 
Example #6
Source File: SmsSenderUtil.java    From qcloudsms_java with MIT License 5 votes vote down vote up
public static String calculateSignature(String appkey, long random, long time) {

        StringBuffer buffer = new StringBuffer("appkey=")
            .append(appkey)
            .append("&random=")
            .append(random)
            .append("&time=")
            .append(time);

        return sha256(buffer.toString());
    }
 
Example #7
Source File: SmsSenderUtil.java    From qcloudsms_java with MIT License 5 votes vote down vote up
public static String calculateFStatusSignature(String appkey, long random,
        long time, String fid) {

    StringBuffer buffer = new StringBuffer("appkey=")
        .append(appkey)
        .append("&random=")
        .append(random)
        .append("&time=")
        .append(time)
        .append("&fid=")
        .append(fid);

    return sha256(buffer.toString());
}
 
Example #8
Source File: SmsSenderUtil.java    From qcloudsms_java with MIT License 5 votes vote down vote up
public static String calculateAuth(String appkey, long random, long time, String fileSha1Sum) {
    StringBuffer buffer = new StringBuffer("appkey=")
        .append(appkey)
        .append("&random=")
        .append(random)
        .append("&time=")
        .append(time)
        .append("&content-sha1=")
        .append(fileSha1Sum);

    return sha256(buffer.toString());
}
 
Example #9
Source File: Gnuplotter.java    From act with GNU General Public License v3.0 5 votes vote down vote up
public void plotMulti3D(String dataFile, String outFile, String fmt, String[] dataset_names, double maxz) {
  int numDataSets = dataset_names.length;

  int gridY = 1, gridX = numDataSets; // landscape layout n columns, 1 row
  // So we better adjust the size to 5 inches x #grid cells reqd
  double sizeY = 5 * gridY;
  double sizeX = 5 * gridX;
  if ("png".equals(fmt)) { // can be pdf
    // png format takes size in pixels, pdf takes it in inches
    sizeY *= 144; // 144 dpi
    sizeX *= 144; // 144 dpi
  }
  StringBuffer cmd = new StringBuffer();

  cmd.append(" set terminal " + fmt + " size " + sizeX + "," + sizeY + ";");
  cmd.append(" set output \"" + outFile + "\";");
  cmd.append(" set multiplot layout " + gridY + ", " + gridX + "; ");

  for (int i = 0; i < numDataSets; i++) {
    cmd.append(" set hidden3d; set dgrid 50,50; ");
    cmd.append(" set xlabel \"m/z\";");
    cmd.append(" unset xtics;"); // remove the xaxis labelling
    cmd.append(" set ylabel \"time in seconds\";");
    cmd.append(" set zlabel \"intensity\" offset 0,-12;");
    if (maxz != -1) cmd.append(" set zrange [0:" + maxz + "]; ");
    cmd.append(" splot \"" + dataFile + "\" index " + i + " u 2:1:3 with lines title \"" + sanitize(dataset_names[i]) + "\"; ");
  }
  cmd.append(" unset multiplot; set output;");

  String[] plot3DMulti = new String[] { "gnuplot", "-e", cmd.toString() };

  exec(plot3DMulti);

}
 
Example #10
Source File: GoEnvironment.java    From gocd-s3-artifacts with Apache License 2.0 5 votes vote down vote up
public String replaceVariables(String str) {
  Matcher m = envPat.matcher(str);

  StringBuffer sb = new StringBuffer();
  while (m.find()) {
    String replacement = get(m.group(1));
    if(replacement != null) {
      m.appendReplacement(sb, replacement);
    }
  }

  m.appendTail(sb);

  return sb.toString();
}
 
Example #11
Source File: GoEnvironment.java    From gocd-s3-artifacts with Apache License 2.0 5 votes vote down vote up
public String replaceVariables(String str) {
  Matcher m = envPat.matcher(str);

  StringBuffer sb = new StringBuffer();
  while (m.find()) {
    String replacement = get(m.group(1));
    if(replacement != null) {
      m.appendReplacement(sb, replacement);
    }
  }

  m.appendTail(sb);

  return sb.toString();
}