List of usage examples for java.lang String join
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)
From source file:io.pravega.test.system.MultiControllerTest.java
@Before public void setup() { Service zkService = new ZookeeperService("zookeeper"); Assert.assertTrue(zkService.isRunning()); List<URI> zkUris = zkService.getServiceDetails(); log.info("zookeeper service details: {}", zkUris); // Fetch the controller instances. List<URI> conUris = new ArrayList<>(); controllerServiceInstance1 = new PravegaControllerService("multicontroller1", zkUris.get(0)); Assert.assertTrue(controllerServiceInstance1.isRunning()); conUris.addAll(controllerServiceInstance1.getServiceDetails()); controllerServiceInstance2 = new PravegaControllerService("multicontroller2", zkUris.get(0)); Assert.assertTrue(controllerServiceInstance2.isRunning()); conUris.addAll(controllerServiceInstance2.getServiceDetails()); controllerServiceInstance3 = new PravegaControllerService("multicontroller3", zkUris.get(0)); Assert.assertTrue(controllerServiceInstance3.isRunning()); conUris.addAll(controllerServiceInstance3.getServiceDetails()); log.info("Pravega Controller service instance details: {}", conUris); // Fetch all the RPC endpoints and construct the client URIs. final List<String> uris = conUris.stream().filter(uri -> uri.getPort() == 9092).map(URI::getAuthority) .collect(Collectors.toList()); controllerURIDirect = URI.create("tcp://" + String.join(",", uris)); log.info("Controller Service direct URI: {}", controllerURIDirect); controllerURIDiscover = URI.create("pravega://" + String.join(",", uris)); log.info("Controller Service discovery URI: {}", controllerURIDiscover); }
From source file:gr.cti.android.experimentation.controller.ui.RestRankingController.java
@ResponseBody @RequestMapping(value = { "/results/{experimentId}/csv" }, method = RequestMethod.GET, produces = "text/csv") public String getResultsCsv(@PathVariable("experimentId") final int experimentId) { final Set<Result> results = resultRepository.findByExperimentId(experimentId); final StringBuilder resResponse = new StringBuilder(); final Set<String> headers = new HashSet<>(); for (final Result result : results) { try {// www . jav a 2 s. co m final HashMap<String, Object> dataMap = new ObjectMapper().readValue(result.getMessage(), new HashMap<String, Object>().getClass()); headers.addAll(dataMap.keySet()); } catch (IOException ignore) { } } headers.remove(LONGITUDE); headers.remove(LATITUDE); resResponse.append("timestamp,longitude,latitude,"); resResponse.append(String.join(",", headers)).append("\n"); for (final Result result : results) { final List<String> values = new ArrayList<>(); values.add(String.valueOf(result.getTimestamp())); try { final HashMap<String, Object> dataMap = new ObjectMapper().readValue(result.getMessage(), new HashMap<String, Object>().getClass()); values.add(String.valueOf(dataMap.get(LONGITUDE))); values.add(String.valueOf(dataMap.get(LATITUDE))); for (final String key : headers) { if (dataMap.containsKey(key)) { values.add(String.valueOf(dataMap.get(key))); } else { values.add(null); } } resResponse.append(String.join(",", values)).append("\n"); } catch (IOException e) { LOGGER.warn(e, e); } } return resResponse.toString(); }
From source file:it.uniud.ailab.dcore.annotation.annotators.RawTdidfAnnotator.java
private static void loadFile(File f, Locale locale) { BufferedReader br = null;//w ww . j av a 2 s. c o m StringBuilder document = new StringBuilder(); String line; int tokenCount = 0; try { br = new BufferedReader(new FileReader(f)); while ((line = br.readLine()) != null) { String[] tokenizedDocument = OpenNlpBootstrapperAnnotator.tokenizeText(line, locale.getLanguage()); SnowballStemmer stemmer = SnowballStemmerSelector.getStemmerForLanguage(locale); for (int i = 0; i < tokenizedDocument.length; i++) { stemmer.setCurrent(tokenizedDocument[i]); if (stemmer.stem()) { tokenizedDocument[i] = stemmer.getCurrent(); } } tokenCount += tokenizedDocument.length; document.append(String.join(" ", markTokens(tokenizedDocument)).trim()); document.append(" "); } } catch (FileNotFoundException e) { throw new AnnotationException(new RawTdidfAnnotator(), "Can't read the tf-idf database.", e); } catch (IOException e) { throw new AnnotationException(new RawTdidfAnnotator(), "Can't read the tf-idf database.", e); } finally { if (br != null) { try { br.close(); } catch (IOException e) { // don't care } } } String documentText = document.toString().trim(); documents.put(f.getAbsolutePath(), documentText); docLengths.put(f.getAbsolutePath(), tokenCount); }
From source file:com.github.cc007.headsplacer.commands.HeadsPlacerCommand.java
private boolean searchFirst(Player player, String[] args) { if (args.length < 2) { player.sendMessage(ChatColor.RED + "You need to specify a head! Use: /heads (search|searchfirst|searchatindex <index>) <head name>"); return false; }/*w w w . j a v a2 s .c o m*/ String[] searchArgs = new String[args.length - 1]; System.arraycopy(args, 1, searchArgs, 0, searchArgs.length); player.sendMessage(ChatColor.GREEN + "Placing head..."); try { ItemStack head = HeadCreator.getItemStack(plugin.getHeadsUtils().getHead(String.join(" ", searchArgs))); placeHeadAndGetInv(head, player, 0); player.sendMessage(ChatColor.GREEN + "Head placed."); return true; } catch (NullPointerException ex) { player.sendMessage(ChatColor.RED + "No heads found!"); return false; } }
From source file:org.createnet.raptor.auth.service.services.AclManagerService.java
@Retryable(maxAttempts = 3, value = AclManagerException.class, backoff = @Backoff(delay = 500, multiplier = 2)) public <T> void addPermissions(Class<T> clazz, Serializable identifier, Sid sid, List<Permission> permissions, Long parentId) {/*from w ww.j a va 2 s.co m*/ try { log.debug("Storing ACL {} {} {}:{}", sid, String.join(",", RaptorPermission.toLabel(permissions)), clazz, identifier); MutableAcl acl = getACL(clazz, identifier); permissions.stream().forEach((Permission p) -> { isPermissionGranted(p, sid, acl); }); if (parentId != null) { log.debug("Setting parent ACL to {}", parentId); MutableAcl parentAcl = getACL(clazz, parentId); acl.setEntriesInheriting(true); acl.setParent(parentAcl); } aclService.updateAcl(acl); } catch (NotFoundException ex) { log.debug("Storing ACL FAILED for {} {} {}:{}", sid, String.join(",", RaptorPermission.toLabel(permissions)), clazz, identifier); throw new AclManagerException(ex); } }
From source file:com.contrastsecurity.ide.eclipse.core.Util.java
public static String filterHeaders(String data, String separator) { String[] lines = data.split(separator); String[] headers = { "authorization:", "_tid:", ":" }; ArrayList<String> filtered = new ArrayList<>(); for (String line : lines) { boolean filteredLine = true; for (String header : headers) { if (line.toLowerCase().contains(header)) { if (!header.equals(":")) { filteredLine = false; } else { if (line.split(":")[0].toLowerCase().contains("token")) { filteredLine = false; }//from www.jav a 2s . co m } } } if (filteredLine) { filtered.add(line); } } return String.join(separator, filtered); }
From source file:com.viewer.servlets.ViewDocument.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.addHeader("Content-Type", "application/json"); ViewDocumentParameters params = new ObjectMapper().readValue(request.getInputStream(), ViewDocumentParameters.class); ViewDocumentResponse result = new ViewDocumentResponse(); FileData fileData = ViewerUtils.factoryFileData(params.getPath()); DocumentInfoContainer docInfo = null; try {//ww w . j a v a2 s .co m result.setDocumentDescription( (new FileDataJsonSerializer(fileData, new FileDataOptions())).Serialize(false)); } catch (ParseException x) { throw new ServletException(x); } if (params.getUseHtmlBasedEngine()) { try { docInfo = ViewerUtils.getViewerHtmlHandler() .getDocumentInfo(new DocumentInfoOptions(params.getPath())); } catch (Exception x) { throw new ServletException(x); } result.setPageCss(new String[0]); result.setLic(true); result.setPdfDownloadUrl(GetPdfDownloadUrl(params)); result.setPdfPrintUrl(GetPdfPrintUrl(params)); result.setUrl(GetFileUrl(params)); result.setPath(params.getPath()); result.setName(params.getPath()); try { result.setDocumentDescription( (new FileDataJsonSerializer(fileData, new FileDataOptions())).Serialize(false)); } catch (ParseException x) { throw new ServletException(x); } result.setDocType(docInfo.getDocumentType()); result.setFileType(docInfo.getFileType()); HtmlOptions htmlOptions = new HtmlOptions(); htmlOptions.setResourcesEmbedded(true); htmlOptions.setHtmlResourcePrefix("/GetResourceForHtml?documentPath=" + params.getPath() + "&pageNumber={page-number}&resourceName="); if (!DotNetToJavaStringHelper.isNullOrEmpty(params.getPreloadPagesCount().toString()) && params.getPreloadPagesCount().intValue() > 0) { htmlOptions.setPageNumber(1); htmlOptions.setCountPagesToConvert(params.getPreloadPagesCount().intValue()); } String[] cssList = null; RefObject<ArrayList<String>> tempRef_cssList = new RefObject<ArrayList<String>>(cssList); List<PageHtml> htmlPages; try { htmlPages = GetHtmlPages(params.getPath(), htmlOptions); cssList = tempRef_cssList.argValue; ArrayList<String> pagesContent = new ArrayList<String>(); for (PageHtml page : htmlPages) { pagesContent.add(page.getHtmlContent()); } String[] htmlContent = pagesContent.toArray(new String[0]); result.setPageHtml(htmlContent); result.setPageCss(new String[] { String.join(" ", temp_cssList) }); for (int i = 0; i < result.getPageHtml().length; i++) { String html = result.getPageHtml()[i]; int indexOfScript = html.indexOf("script"); if (indexOfScript > 0) { result.getPageHtml()[i] = html.substring(0, indexOfScript); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { try { docInfo = ViewerUtils.getViewerImageHandler() .getDocumentInfo(new DocumentInfoOptions(params.getPath())); } catch (Exception x) { throw new ServletException(x); } int maxWidth = 0; int maxHeight = 0; for (PageData pageData : docInfo.getPages()) { if (pageData.getHeight() > maxHeight) { maxHeight = pageData.getHeight(); maxWidth = pageData.getWidth(); } } fileData.setDateCreated(new Date()); fileData.setDateModified(docInfo.getLastModificationDate()); fileData.setPageCount(docInfo.getPages().size()); fileData.setPages(docInfo.getPages()); fileData.setMaxWidth(maxWidth); fileData.setMaxHeight(maxHeight); result.setPageCss(new String[0]); result.setLic(true); result.setPdfDownloadUrl(GetPdfDownloadUrl(params)); result.setPdfPrintUrl(GetPdfPrintUrl(params)); result.setUrl(GetFileUrl(params.getPath(), true, false, params.getFileDisplayName(), params.getWatermarkText(), params.getWatermarkColor(), params.getWatermarkPostion(), params.getWatermarkWidth(), params.getIgnoreDocumentAbsence(), params.getUseHtmlBasedEngine(), params.getSupportPageRotation())); result.setPath(params.getPath()); result.setName(params.getPath()); result.setDocType(docInfo.getDocumentType()); result.setFileType(docInfo.getFileType()); int[] pageNumbers = new int[docInfo.getPages().size()]; int count = 0; for (PageData page : docInfo.getPages()) { pageNumbers[count] = page.getNumber(); count++; } String applicationHost = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); String[] imageUrls = ImageUrlHelper.GetImageUrls(applicationHost, pageNumbers, params); result.setImageUrls(imageUrls); } new ObjectMapper().writeValue(response.getOutputStream(), result); }
From source file:cc.recommenders.io.ZipFolderLRUCacheTest.java
private String relFile(String... tokens) { return String.join(File.separator, tokens); }
From source file:com.nestedbird.modules.facebookreader.FacebookReader.java
/** * Generates the URL to request the data from facebook with * * @param id the identifier of the resource * @param nestedItem a child identifier/* w w w . j av a2 s.com*/ * @param fields what info are we requesing * @return the url */ private String generateRequestUrl(final String id, final String nestedItem, final String[] fields) { return String.format("https://graph.facebook.com/%s/%s/?fields=%s&access_token=%s&limit=60", id, nestedItem, String.join(",", fields), socialConfigSettings.getFbAccessToken()); }
From source file:sample.fa.ScriptRunnerApplication.java
void loadScript(File f) { try {//from ww w .ja v a 2s . c o m scriptContents.setText(String.join("\n", Files.readAllLines(f.toPath()))); String name = f.getName(); int lastDot = name.lastIndexOf('.'); if (lastDot >= 0) { String extension = name.substring(lastDot + 1); for (int i = 0; i < languagesModel.getSize(); i++) { ScriptEngine se = languagesModel.getElementAt(i); if (se.getFactory().getExtensions().indexOf(extension) >= 0) { languagesModel.setSelectedItem(se); break; } } } } catch (IOException ex) { JOptionPane.showMessageDialog(scriptContents, ex.getMessage(), "Error Loading Script", JOptionPane.ERROR_MESSAGE); } }