List of usage examples for com.google.common.base Strings repeat
public static String repeat(String string, int count)
From source file:org.syncany.cli.AbstractInitCommand.java
@Override public boolean onUserConfirm(String header, String message, String question) { if (header != null) { out.println();/*from ww w .j ava 2 s . co m*/ out.println(header); out.println(Strings.repeat("-", header.length())); } out.println(message); out.println(); String yesno = console.readLine(question + " (y/n)? "); if (!yesno.toLowerCase().startsWith("y") && !"".equals(yesno)) { return false; } else { return true; } }
From source file:com.netflix.client.config.DefaultClientConfigImpl.java
@Override public String toString() { final StringBuilder sb = new StringBuilder(); String separator = ""; sb.append("ClientConfig:"); for (IClientConfigKey key : CommonClientConfigKey.values()) { final Object value = getProperty(key); sb.append(separator);//from w w w .ja v a 2 s . co m separator = ", "; sb.append(key).append(":"); if (key.key().endsWith("Password") && value instanceof String) { sb.append(Strings.repeat("*", ((String) value).length())); } else { sb.append(value); } } return sb.toString(); }
From source file:org.syncany.cli.AbstractInitCommand.java
@Override public String onUserPassword(String header, String message) { if (!isInteractive) { throw new RuntimeException( "Repository is encrypted, but no password was given in non-interactive mode."); }//from w w w.j av a 2s .c o m out.println(); if (header != null) { out.println(header); out.println(Strings.repeat("-", header.length())); } if (!message.trim().endsWith(":")) { message += ": "; } char[] passwordChars = console.readPassword(message); return String.copyValueOf(passwordChars); }
From source file:net.minecraftforge.fml.client.FMLClientHandler.java
public void logMissingTextureErrors() { if (missingTextures.isEmpty() && brokenTextures.isEmpty()) { return;//from w ww . j a v a 2 s .c o m } Logger logger = LogManager.getLogger("TEXTURE ERRORS"); logger.error(Strings.repeat("+=", 25)); logger.error("The following texture errors were found."); Map<String, FallbackResourceManager> resManagers = ObfuscationReflectionHelper.getPrivateValue( SimpleReloadableResourceManager.class, (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(), "domainResourceManagers", "field_110548" + "_a"); for (String resourceDomain : missingTextures.keySet()) { Set<ResourceLocation> missing = missingTextures.get(resourceDomain); logger.error(Strings.repeat("=", 50)); logger.error(" DOMAIN {}", resourceDomain); logger.error(Strings.repeat("-", 50)); logger.error(" domain {} is missing {} texture{}", resourceDomain, missing.size(), missing.size() != 1 ? "s" : ""); FallbackResourceManager fallbackResourceManager = resManagers.get(resourceDomain); if (fallbackResourceManager == null) { logger.error( " domain {} is missing a resource manager - it is probably a side-effect of automatic texture processing", resourceDomain); } else { List<IResourcePack> resPacks = ObfuscationReflectionHelper.getPrivateValue( FallbackResourceManager.class, fallbackResourceManager, "resourcePacks", "field_110540" + "_a"); logger.error(" domain {} has {} location{}:", resourceDomain, resPacks.size(), resPacks.size() != 1 ? "s" : ""); for (IResourcePack resPack : resPacks) { if (resPack instanceof FMLContainerHolder) { FMLContainerHolder containerHolder = (FMLContainerHolder) resPack; ModContainer fmlContainer = containerHolder.getFMLContainer(); logger.error(" mod {} resources at {}", fmlContainer.getModId(), fmlContainer.getSource().getPath()); } else if (resPack instanceof AbstractResourcePack) { AbstractResourcePack resourcePack = (AbstractResourcePack) resPack; File resPath = ObfuscationReflectionHelper.getPrivateValue(AbstractResourcePack.class, resourcePack, "resourcePackFile", "field_110597" + "_b"); logger.error(" resource pack at path {}", resPath.getPath()); } else { logger.error(" unknown resourcepack type {} : {}", resPack.getClass().getName(), resPack.getPackName()); } } } logger.error(Strings.repeat("-", 25)); logger.error(" The missing resources for domain {} are:", resourceDomain); for (ResourceLocation rl : missing) { logger.error(" {}", rl.getResourcePath()); } logger.error(Strings.repeat("-", 25)); if (!brokenTextures.containsRow(resourceDomain)) { logger.error(" No other errors exist for domain {}", resourceDomain); } else { logger.error(" The following other errors were reported for domain {}:", resourceDomain); Map<String, Set<ResourceLocation>> resourceErrs = brokenTextures.row(resourceDomain); for (String error : resourceErrs.keySet()) { logger.error(Strings.repeat("-", 25)); logger.error(" Problem: {}", error); for (ResourceLocation rl : resourceErrs.get(error)) { logger.error(" {}", rl.getResourcePath()); } } } logger.error(Strings.repeat("=", 50)); } logger.error(Strings.repeat("+=", 25)); }
From source file:org.glowroot.central.storage.AggregateDao.java
private static String insertPS(Table table, boolean transaction, int i) { StringBuilder sb = new StringBuilder(); sb.append("insert into "); sb.append(getTableName(table.partialName(), transaction, i)); sb.append(" (server_rollup, transaction_type"); if (transaction) { sb.append(", transaction_name"); }// w ww.ja v a 2 s .com sb.append(", capture_time"); for (Column column : table.columns()) { sb.append(", "); sb.append(column.name()); } sb.append(") values (?, ?, ?"); if (transaction) { sb.append(", ?"); } sb.append(Strings.repeat(", ?", table.columns().size())); sb.append(")"); return sb.toString(); }
From source file:com.chiorichan.http.HttpHandler.java
@Override protected void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception { Timings.start(this); if (msg instanceof FullHttpRequest) { if (AppLoader.instances().get(0).runLevel() != RunLevel.RUNNING) { // Outputs a very crude raw message if we are running in a low level mode a.k.a. Startup or Reload. // While in the mode, much of the server API is potentially unavailable, that is why we do this. StringBuilder sb = new StringBuilder(); sb.append("<h1>503 - Service Unavailable</h1>\n"); sb.append(//from w ww. j av a 2s. c o m "<p>I'm sorry to have to be the one to tell you this but the server is currently unavailable.</p>\n"); sb.append( "<p>This is most likely due to many possibilities, most commonly being it's currently booting up. Which would be great news because it means your request should succeed if you try again.</p>\n"); sb.append( "<p>But it is also possible that the server is actually running in a low level mode or could be offline for some other reason. If you feel this is a mistake, might I suggest you talk with the server admin.</p>\n"); sb.append("<p><i>You have a good day now and we will see you again soon. :)</i></p>\n"); sb.append("<hr>\n"); sb.append("<small>Running <a href=\"https://github.com/ChioriGreene/ChioriWebServer\">" + Versioning.getProduct() + "</a> Version " + Versioning.getVersion() + " (Build #" + Versioning.getBuildNumber() + ")<br />" + Versioning.getCopyright() + "</small>"); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(503), Unpooled.wrappedBuffer(sb.toString().getBytes())); ctx.write(response); return; } requestFinished = false; requestOrig = (FullHttpRequest) msg; request = new HttpRequestWrapper(ctx.channel(), requestOrig, this, ssl, log); response = request.getResponse(); String threadName = Thread.currentThread().getName(); if (threadName.length() > 10) threadName = threadName.substring(0, 2) + ".." + threadName.substring(threadName.length() - 6); else if (threadName.length() < 10) threadName = threadName + Strings.repeat(" ", 10 - threadName.length()); log.header("&7[&d%s&7] %s %s [&9%s:%s&7] -> [&a%s:%s&7]", threadName, dateFormat.format(Timings.millis()), timeFormat.format(Timings.millis()), request.getIpAddr(), request.getRemotePort(), request.getLocalIpAddr(), request.getLocalPort()); if (HttpHeaderUtil.is100ContinueExpected((HttpRequest) msg)) send100Continue(ctx); if (NetworkSecurity.isIpBanned(request.getIpAddr())) { response.sendError(403); return; } Site currentSite = request.getLocation(); File tmpFileDirectory = currentSite != null ? currentSite.directoryTemp() : AppConfig.get().getDirectoryCache(); setTempDirectory(tmpFileDirectory); if (request.isWebsocketRequest()) { try { WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory( request.getWebSocketLocation(requestOrig), null, true); handshaker = wsFactory.newHandshaker(requestOrig); if (handshaker == null) WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()); else handshaker.handshake(ctx.channel(), requestOrig); } catch (WebSocketHandshakeException e) { NetworkManager.getLogger().severe( "A request was made on the websocket uri '/fw/websocket' but it failed to handshake for reason '" + e.getMessage() + "'."); response.sendError(500, null, "This URI is for websocket requests only<br />" + e.getMessage()); } return; } if (request.method() != HttpMethod.GET) try { decoder = new HttpPostRequestDecoder(factory, requestOrig); } catch (ErrorDataDecoderException e) { e.printStackTrace(); response.sendException(e); return; } request.contentSize += requestOrig.content().readableBytes(); if (decoder != null) { try { decoder.offer(requestOrig); } catch (ErrorDataDecoderException e) { e.printStackTrace(); response.sendError(e); // ctx.channel().close(); return; } catch (IllegalArgumentException e) { // TODO Handle this further? maybe? // java.lang.IllegalArgumentException: empty name } readHttpDataChunkByChunk(); } handleHttp(); finish(); } else if (msg instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) msg; // Check for closing frame if (frame instanceof CloseWebSocketFrame) { handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain()); return; } if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (!(frame instanceof TextWebSocketFrame)) throw new UnsupportedOperationException( String.format("%s frame types are not supported", frame.getClass().getName())); String request = ((TextWebSocketFrame) frame).text(); NetworkManager.getLogger() .fine("Received '" + request + "' over WebSocket connection '" + ctx.channel() + "'"); ctx.channel().write(new TextWebSocketFrame(request.toUpperCase())); } else if (msg instanceof DefaultHttpRequest) { // Do Nothing! } else NetworkManager.getLogger().warning( "Received Object '" + msg.getClass() + "' and had nothing to do with it, is this a bug?"); }
From source file:org.glowroot.central.storage.AggregateDao.java
private static String insertSummaryPS(Table table, boolean transaction, int i) { StringBuilder sb = new StringBuilder(); sb.append("insert into "); sb.append(getTableName(table.partialName(), transaction, i)); sb.append(" (server_rollup, transaction_type, capture_time"); if (transaction) { sb.append(", transaction_name"); }/* w ww . j av a 2s . c o m*/ for (Column column : table.columns()) { sb.append(", "); sb.append(column.name()); } sb.append(") values (?, ?, ?"); if (transaction) { sb.append(", ?"); } sb.append(Strings.repeat(", ?", table.columns().size())); sb.append(")"); return sb.toString(); }
From source file:net.sourceforge.vaticanfetcher.util.Util.java
/** * Equivalent to {@link File#createTempFile(String, String, File)}, except: * <ul>/*ww w . j a va2 s . c om*/ * <li>The returned file will be deleted automatically after JVM shutdown. * <li>Unlike {@link File#createTempFile(String, String, File)}, this method * will not throw an exception if the prefix is shorter than 3 characters. * Instead, the prefix will be right-padded with underscores to make it 3 characters long. * </ul> * * @see {@link File#createTempFile(String, String, File)} */ @SuppressAjWarnings public static File createTempFile(@NotNull String prefix, @Nullable String suffix, @Nullable File directory) throws IOException { int prefixLength = prefix.length(); if (prefixLength < 3) prefix += Strings.repeat("_", 3 - prefixLength); File file = File.createTempFile(prefix, suffix, directory); /* * On Mac OS X, File.createTempFile() will give us a symlink to a file, which is not what we want, because our * file walker will silently ignore symlinks. The workaround is to return a canonical file on Mac OS X. */ if (Util.IS_MAC_OS_X) file = file.getCanonicalFile(); file.deleteOnExit(); return file; }
From source file:net.sourceforge.docfetcher.util.Util.java
/** * Equivalent to {@link File#createTempFile(String, String, File)}, except: * <ul>/*from w w w . ja v a 2 s. c o m*/ * <li>The returned file will be deleted automatically after JVM shutdown. * <li>Unlike {@link File#createTempFile(String, String, File)}, this method * will not throw an exception if the prefix is shorter than 3 characters. * Instead, the prefix will be right-padded with underscores to make it 3 * characters long. * </ul> * * @see {@link File#createTempFile(String, String, File)} */ @SuppressAjWarnings public static File createTempFile(@NotNull String prefix, @Nullable String suffix, @Nullable File directory) throws IOException { int prefixLength = prefix.length(); if (prefixLength < 3) prefix += Strings.repeat("_", 3 - prefixLength); File file = File.createTempFile(prefix, suffix, directory); /* * On Mac OS X, File.createTempFile() will give us a symlink to a file, * which is not what we want, because our file walker will silently * ignore symlinks. The workaround is to return a canonical file on Mac * OS X. */ if (Util.IS_MAC_OS_X) file = file.getCanonicalFile(); file.deleteOnExit(); return file; }
From source file:org.guldenj.utils.BtcFormat.java
/** Return a representation of the pattern used by this instance for formatting and * parsing. The format is similar to, but not the same as the format recognized by the * {@link Builder#pattern} and {@link Builder#localizedPattern} methods. The pattern * returned by this method is localized, any currency signs expressed are literally, and * optional fractional decimal places are shown grouped in parentheses. */ public String pattern() { synchronized (numberFormat) { StringBuilder groups = new StringBuilder(); for (int group : decimalGroups) { groups.append("(").append(Strings.repeat("#", group)).append(")"); }//from ww w . j a v a2s .c om DecimalFormatSymbols s = numberFormat.getDecimalFormatSymbols(); String digit = String.valueOf(s.getDigit()); String exp = s.getExponentSeparator(); String groupSep = String.valueOf(s.getGroupingSeparator()); String moneySep = String.valueOf(s.getMonetaryDecimalSeparator()); String zero = String.valueOf(s.getZeroDigit()); String boundary = String.valueOf(s.getPatternSeparator()); String minus = String.valueOf(s.getMinusSign()); String decSep = String.valueOf(s.getDecimalSeparator()); String prefixAndNumber = "(^|" + boundary + ")" + "([^" + Matcher.quoteReplacement(digit + zero + groupSep + decSep + moneySep) + "']*('[^']*')?)*" + "[" + Matcher.quoteReplacement(digit + zero + groupSep + decSep + moneySep + exp) + "]+"; return numberFormat.toLocalizedPattern().replaceAll(prefixAndNumber, "$0" + groups.toString()) .replaceAll("", Matcher.quoteReplacement(coinCode())) .replaceAll("", Matcher.quoteReplacement(coinSymbol())); } }