List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:google.registry.util.UrlFetchUtils.java
private static String createMultipartBoundary() { // Generate 192 random bits (24 bytes) to produce 192/log_2(64) = 192/6 = 32 base64 digits. byte[] rand = new byte[24]; random.nextBytes(rand);//w w w . j a va 2 s . c o m // Boundary strings can be up to 70 characters long, so use 30 hyphens plus 32 random digits. // See https://tools.ietf.org/html/rfc2046#section-5.1.1 return Strings.repeat("-", 30) + base64().encode(rand); }
From source file:com.axelor.meta.loader.Module.java
public String pprint(int depth) { StringBuilder builder = new StringBuilder(); builder.append(name).append("\n"); for (Module dep : depends) { builder.append(Strings.repeat(" ", depth)).append("-> ").append(dep.pprint(depth + 1)); }/*from w ww.j ava 2s. c o m*/ return builder.toString(); }
From source file:org.apache.james.queue.api.MailQueueContract.java
@Test default void queueShouldSupportBigMail() throws Exception { String name = "name1"; // 12 MB of text String messageText = Strings.repeat("0123456789\r\n", 1024 * 1024); FakeMail mail = defaultMail().name(name) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText(messageText)).build(); enQueue(mail);/* ww w .j a va 2 s. c o m*/ MailQueue.MailQueueItem mailQueueItem = getMailQueue().deQueue(); assertThat(mailQueueItem.getMail().getName()).isEqualTo(name); }
From source file:com.google.template.soy.error.ErrorReporterImpl.java
/** Returns a source line snippet with a caret pointing at the error column offset. */ private Optional<String> getSnippet(SourceLocation sourceLocation) { // Try to find a snippet of source code associated with the exception and print it. Optional<String> snippet = getSourceLine(sourceLocation); // TODO(user): this is a result of calling SoySyntaxException#createWithoutMetaInfo, // which occurs almost 100 times. Clean them up. if (snippet.isPresent()) { StringBuilder builder = new StringBuilder(); builder.append(snippet.get()).append("\n"); // Print a caret below the error. // TODO(brndn): SourceLocation.beginColumn is occasionally -1. Review all SoySyntaxException // instantiations and ensure the SourceLocation is well-formed. int beginColumn = Math.max(sourceLocation.getBeginColumn(), 1); String caretLine = Strings.repeat(" ", beginColumn - 1) + "^"; builder.append(caretLine).append("\n"); return Optional.of(builder.toString()); }// w w w .ja va 2 s.c om return Optional.absent(); }
From source file:com.google.cloud.tools.gradle.appengine.core.task.ShowConfigurationTask.java
private static String spaces(int depth) { return Strings.repeat(" ", depth); }
From source file:com.mycelium.wallet.LedgerPinDialog.java
@Override protected void updatePinDisplay() { pinDisp.setText(Strings.repeat(PinDialog.PLACEHOLDER_TYPED, enteredPin.length())); checkPin(); }
From source file:com.brq.wallet.LedgerPinDialog.java
@Override protected void updatePinDisplay() { pinDisp.setText(Strings.repeat(PLACEHOLDER_TYPED, enteredPin.length())); checkPin(); }
From source file:org.shaf.server.util.HtmlDecorator.java
/** * Transforms the exceptions into HTML representation. * // w w w.j a va 2s .co m * @param source * the exception to decorate * @return the HTML representation of the exception. */ public static final String exception2html(final String source) { String colorKeyword = "#000000"; String colorMessage = "#FF0000"; String colorClassInt = "#800000"; String colorClassExt = "#808080"; String colorMethod = "#000000"; String colorSource = "#000099"; String colorLineNumber = "#0000FF"; StringBuilder html = new StringBuilder(); for (String line : source.split("\n")) { try { if (!line.trim().isEmpty()) { if (line.trim().startsWith("...")) { html.append(colorize(colorKeyword, line)); } else if (line.trim().startsWith("Caused by:")) { String[] groups = getGroups("Caused\\sby\\:\\s([\\w\\.\\$]+)\\:?(.*)?", line); html.append(colorize(colorKeyword, "Caused by: ")); html.append("<b>"); if (groups[0].startsWith("org.shaf")) { html.append(colorize(colorClassInt, groups[0])); } else { html.append(colorize(colorClassExt, groups[0])); } if (groups.length > 1) { html.append(colorize(colorMessage, ": ")); html.append(colorize(colorMessage, groups[1])); } html.append("</b>"); } else if (line.trim().startsWith("at ")) { if (line.trim().contains("Native Method")) { String[] groups = getGroups("\\s+at\\s([\\w\\.\\$]+)\\.([\\w]+)\\(Native\\sMethod\\)", line); html.append(colorize(colorKeyword, Strings.repeat(" ", 5) + "at ")); html.append(colorize(colorClassExt, groups[0])); html.append(colorize(colorKeyword, ".")); html.append(colorize(colorMethod, groups[1])); html.append(colorize(colorKeyword, "(")); html.append(colorize(colorSource, "Native Method")); html.append(colorize(colorKeyword, ")")); } else { String[] groups = getGroups( "\\s+at\\s([\\w\\.\\$]+)\\.([\\w]+)\\((.*\\.java)\\:(\\d+)\\)", line); html.append(colorize(colorKeyword, Strings.repeat(" ", 5) + "at ")); if (groups[0].startsWith("org.shaf")) { html.append(colorize(colorClassInt, (groups[0]))); } else { html.append(colorize(colorClassExt, (groups[0]))); } html.append(colorize(colorKeyword, ".")); html.append(colorize(colorMethod, groups[1])); html.append(colorize(colorKeyword, "(")); html.append(colorize(colorSource, groups[2])); html.append(colorize(colorKeyword, ":")); html.append(colorize(colorLineNumber, groups[3])); html.append(colorize(colorKeyword, ")")); } } else { html.append("<b>"); String[] groups = getGroups("([\\w\\.\\$]+)(\\:.*)?", line); if (groups[0].startsWith("org.shaf")) { html.append(colorize(colorClassInt, groups[0])); } else { html.append(colorize(colorClassExt, groups[0])); } if (groups.length > 1) { html.append(colorize(colorMessage, groups[1])); } html.append("</b>"); } } } catch (Exception exc) { LOG.error("Failed to decorate a part of exception trace: \"" + line + "\".", exc); html.append(line); } html.append("<br/>"); } return html.toString(); }
From source file:org.asoem.greyfish.cli.ExperimentMonitorService.java
private void replaceStatusLine(final String message, final boolean newLine) { writer.print("\r" + Strings.repeat(" ", lastMessage.length())); writer.print("\r" + message); if (newLine) { writer.println();/*from w w w .java 2s . c o m*/ } writer.flush(); lastMessage = message; }
From source file:google.registry.flows.EppController.java
/** Reads EPP XML, executes the matching flow, and returns an {@link EppOutput}. */ public EppOutput handleEppCommand(SessionMetadata sessionMetadata, TransportCredentials credentials, EppRequestSource eppRequestSource, boolean isDryRun, boolean isSuperuser, byte[] inputXmlBytes) { metricBuilder.setClientId(Optional.fromNullable(sessionMetadata.getClientId())); metricBuilder.setPrivilegeLevel(isSuperuser ? "SUPERUSER" : "NORMAL"); try {// w w w.j a v a 2 s .c o m EppInput eppInput; try { eppInput = unmarshal(EppInput.class, inputXmlBytes); } catch (EppException e) { // Log the unmarshalling error, with the raw bytes (in base64) to help with debugging. logger.infofmt(e, "EPP request XML unmarshalling failed - \"%s\":\n%s\n%s\n%s\n%s", e.getMessage(), JSONValue.toJSONString(ImmutableMap.<String, Object>of("clientId", nullToEmpty(sessionMetadata.getClientId()), "resultCode", e.getResult().getCode().code, "resultMessage", e.getResult().getCode().msg, "xmlBytes", base64().encode(inputXmlBytes))), Strings.repeat("=", 40), new String(inputXmlBytes, UTF_8).trim(), // Charset decoding failures are swallowed. Strings.repeat("=", 40)); // Return early by sending an error message, with no clTRID since we couldn't unmarshal it. metricBuilder.setStatus(e.getResult().getCode()); return getErrorResponse(e.getResult(), Trid.create(null)); } metricBuilder.setCommandName(eppInput.getCommandName()); if (!eppInput.getTargetIds().isEmpty()) { metricBuilder.setEppTarget(Joiner.on(',').join(eppInput.getTargetIds())); } EppOutput output = runFlowConvertEppErrors(flowComponentBuilder.flowModule( new FlowModule.Builder().setSessionMetadata(sessionMetadata).setCredentials(credentials) .setEppRequestSource(eppRequestSource).setIsDryRun(isDryRun).setIsSuperuser(isSuperuser) .setInputXmlBytes(inputXmlBytes).setEppInput(eppInput).build()) .build()); if (output.isResponse()) { metricBuilder.setStatus(output.getResponse().getResult().getCode()); } return output; } finally { EppMetric metric = metricBuilder.build(); bigQueryMetricsEnqueuer.export(metric); eppMetrics.incrementEppRequests(metric); eppMetrics.recordProcessingTime(metric); } }