List of usage examples for java.lang String subSequence
public CharSequence subSequence(int beginIndex, int endIndex)
From source file:org.jgrapht.io.DOTImporter.java
/** * Unescape an HTML string DOT identifier. * * @param input the input//from w w w. j a va 2 s . c o m * @return the unescaped output */ private static String unescapeHtmlString(String input) { if (input.charAt(0) != '<' || input.charAt(input.length() - 1) != '>') { return input; } String noQuotes = input.subSequence(1, input.length() - 1).toString(); String unescaped = StringEscapeUtils.unescapeXml(noQuotes); return unescaped; }
From source file:com.igormaznitsa.jcp.utils.PreprocessorUtils.java
@Nonnull public static String replacePartByChar(@Nonnull final String text, final char chr, final int startPosition, final int length) { Assertions.assertTrue("Start position must be great or equals zero", startPosition >= 0); Assertions.assertTrue("Length must be great or equals zero", length >= 0); final StringBuilder result = new StringBuilder(text.length()); result.append(text.subSequence(0, Math.min(text.length(), startPosition))); for (int i = startPosition; i < Math.min(text.length(), startPosition + length); i++) { result.append(chr);/* w w w. j av a2s. co m*/ } result.append(text.subSequence(Math.min(startPosition + length, text.length()), text.length())); return result.toString(); }
From source file:at.gv.egiz.pdfas.cli.Main.java
private static void perform_sign(CommandLine cli) throws Exception { String configurationFile = null; if (cli.hasOption(CLI_ARG_CONF_SHORT)) { configurationFile = cli.getOptionValue(CLI_ARG_CONF_SHORT); } else {/* ww w . j a v a 2 s .c o m*/ configurationFile = STANDARD_CONFIG_LOCATION; deployConfigIfNotexisting(); } String positionString = null; if (cli.hasOption(CLI_ARG_POSITION_SHORT)) { positionString = cli.getOptionValue(CLI_ARG_POSITION_SHORT); } else { positionString = null; } String profilID = null; if (cli.hasOption(CLI_ARG_PROFILE_SHORT)) { profilID = cli.getOptionValue(CLI_ARG_PROFILE_SHORT); } String outputFile = null; if (cli.hasOption(CLI_ARG_OUTPUT_SHORT)) { outputFile = cli.getOptionValue(CLI_ARG_OUTPUT_SHORT); } String connector = null; if (cli.hasOption(CLI_ARG_CONNECTOR_SHORT)) { connector = cli.getOptionValue(CLI_ARG_CONNECTOR_SHORT); } String pdfFile = null; pdfFile = cli.getArgs()[cli.getArgs().length - 1]; File inputFile = new File(pdfFile); if (!inputFile.exists()) { throw new Exception("Input file does not exists"); } if (outputFile == null) { if (pdfFile.endsWith(".pdf")) { outputFile = pdfFile.subSequence(0, pdfFile.length() - ".pdf".length()) + "_signed.pdf"; } else { outputFile = pdfFile + "_signed.pdf"; } } File outputPdfFile = new File(outputFile); DataSource dataSource = new FileDataSource(inputFile); PdfAs pdfAs = null; pdfAs = PdfAsFactory.createPdfAs(new File(configurationFile)); Configuration configuration = pdfAs.getConfiguration(); FileOutputStream fos = new FileOutputStream(outputPdfFile, false); SignParameter signParameter = PdfAsFactory.createSignParameter(configuration, dataSource, fos); String id = UUID.randomUUID().toString(); signParameter.setTransactionId(id); System.out.println("Transaction: " + id); IPlainSigner slConnector = null; if (connector != null) { if (connector.equalsIgnoreCase("bku")) { slConnector = new PAdESSigner(new BKUSLConnector(configuration)); } else if (connector.equalsIgnoreCase("moa")) { slConnector = new PAdESSigner(new MOAConnector(configuration)); } else if (connector.equalsIgnoreCase("ks")) { String keystoreFilename = null; String keystoreAlias = null; String keystoreType = null; String keystoreStorepass = null; String keystoreKeypass = null; if (cli.hasOption(CLI_ARG_KEYSTORE_FILE_SHORT)) { keystoreFilename = cli.getOptionValue(CLI_ARG_KEYSTORE_FILE_SHORT); } if (cli.hasOption(CLI_ARG_KEYSTORE_ALIAS_SHORT)) { keystoreAlias = cli.getOptionValue(CLI_ARG_KEYSTORE_ALIAS_SHORT); } if (cli.hasOption(CLI_ARG_KEYSTORE_TYPE_SHORT)) { keystoreType = cli.getOptionValue(CLI_ARG_KEYSTORE_TYPE_SHORT); } if (cli.hasOption(CLI_ARG_KEYSTORE_STOREPASS_SHORT)) { keystoreStorepass = cli.getOptionValue(CLI_ARG_KEYSTORE_STOREPASS_SHORT); } if (cli.hasOption(CLI_ARG_KEYSTORE_KEYPASS_SHORT)) { keystoreKeypass = cli.getOptionValue(CLI_ARG_KEYSTORE_KEYPASS_SHORT); } if (keystoreFilename == null) { throw new Exception("You need to provide a keystore file if using ks connector"); } if (keystoreAlias == null) { throw new Exception("You need to provide a key alias if using ks connector"); } if (keystoreType == null) { keystoreType = "PKCS12"; System.out.println("Defaulting to " + keystoreType + " keystore type."); } if (keystoreStorepass == null) { keystoreStorepass = ""; } if (keystoreKeypass == null) { keystoreKeypass = ""; } slConnector = new PAdESSignerKeystore(keystoreFilename, keystoreAlias, keystoreStorepass, keystoreKeypass, keystoreType); } } if (slConnector == null) { slConnector = new PAdESSigner(new BKUSLConnector(configuration)); } signParameter.setPlainSigner(slConnector); signParameter.setDataSource(dataSource); signParameter.setSignaturePosition(positionString); signParameter.setSignatureProfileId(profilID); System.out.println("Starting signature for " + pdfFile); System.out.println("Selected signature Profile " + profilID); SignResult result = null; try { result = pdfAs.sign(signParameter); } finally { if (result != null) { Iterator<Entry<String, String>> infoIt = result.getProcessInformations().entrySet().iterator(); while (infoIt.hasNext()) { Entry<String, String> infoEntry = infoIt.next(); logger.debug("Process Information: {} = {}", infoEntry.getKey(), infoEntry.getValue()); } } } fos.close(); System.out.println("Signed document " + outputFile); }
From source file:org.faster.util.Strings.java
/** * ()/* ww w. j a v a 2 s . com*/ * * @param content * ?? * @param headFlag * * @param tailFlag * * @return */ private static String removeSpecifiedString(String content, String headFlag, String tailFlag) { int startIndex = content.indexOf(headFlag); if (startIndex < 0) { return content; } StringBuilder buf = new StringBuilder(); buf.append(content.substring(0, startIndex)); int endIndex = content.indexOf(tailFlag, startIndex); while ((startIndex = content.indexOf(headFlag, endIndex)) > 0) { buf.append(content.subSequence(endIndex, startIndex)); endIndex = content.indexOf(tailFlag, startIndex); } buf.append(content.substring(endIndex, content.length())); return buf.toString(); }
From source file:com.google.jenkins.flakyTestHandler.junit.FlakyCaseResult.java
static String possiblyTrimStdio(Collection<FlakyCaseResult> results, boolean keepLongStdio, String stdio) { // HUDSON-6516 if (stdio == null) { return null; }//from w ww . j a v a 2 s. c o m if (!isTrimming(results, keepLongStdio)) { return stdio; } int len = stdio.length(); int middle = len - HALF_MAX_SIZE * 2; if (middle <= 0) { return stdio; } return stdio.subSequence(0, HALF_MAX_SIZE) + "\n...[truncated " + middle + " chars]...\n" + stdio.subSequence(len - HALF_MAX_SIZE, len); }
From source file:hudson.tasks.junit.CaseResult.java
static String possiblyTrimStdio(Collection<CaseResult> results, boolean keepLongStdio, String stdio) { // HUDSON-6516 if (stdio == null) { return null; }//from ww w . j a va2 s. c o m if (keepLongStdio) { return stdio; } int len = stdio.length(); int halfMaxSize = halfMaxSize(results); int middle = len - halfMaxSize * 2; if (middle <= 0) { return stdio; } return stdio.subSequence(0, halfMaxSize) + "\n...[truncated " + middle + " chars]...\n" + stdio.subSequence(len - halfMaxSize, len); }
From source file:com.genentech.struchk.oeStruchk.OEStruchk.java
public static URL getResourceURL(Class<?> cls, String name) { String path = cls.getName().replace('.', '/'); path = path.subSequence(0, path.lastIndexOf('/') + 1) + name; return cls.getClassLoader().getResource(path); }
From source file:org.faster.util.Strings.java
/** * XMLnamespace/*from w w w . j a v a 2 s .co m*/ * * @param xml * XML * @return namespacexml */ public static String removeXmlNamespace(String xml) { String HEAD_FLAG = "xmlns="; String TAIL_FLAG = ">"; int startIndex = xml.indexOf(HEAD_FLAG); if (startIndex < 0) { return xml; } StringBuilder buf = new StringBuilder(); // startIndex - 1 is blank, so also to remove it buf.append(xml.substring(0, startIndex - 1)); int endIndex = xml.indexOf(TAIL_FLAG, startIndex); while ((startIndex = xml.indexOf(HEAD_FLAG, endIndex)) > 0) { buf.append(xml.subSequence(endIndex, startIndex - 1)); endIndex = xml.indexOf(TAIL_FLAG, startIndex); } buf.append(xml.substring(endIndex, xml.length())); return buf.toString(); }
From source file:io.fabric8.maven.core.handler.ProbeHandler.java
private HTTPGetAction getHTTPGetAction(String getUrl) { if (getUrl == null || !getUrl.subSequence(0, 4).toString().equalsIgnoreCase("http")) { return null; }/*from w ww. ja va 2 s . c o m*/ try { URL url = new URL(getUrl); return new HTTPGetAction(url.getHost(), null /* headers */, url.getPath(), new IntOrString(url.getPort()), url.getProtocol()); } catch (MalformedURLException e) { throw new IllegalArgumentException("Invalid URL " + getUrl + " given for HTTP GET readiness check"); } }
From source file:uk.co.threeonefour.ifictionary.web.pages.ExploreController.java
@RequestMapping(method = RequestMethod.GET) public String renderPage(Model model) { PegDownProcessor processor = new PegDownProcessor(); List<GameInfo> featuredGames = gameService.listFeaturedGames(); for (GameInfo featuredGame : featuredGames) { String description = featuredGame.getDescription(); if (description.length() > 200) { description = description.subSequence(0, 200) + "..."; }//from w w w. j a v a 2 s . c o m featuredGame.setDescription(processor.markdownToHtml(description)); } model.addAttribute("featuredGames", featuredGames); return "explore"; }