List of usage examples for org.apache.commons.lang StringUtils chomp
public static String chomp(String str)
Removes one newline from end of a String if it's there, otherwise leave it alone.
From source file:ch.cyberduck.core.threading.BackgroundException.java
/** * @return Detailed message from the underlying cause. *//*from w ww . ja v a 2 s .c o m*/ public String getDetailedCauseMessage() { final Throwable cause = this.getCause(); StringBuilder buffer = new StringBuilder(); if (null != cause) { if (StringUtils.isNotBlank(cause.getMessage())) { String m = StringUtils.chomp(cause.getMessage()); buffer.append(m); if (!m.endsWith(".")) { buffer.append("."); } } if (cause instanceof ServiceException) { final ServiceException s3 = (ServiceException) cause; if (StringUtils.isNotBlank(s3.getResponseStatus())) { // HTTP method status buffer.append(" ").append(s3.getResponseStatus()).append("."); } if (StringUtils.isNotBlank(s3.getErrorMessage())) { // S3 protocol message buffer.append(" ").append(s3.getErrorMessage()); } } else if (cause instanceof SardineException) { final SardineException http = (SardineException) cause; if (StringUtils.isNotBlank(http.getResponsePhrase())) { buffer.delete(0, buffer.length()); // HTTP method status buffer.append(http.getResponsePhrase()).append("."); } } else if (cause instanceof org.jets3t.service.impl.rest.HttpException) { final org.jets3t.service.impl.rest.HttpException http = (org.jets3t.service.impl.rest.HttpException) cause; buffer.append(" ").append(http.getResponseCode()); if (StringUtils.isNotBlank(http.getResponseMessage())) { buffer.append(" ").append(http.getResponseMessage()); } } else if (cause instanceof CloudFrontServiceException) { final CloudFrontServiceException cf = (CloudFrontServiceException) cause; if (StringUtils.isNotBlank(cf.getErrorMessage())) { buffer.append(" ").append(cf.getErrorMessage()); } if (StringUtils.isNotBlank(cf.getErrorDetail())) { buffer.append(" ").append(cf.getErrorDetail()); } } else if (cause instanceof FilesException) { final FilesException cf = (FilesException) cause; final StatusLine status = cf.getHttpStatusLine(); if (null != status) { if (StringUtils.isNotBlank(status.getReasonPhrase())) { buffer.append(" ").append(status.getReasonPhrase()); } } } else if (cause instanceof AmazonServiceException) { final AmazonServiceException a = (AmazonServiceException) cause; final String status = a.getErrorCode(); if (StringUtils.isNotBlank(status)) { buffer.append(" ").append(status); } } } String message = buffer.toString(); if (!StringUtils.isEmpty(message)) { if (Character.isLetter(message.charAt(message.length() - 1))) { message = message + "."; } } return Locale.localizedString(message, "Error"); }
From source file:dkpro.similarity.experiments.wordpairs.io.WordPairReader.java
/** * Processes a text containing a word pair list. * Expected format of the list:/*from w w w. ja v a2 s. c om*/ * - each pair on a single line * - words separated by a the value indicated by the separator parameter (default ":"), e.g. 'car:automobile' * - followed by the gold standard value and two pos tags from the set (n,v,a) * - everything starting with the value indicated by the comment parameter (default "#") is ignored * @param cas The CAS. * @param document The document text to process. * @throws AnalysisEngineProcessException */ private void processDocument(JCas jcas, String document) throws CollectionException { // split document into lines String[] lines = document.split(LINE_SEP); int i = 0; int startOffset = 0; for (String line : lines) { i++; if (line.startsWith(commentChar)) { startOffset += line.length() + LINE_SEP.length(); continue; } String[] parts = line.split(separatorChar); if (parts.length < 2 || parts.length > 5) { this.getLogger().log(Level.SEVERE, "Wrong file format: " + line); throw new CollectionException(new Throwable("Wrong file format on line '" + i + " " + line + "'. It should be word1:word2:gold[:pos1:pos2]")); } Token token1 = new Token(jcas); token1.setBegin(startOffset); token1.setEnd((startOffset + parts[0].length())); token1.addToIndexes(); Token token2 = new Token(jcas); token2.setBegin(startOffset + parts[0].length() + 1); token2.setEnd(startOffset + parts[0].length() + 1 + parts[1].length()); token2.addToIndexes(); String goldValueString = parts[2]; double goldValue = -1.0; try { goldValue = new Double(goldValueString); } catch (NumberFormatException e) { this.getLogger().log(Level.INFO, "Wrong number format: " + goldValueString); startOffset += line.length() + LINE_SEP.length(); continue; } POS pos1 = new POS(jcas, token1.getBegin(), token1.getEnd()); pos1.setPosValue(parts[3]); pos1.addToIndexes(); POS pos2 = new POS(jcas, token2.getBegin(), token2.getEnd()); pos2.setPosValue(StringUtils.chomp(parts[4])); pos2.addToIndexes(); SemRelWordPair wordPairAnnotation = new SemRelWordPair(jcas); wordPairAnnotation.setBegin(token1.getBegin()); wordPairAnnotation.setEnd(token2.getEnd()); wordPairAnnotation.setWord1(token1.getCoveredText()); wordPairAnnotation.setWord2(token2.getCoveredText()); wordPairAnnotation.setToken1(token1); wordPairAnnotation.setToken2(token2); wordPairAnnotation.setPos1(pos1); wordPairAnnotation.setPos2(pos2); wordPairAnnotation.setGoldValue(goldValue); wordPairAnnotation.addToIndexes(); startOffset += line.length() + LINE_SEP.length(); } }
From source file:net.sf.jtmt.summarizers.LuceneSummarizer.java
/** * Search index./*from ww w .j a v a 2s.c o m*/ * * @param ramdir the ramdir * @param query the query * @return the string[] * @throws Exception the exception */ private String[] searchIndex(Directory ramdir, Query query) throws Exception { SortedMap<Integer, String> sentenceMap = new TreeMap<Integer, String>(); IndexSearcher searcher = new IndexSearcher(ramdir, true); TopDocs topDocs = searcher.search(query, numSentences); for (ScoreDoc scoreDoc : topDocs.scoreDocs) { int docId = scoreDoc.doc; Document doc = searcher.doc(docId); sentenceMap.put(scoreDoc.doc, StringUtils.chomp(doc.get("text"))); } searcher.close(); return sentenceMap.values().toArray(new String[0]); }
From source file:io.bitgrillr.gocddockerexecplugin.docker.DockerUtils.java
private static int execCommand(String containerId, Printer printer, String user, String cmd, String... args) throws DockerException, InterruptedException { JobConsoleLogger.getConsoleLogger().printLine((new StringBuilder()) .append("Creating exec instance for command ").append(getCommandString(cmd, args)).toString()); String[] cmdArray = new String[args.length + 1]; cmdArray[0] = cmd;/*from w w w. j a v a2 s. c om*/ System.arraycopy(args, 0, cmdArray, 1, args.length); // for whatever reason, unless all streams are attached, the exec barfs and no-one knows why // see https://github.com/spotify/docker-client/issues/513 List<ExecCreateParam> execCreateParams = new ArrayList<>(); execCreateParams.add(ExecCreateParam.attachStdout()); execCreateParams.add(ExecCreateParam.attachStderr()); execCreateParams.add(ExecCreateParam.attachStdin()); if (user != null) { execCreateParams.add(ExecCreateParam.user(user)); } final ExecCreation execCreation = getDockerClient().execCreate(containerId, cmdArray, execCreateParams.toArray(new ExecCreateParam[execCreateParams.size()])); if (execCreation.warnings() != null && !execCreation.warnings().isEmpty()) { for (final String warning : execCreation.warnings()) { JobConsoleLogger.getConsoleLogger() .printLine((new StringBuilder()).append("WARNING: ").append(warning).toString()); } } JobConsoleLogger.getConsoleLogger().printLine((new StringBuilder()).append("Created exec instance '") .append(execCreation.id()).append("'").toString()); JobConsoleLogger.getConsoleLogger().printLine((new StringBuilder()).append("Starting exec instance '") .append(execCreation.id()).append("'").toString()); try (final LogStream logStream = getDockerClient().execStart(execCreation.id())) { while (logStream.hasNext()) { final String logMessage = StringUtils .chomp(StandardCharsets.UTF_8.decode(logStream.next().content()).toString()); for (String logLine : logMessage.split("\n")) { printer.print(logLine); } } } final Integer exitStatus = getDockerClient().execInspect(execCreation.id()).exitCode(); if (exitStatus == null) { throw new IllegalStateException("Exit code of exec comand null"); } JobConsoleLogger.getConsoleLogger().printLine((new StringBuilder()).append("Exec instance '") .append(execCreation.id()).append("' exited with status ").append(exitStatus).toString()); return exitStatus; }
From source file:com.projity.dialog.FieldDialog.java
protected JComponent createFieldsPanel(FieldComponentMap map, Collection fields) { if (fields == null || fields.size() == 0) return null; FormLayout layout = new FormLayout("p, 3dlu, fill:160dlu:grow", //$NON-NLS-1$ StringUtils.chomp(StringUtils.repeat("p,3dlu,", fields.size()))); // repeats and gets rid of last comma //$NON-NLS-1$ DefaultFormBuilder builder = new DefaultFormBuilder(layout); map.append(builder, fields);//from w w w .j a va 2s . c om return builder.getPanel(); }
From source file:ddf.catalog.pubsub.command.ListCommandTest.java
private List<String> getConsoleOutputText(ByteArrayOutputStream buffer) { // Get console output as individual lines that are not whitespace or only new lines List<String> linesWithText = new ArrayList<String>(); String[] lines = buffer.toString().split("\n"); if (lines != null) { for (String line : lines) { String text = StringUtils.chomp(line); if (!StringUtils.isEmpty(text)) { linesWithText.add(text); }/*from w ww. java 2 s .c o m*/ } } return linesWithText; }
From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java
/** * @param file//from ww w. j a v a2 s . c o m * @param dstFile * @param hash */ protected void mergeFile(final File file, final File dstFile, final HashMap<String, Pair<String, String>> hash) { try { List<String> srcLines = (List<String>) FileUtils.readLines(file, "UTF8"); Vector<String> dstLines = new Vector<String>(); for (int i = 0; i < srcLines.size(); i++) { String line = srcLines.get(i); if (StringUtils.contains(line, "<string")) { String key = getKey(line); String text = null; if (key != null && hash.get(key) != null) { text = hash.get(key).first; } else { String txt = getText(line); text = translate(txt); System.out.println("[" + txt + "][" + text + "]"); } line = String.format(" <string name=\"%s\">%s</string>", key, text); } if (line.endsWith("\n")) { line = StringUtils.chomp(line); } dstLines.add(line); } /* System.out.println("----------"); for (String s : dstLines) { System.out.print(s); } */ FileUtils.writeLines(dstFile, "UTF8", dstLines); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:edu.ku.brc.ui.UIHelper.java
/** * Changes the Window indicator to shoe that it is modified * @param comp the Dialog/Frame/*from w ww .ja v a 2s. c o m*/ * @param isModified whether it is modified */ public static void setWindowModified(final Component comp, final boolean isModified) { if (comp != null) { if (comp instanceof JDialog) { //JDialog dlg = (JDialog)comp; //if (isMacOS_10_5_X) //{ // only works on JFrame // dlg.getRootPane().putClientProperty("JComponent.windowModified", isModified ? Boolean.TRUE : Boolean.FALSE); //} else //{ // dlg.setTitle(dlg.getTitle() + "*"); //} } else if (comp instanceof JFrame) { JFrame dlg = (JFrame) comp; if (isMacOS_10_5_X) { dlg.getRootPane().putClientProperty("JComponent.windowModified", isModified ? Boolean.TRUE : Boolean.FALSE); } else { String title; if (isModified) { title = dlg.getTitle() + "*"; } else { title = dlg.getTitle(); if (title.endsWith("*")) { title = StringUtils.chomp(title); } } dlg.setTitle(title); } } } }
From source file:org.apache.ambari.server.configuration.Configuration.java
private String readPasswordFromFile(String filePath, String defaultPassword) { if (filePath == null) { LOG.debug("DB password file not specified - using default"); return defaultPassword; } else {/* w w w . ja v a2 s . co m*/ LOG.debug("Reading password from file {}", filePath); String password; try { password = FileUtils.readFileToString(new File(filePath)); password = StringUtils.chomp(password); } catch (IOException e) { throw new RuntimeException("Unable to read database password", e); } return password; } }
From source file:org.archive.io.hdfs.HDFSWriterDocument.java
public String getRequestString() throws UnsupportedEncodingException { return StringUtils .chomp(new String(getRequestBytes(), getRequestOffset(), getRequestLength(), getValidCharset())); }