List of usage examples for java.lang StringBuffer length
@Override public synchronized int length()
From source file:com.clican.pluto.orm.usertype.StringSplitType.java
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { if (value == null) { st.setString(index, ""); } else if (value instanceof String[]) { StringBuffer result = new StringBuffer(); for (String s : ((String[]) value)) { result.append(s);// w w w . ja v a 2 s . co m result.append(","); } if (result.length() == 0) { st.setString(index, ""); } else { st.setString(index, result.toString().substring(0, result.length() - 1)); } } else { throw new HibernateException("The property must be a comma-split string."); } }
From source file:be.ibridge.kettle.trans.step.getfilenames.GetFileNames.java
public static final String getLine(LogWriter log, InputStreamReader reader, String format) throws KettleFileException { StringBuffer line = new StringBuffer(256); int c = 0;//from www . ja va 2s . co m try { while (c >= 0) { c = reader.read(); if (c == '\n' || c == '\r') { if (format.equalsIgnoreCase("DOS")) { c = reader.read(); // skip \n and \r if (c != '\r' && c != '\n') { // make sure its really a linefeed or cariage return // raise an error this is not a DOS file // so we have pulled a character from the next line throw new KettleFileException( "DOS format was specified but only a single line feed character was found, not 2"); } } return line.toString(); } if (c >= 0) line.append((char) c); } } catch (KettleFileException e) { throw e; } catch (Exception e) { if (line.length() == 0) { log.logError("get line", "Exception reading line: " + e.toString()); return null; } return line.toString(); } if (line.length() > 0) return line.toString(); return null; }
From source file:dk.i2m.jsf.components.alertmessage.AlertMessageRenderer.java
@Override public void encodeBegin(FacesContext context, UIComponent component) throws IOException { AlertMessage alertMessage = (AlertMessage) component; Iterator iter;/* ww w .j a v a 2s . c om*/ if (alertMessage.getFor() != null) { // Locate the component for which to display messages UIComponent forComponent = alertMessage.findComponent(alertMessage.getFor()); // If the component could not be found end processing if (forComponent == null) { return; } iter = context.getMessages(forComponent.getClientId(context)); } else { iter = context.getMessages(); } // Iterate through messages for the component if (iter.hasNext()) { ResponseWriter writer = context.getResponseWriter(); // Start the script tag writer.startElement("script", alertMessage); writer.writeAttribute("type", "text/javascript", null); // Construct one big string of all messages StringBuffer message = new StringBuffer(); while (iter.hasNext()) { FacesMessage msg = (FacesMessage) iter.next(); if (message.length() > 0) { // Separate each message with the JavaScript escape code // for newline message.append("\n"); } message.append(msg.getDetail()); } // Escape the constructed string to be outputable as a JavaScript String displayMessage = StringEscapeUtils.escapeJavaScript(message.toString()); // Output the javascript code for displaying the alert dialogue String jsAlert = "alert('" + displayMessage + "');"; writer.writeText(jsAlert.toCharArray(), 0, jsAlert.length()); // End the script tag writer.endElement("script"); } }
From source file:com.github.guava.JoinerPractice.java
private String mapJoinWith(Map<?, ?> map, String keyValueSeparator, String separator) { StringBuffer stringBuffer = new StringBuffer(); for (Object key : map.keySet()) { stringBuffer.append(key).append(keyValueSeparator).append(map.get(key)).append(separator); }// ww w . java2 s . c om stringBuffer.setLength(stringBuffer.length() - separator.length()); return stringBuffer.toString(); }
From source file:fiftyfive.wicket.util.LoggingUtils.java
/** * Returns a description of component or page that is currently being * processed by the Wicket framework. If a component is being executed, the * description will be in the form://from ww w .j a va 2 s . co m * <pre class="example"> * PageClass > ComponentClass (superclass if component is anonymous) [wicket:id path]</pre> * <p> * Example: * <pre class="example"> * MyPage > MyPanel$1 (Link) [path:to:link]</pre> * <p> * If a page is being rendered, the description will be the page class. */ public static String describeRequestComponent() { IRequestHandler handler = guessOriginalRequestHandler(); Class<? extends IRequestablePage> pageClass = null; IRequestableComponent component = null; if (handler instanceof IPageClassRequestHandler) { pageClass = ((IPageClassRequestHandler) handler).getPageClass(); } if (handler instanceof IComponentRequestHandler) { component = ((IComponentRequestHandler) handler).getComponent(); } StringBuffer desc = new StringBuffer(); if (pageClass != null) { desc.append(Classes.simpleName(pageClass)); } if (component != null) { String classDesc = null; if (component.getClass().isAnonymousClass()) { classDesc = String.format("%s (%s)", Classes.simpleName(component.getClass()), Classes.simpleName(component.getClass().getSuperclass())); } else { classDesc = Classes.simpleName(component.getClass()); } desc.append(String.format(" > %s [%s]", classDesc, component.getPageRelativePath())); } return desc.length() > 0 ? desc.toString() : null; }
From source file:com.yolodata.tbana.hadoop.mapred.util.CSVReader.java
protected void foundDelimiter(StringBuffer sb, List<Text> values, boolean takeDelimiterOut) throws UnsupportedEncodingException { Text text = new Text(); String val = (takeDelimiterOut) ? sb.substring(0, sb.length() - separator.length()) : sb.toString(); val = StringUtils.strip(val, "\n"); val = StringUtils.strip(val, delimiter); text.set(val); values.add(text);/*from ww w .j av a 2s . c o m*/ sb.setLength(0); }
From source file:edu.northwestern.bioinformatics.studycalendar.web.taglibs.jsgenerator.ElementUpdatingGenerator.java
protected String call(String method, Object... parameters) { StringBuffer call = new StringBuffer(method).append('('); for (Object parameter : parameters) { call.append(createJavascriptLiteralRepresentation(parameter)).append(", "); }/*from w w w. j av a2 s . c om*/ call.setLength(call.length() - 2); call.append(')'); return call.toString(); }
From source file:com.twinsoft.convertigo.engine.billing.GoogleAnalyticsTicketManager.java
public synchronized void addTicket(Ticket ticket) throws BillingException { if (log.isDebugEnabled()) { log.debug("(GoogleAnalyticsTicketManager) addTicket " + ticket); }/*from ww w . ja v a 2 s.c o m*/ PostMethod method = new PostMethod(urls[0]); HeaderName.ContentType.setRequestHeader(method, MimeType.WwwForm.value()); // set parameters for POST method method.setParameter("v", "1"); method.setParameter("tid", analyticsID); String cid = ticket.getDeviceUUID(); if (cid.isEmpty()) { cid = ticket.getSessionID(); } try { cid = UuidUtils.toUUID(cid).toString(); } catch (Exception e) { log.debug("(GoogleAnalyticsTicketManager) failed to get DeviceUUID", e); } method.setParameter("cid", cid); method.setParameter("uid", ticket.getUserName()); method.setParameter("uip", ticket.getClientIp()); method.setParameter("t", "event"); method.setParameter("an", ticket.getProjectName()); method.setParameter("ec", ticket.getProjectName()); StringBuffer requestableName = new StringBuffer(ticket.getConnectorName()); if (requestableName.length() > 0) { requestableName.append('.'); } method.setParameter("ea", requestableName.append(ticket.getRequestableName()).toString()); method.setParameter("ev", Long.toString(ticket.getResponseTime())); method.setParameter("ua", ticket.getUserAgent()); // execute HTTP post with parameters if (GAClient != null) { try { int httpCode = GAClient.executeMethod(method); String body = method.getResponseBodyAsString(); log.debug("[" + httpCode + "] " + body); } catch (MalformedURLException e) { log.error("(GoogleAnalyticsTicketManager) error creating GAanalytics HttpClient, bad url", e); } catch (HttpException e) { log.error( "(GoogleAnalyticsTicketManager) error creating GAanalytics HttpClient, Error in HTTP request", e); } catch (IOException e) { log.error("(GoogleAnalyticsTicketManager) error creating GAanalytics HttpClient, I/O error", e); } } }
From source file:com.bjwg.back.util.PropertyFilter.java
public static String buildStringByPropertyFilter(final List<PropertyFilter> filters) { StringBuffer sb = new StringBuffer(); for (PropertyFilter filter : filters) { if (!filter.hasMultiProperties()) { //?,filter_EQS_account sb = toSqlString(filter.getPropertyName(), filter.getMatchValue(), filter.getMatchType(), filter.getPropertyClass(), sb); } else {//,filter_LIKES_realName_OR_email sb = toSqlString(filter.getPropertyNames(), filter.getMatchValue(), filter.getMatchType(), filter.getPropertyClass(), sb); }//from ww w . j a va 2 s . c o m } if (sb == null || sb.length() <= 0) { return ""; } return sb.toString(); }
From source file:gov.nih.nci.caintegrator.application.analysis.grid.gistic.GisticGridRunner.java
private String getDescription(InvalidParameterException e) { StringBuffer description = new StringBuffer(); for (BaseFaultTypeDescription typeDescription : e.getDescription()) { if (description.length() > 0) { description.append(", "); }// ww w. ja v a2 s . c om description.append(typeDescription.get_value()); } return description.toString(); }