List of usage examples for java.lang String join
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)
From source file:com.orange.clara.cloud.servicedbdumper.service.DbDumperServiceInstanceService.java
private void restoreDump(Map<String, Object> parameters, DbDumperServiceInstance dbDumperServiceInstance) throws ServiceBrokerException, RestoreException { String targetUrl = getParameterAsString(parameters, TARGET_URL_PARAMETER, null); if (targetUrl == null) { targetUrl = getParameterAsString(parameters, NEW_TARGET_URL_PARAMETER); }/*ww w. j a v a 2 s . c om*/ String createdAtString = getParameterAsString(parameters, CREATED_AT_PARAMETER, null); DatabaseRef databaseRefTarget = this.getDatabaseRefFromParams(parameters, targetUrl); if (createdAtString == null || createdAtString.isEmpty()) { this.jobFactory.createJobRestoreDump(databaseRefTarget, null, dbDumperServiceInstance); return; } Date createdAt; try { createdAt = this.parseDate(createdAtString); } catch (ParseException e) { throw new ServiceBrokerException( "When use " + CREATED_AT_PARAMETER + " parameter you should pass a date in one of this forms: " + String.join(", ", VALID_DATES_FORMAT)); } this.jobFactory.createJobRestoreDump(databaseRefTarget, createdAt, dbDumperServiceInstance); }
From source file:com.formkiq.core.service.generator.docx4j.WorkflowOutputWordDocxTest.java
/** * testGetOutputFormFields01()./*from w w w . j a v a 2 s .co m*/ * @throws Exception Exception */ @Test public void testGenerate01() throws Exception { // given String filename = "sample1.docx"; ArchiveDTO archive = ObjectBuilder.buildArchiveDTO("test"); byte[] data = Resources.getResourceAsBytes("/sample1.docx"); // when this.woutput.generate(archive, filename, data); // then final int fieldCount = 21; assertEquals(1, archive.getWorkflow().getSteps().size()); assertEquals(0, archive.getWorkflow().getPrintsteps().size()); assertEquals(1, archive.getForms().size()); FormJSON form = archive.getForms().values().iterator().next(); assertNotNull(form.getUUID()); assertEquals("sample1", form.getName()); assertEquals(1, form.getSections().size()); List<FormJSONField> fields = form.getSections().get(0).getFields(); assertEquals(fieldCount, fields.size()); int i = 0; assertField(fields.get(i++), "DAY", TEXTBOX); assertField(fields.get(i++), "Month", TEXTBOX); assertField(fields.get(i++), "Year", TEXTBOX); assertField(fields.get(i++), "LegalName", TEXTBOX); assertField(fields.get(i++), "Trade Name", TEXTBOX); assertField(fields.get(i++), "ADDRESS", TEXTBOX); assertField(fields.get(i++), "SUITE", TEXTBOX); assertField(fields.get(i++), "CITY", TEXTBOX); assertField(fields.get(i++), "PROVINCE", TEXTBOX); assertField(fields.get(i++), "POSTALCODE", TEXTBOX); assertField(fields.get(i++), "FAX NUMBER", TEXTBOX); assertField(fields.get(i++), "CONTACT NAME", TEXTBOX); assertField(fields.get(i++), "CONTACT TITLE", TEXTBOX); assertField(fields.get(i++), "EMAIL", TEXTBOX); assertField(fields.get(i++), "Lease Date", DATE); FormJSONField field = fields.get(i++); assertEquals("Driver's License", field.getLabel()); assertEquals(SWITCH, field.getType()); assertEquals("Driver's License[Driver's License]", String.join(",", field.getOptions())); assertEquals(IMMEDIATE, field.getRequired()); field = fields.get(i++); assertEquals("Passport", field.getLabel()); assertEquals(SWITCH, field.getType()); assertEquals("Passport[Passport]", String.join(",", field.getOptions())); assertEquals(IMMEDIATE, field.getRequired()); field = fields.get(i++); assertEquals("Checkbox", field.getLabel()); assertEquals(SWITCH, field.getType()); assertEquals("Checkbox[Checkbox]", String.join(",", field.getOptions())); assertEquals(IMMEDIATE, field.getRequired()); assertField(fields.get(i++), "SIG", TEXTBOX); assertField(fields.get(i++), "PRINT NAME", TEXTBOX); assertField(fields.get(i++), "TITLE", TEXTBOX); assertEquals(1, archive.getWorkflow().getOutputs().size()); WorkflowOutputDocument output = (WorkflowOutputDocument) archive.getWorkflow().getOutputs().get(0); assertEquals(WorkflowOutputDocumentType.DOCX, output.getInputDocumentType()); assertEquals(WorkflowOutputDocumentType.DOCX, output.getOutputDocumentType()); List<WorkflowOutputFormField> ofields = output.getFields(); assertEquals(fieldCount, ofields.size()); i = 0; String fn = form.getName() + "[" + form.getUUID() + "]"; assertOutput(ofields.get(i++), fn, "DAY[1]", "DAY"); assertOutput(ofields.get(i++), fn, "Month[2]", "Month"); assertOutput(ofields.get(i++), fn, "Year[3]", "Year"); assertOutput(ofields.get(i++), fn, "LegalName[4]", "LegalName"); assertOutput(ofields.get(i++), fn, "Trade Name[5]", "Trade Name"); assertOutput(ofields.get(i++), fn, "ADDRESS[6]", "ADDRESS"); assertOutput(ofields.get(i++), fn, "SUITE[7]", "SUITE"); assertOutput(ofields.get(i++), fn, "CITY[8]", "CITY"); assertOutput(ofields.get(i++), fn, "PROVINCE[9]", "PROVINCE"); assertOutput(ofields.get(i++), fn, "POSTALCODE[10]", "POSTALCODE"); assertOutput(ofields.get(i++), fn, "FAX NUMBER[11]", "FAX NUMBER"); assertOutput(ofields.get(i++), fn, "CONTACT NAME[12]", "CONTACT NAME"); assertOutput(ofields.get(i++), fn, "CONTACT TITLE[13]", "CONTACT TITLE"); assertOutput(ofields.get(i++), fn, "EMAIL[14]", "EMAIL"); assertOutput(ofields.get(i++), fn, "Lease Date[15]", "Lease Date"); assertOutput(ofields.get(i++), fn, "Driver's License[16]", "Driver's License"); assertOutput(ofields.get(i++), fn, "Passport[17]", "Passport"); assertOutput(ofields.get(i++), fn, "Checkbox[18]", "Checkbox"); assertOutput(ofields.get(i++), fn, "SIG[19]", "SIG"); assertOutput(ofields.get(i++), fn, "PRINT NAME[20]", "PRINT NAME"); assertOutput(ofields.get(i++), fn, "TITLE[21]", "TITLE"); assertNotNull(archive.getObjectByExtension(".docx")); assertEquals(1, archive.getObjects().size()); }
From source file:ddf.catalog.registry.transformer.RegistryServiceConverter.java
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) throws ConversionException { RegistryMetacardImpl meta = new RegistryMetacardImpl(RSMT); List<String> bindingTypes = new ArrayList<>(); String id = validateService(reader); meta.setAttribute(Metacard.ID, id);/* www. j ava 2 s.c o m*/ while (reader.hasMoreChildren()) { reader.moveDown(); switch (reader.getNodeName()) { case "rim:Slot": readTopLevelSlots(reader, meta); break; case "rim:Description": meta.setAttribute(Metacard.DESCRIPTION, readValue(reader)); break; case "rim:Name": meta.setAttribute(Metacard.TITLE, readValue(reader)); break; case "rim:VersionInfo": meta.setAttribute(Metacard.CONTENT_TYPE_VERSION, reader.getAttribute("versionName")); break; case "rim:Classification": readClassification(reader, meta); break; case "rim:ServiceBinding": bindingTypes.add(validateServiceBinding(reader)); break; } reader.moveUp(); } meta.setAttribute(RegistryServiceMetacardType.SERVICE_BINDING_TYPES, String.join(", ", bindingTypes)); return meta; }
From source file:com.spankingrpgs.scarletmoon.loader.EventLoader.java
private void verifyFields(JsonNode eventData) { List<String> missingFields = new ArrayList<>(); if (eventData.get("name") == null) { missingFields.add("name"); }//w w w . j a v a2 s . c om if (!missingFields.isEmpty()) { String msg = String.format("Character %s is missing fields:\n%s", eventData, String.join("\n", missingFields)); LOG.log(Level.SEVERE, msg); throw new IllegalArgumentException(msg); } }
From source file:net.sf.jabref.importer.fetcher.IEEEXploreFetcher.java
private BibEntry cleanup(BibEntry entry) { if (entry == null) { return null; }/*from w ww.j a v a 2 s . c om*/ // clean up title if (entry.hasField(FieldName.TITLE)) { String title = entry.getField(FieldName.TITLE); // USe the alt-text and replace image links title = title.replaceAll("[ ]?img src=[^ ]+ alt=\"([^\"]+)\">[ ]?", "\\$$1\\$"); // Try to sort out most of the /spl / conversions // Deal with this specific nested type first title = title.replaceAll("/sub /spl infin//", "\\$_\\\\infty\\$"); title = title.replaceAll("/sup /spl infin//", "\\$\\^\\\\infty\\$"); // Replace general expressions title = title.replaceAll("/[sS]pl ([^/]+)/", "\\$\\\\$1\\$"); // Deal with subscripts and superscripts title = SUPER_DETECTION_1.matcher(title).replaceAll(SUPER_TEXT_RESULT); title = SUB_DETECTION_1.matcher(title).replaceAll(SUB_TEXT_RESULT); title = SUPER_DETECTION_2.matcher(title).replaceAll(SUPER_TEXT_RESULT); title = SUB_DETECTION_2.matcher(title).replaceAll(SUB_TEXT_RESULT); // Replace \infin with \infty title = title.replaceAll("\\\\infin", "\\\\infty"); // Unit formatting if (Globals.prefs.getBoolean(JabRefPreferences.USE_UNIT_FORMATTER_ON_SEARCH)) { title = unitsToLatexFormatter.format(title); } // Automatic case keeping if (Globals.prefs.getBoolean(JabRefPreferences.USE_CASE_KEEPER_ON_SEARCH)) { title = protectTermsFormatter.format(title); } // Write back entry.setField(FieldName.TITLE, title); } // clean up author if (entry.hasField(FieldName.AUTHOR)) { String author = entry.getField(FieldName.AUTHOR); author = author.replaceAll("\\s+", " "); //reorder the "Jr." "Sr." etc to the correct ordering String[] authorSplit = author.split("(^\\s*|\\s*$|\\s+and\\s+)"); List<String> authorResult = new ArrayList<>(); for (String authorSplitPart : authorSplit) { authorResult.add(authorSplitPart.replaceAll("(.+?),(.+?),(.+)", "$1,$3,$2")); } author = String.join(" and ", authorResult); author = author.replace(".", ". ").replace(" ", " ").replace(". -", ".-").replace("; ", " and ") .replace(" ,", ",").replace(" ", " "); author = author.replaceAll("[ ,;]+$", ""); //TODO: remove trailing commas entry.setField(FieldName.AUTHOR, author); } // clean up month String month = entry.getField(FieldName.MONTH); if ((month != null) && !month.isEmpty()) { month = month.replace(".", ""); month = month.toLowerCase(); Matcher mm = MONTH_PATTERN.matcher(month); StringBuilder date = new StringBuilder(month); if (mm.find()) { if (mm.group(3).isEmpty()) { if (mm.group(2).isEmpty()) { date = new StringBuilder().append(mm.group(1)).append(','); } else { date = new StringBuilder().append('#').append(mm.group(2).substring(0, 3)).append('#'); if (!mm.group(1).isEmpty()) { date.append(' ').append(mm.group(1)).append(','); } } } else if (mm.group(2).isEmpty()) { if (mm.group(4).isEmpty()) { date.append(','); } else { date = new StringBuilder().append('#').append(mm.group(4).substring(0, 3)).append('#') .append(mm.group(1)).append("--").append(mm.group(3)).append(','); } } else { date = new StringBuilder().append('#').append(mm.group(2).substring(0, 3)).append('#') .append(mm.group(1)).append("--#").append(mm.group(4).substring(0, 3)).append('#') .append(mm.group(3)).append(','); } } entry.setField(FieldName.MONTH, date.toString()); } // clean up pages if (entry.hasField(FieldName.PAGES)) { String pages = entry.getField(FieldName.PAGES); String[] pageNumbers = pages.split("-"); if (pageNumbers.length == 2) { if (pageNumbers[0].equals(pageNumbers[1])) {// single page entry.setField(FieldName.PAGES, pageNumbers[0]); } else { entry.setField(FieldName.PAGES, pages.replace("-", "--")); } } } // clean up publication field String type = entry.getType(); String sourceField = ""; if ("article".equals(type)) { sourceField = FieldName.JOURNAL; entry.clearField("booktitle"); } else if ("inproceedings".equals(type)) { sourceField = "booktitle"; } if (entry.hasField(sourceField)) { String fullName = entry.getField(sourceField); if ("article".equals(type)) { int ind = fullName.indexOf(": Accepted for future publication"); if (ind > 0) { fullName = fullName.substring(0, ind); entry.setField(FieldName.YEAR, "to be published"); entry.clearField(FieldName.MONTH); entry.clearField(FieldName.PAGES); entry.clearField(FieldName.NUMBER); } String[] parts = fullName.split("[\\[\\]]"); //[see also...], [legacy...] fullName = parts[0]; if (parts.length == 3) { fullName += parts[2]; } String note = entry.getField("note"); if ("Early Access".equals(note)) { entry.setField(FieldName.YEAR, "to be published"); entry.clearField(FieldName.MONTH); entry.clearField(FieldName.PAGES); entry.clearField(FieldName.NUMBER); } } else { fullName = fullName.replace("Conference Proceedings", "Proceedings") .replace("Proceedings of", "Proceedings").replace("Proceedings.", "Proceedings"); fullName = fullName.replace("International", "Int."); fullName = fullName.replace("Symposium", "Symp."); fullName = fullName.replace("Conference", "Conf."); fullName = fullName.replace(" on", " ").replace(" ", " "); } Matcher m1 = PUBLICATION_PATTERN.matcher(fullName); String abrvPattern = ".*[^,] '?\\d+\\)?"; if (m1.find()) { String prefix = m1.group(2).trim(); String postfix = m1.group(1).trim(); String abrv = ""; String[] parts = prefix.split("\\. ", 2); if (parts.length == 2) { if (parts[0].matches(abrvPattern)) { prefix = parts[1]; abrv = parts[0]; } else { prefix = parts[0]; abrv = parts[1]; } } if (prefix.matches(abrvPattern)) { fullName = postfix + " " + prefix; } else { fullName = prefix + " " + postfix + " " + abrv; fullName = fullName.trim(); } } if ("article".equals(type)) { fullName = fullName.replace(" - ", "-"); //IEE Proceedings- fullName = fullName.trim(); if (Globals.prefs.getBoolean(JabRefPreferences.USE_IEEE_ABRV)) { fullName = abbreviationLoader .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs)) .getMedlineAbbreviation(fullName).orElse(fullName); } } if ("inproceedings".equals(type)) { Matcher m2 = PROCEEDINGS_PATTERN.matcher(fullName); if (m2.find()) { String prefix = m2.group(2); String postfix = m2.group(1).replaceAll("\\.$", ""); if (prefix.matches(abrvPattern)) { fullName = postfix.trim() + " " + prefix.trim(); } else { String abrv = ""; String[] parts = postfix.split("\\. ", 2); if (parts.length == 2) { if (parts[0].matches(abrvPattern)) { postfix = parts[1]; abrv = parts[0]; } else { postfix = parts[0]; abrv = parts[1]; } } fullName = prefix.trim() + " " + postfix.trim() + " " + abrv; } } fullName = fullName.trim(); fullName = fullName.replaceAll("^[tT]he ", "").replaceAll("^\\d{4} ", "").replaceAll("[,.]$", ""); String year = entry.getField(FieldName.YEAR); if (year != null) { fullName = fullName.replaceAll(", " + year + "\\.?", ""); } if (!fullName.contains("Abstract") && !fullName.contains("Summaries") && !fullName.contains("Conference Record")) { fullName = "Proc. " + fullName; } } entry.setField(sourceField, fullName); } // clean up abstract if (entry.hasField(FieldName.ABSTRACT)) { String abstr = entry.getField(FieldName.ABSTRACT); // Try to sort out most of the /spl / conversions // Deal with this specific nested type first abstr = abstr.replaceAll("/sub /spl infin//", "\\$_\\\\infty\\$"); abstr = abstr.replaceAll("/sup /spl infin//", "\\$\\^\\\\infty\\$"); // Replace general expressions abstr = abstr.replaceAll("/[sS]pl ([^/]+)/", "\\$\\\\$1\\$"); // Deal with subscripts and superscripts abstr = SUPER_DETECTION_1.matcher(abstr).replaceAll(SUPER_TEXT_RESULT); abstr = SUB_DETECTION_1.matcher(abstr).replaceAll(SUB_TEXT_RESULT); abstr = SUPER_DETECTION_2.matcher(abstr).replaceAll(SUPER_TEXT_RESULT); abstr = SUB_DETECTION_2.matcher(abstr).replaceAll(SUB_TEXT_RESULT); // Replace \infin with \infty abstr = abstr.replace("\\infin", "\\infty"); // Write back entry.setField(FieldName.ABSTRACT, abstr); } // Clean up url entry.getFieldOptional(FieldName.URL).ifPresent( url -> entry.setField(FieldName.URL, "http://ieeexplore.ieee.org" + url.replace("tp=&", ""))); // Replace ; as keyword separator entry.getFieldOptional(FieldName.KEYWORDS).ifPresent(keys -> entry.setField(FieldName.KEYWORDS, keys.replace(";", Globals.prefs.get(JabRefPreferences.KEYWORD_SEPARATOR)))); return entry; }
From source file:net.sf.jabref.gui.openoffice.OOBibBase.java
/** * This method inserts a cite marker in the text for the given BibEntry, * and may refresh the bibliography./*w ww . ja va 2s . c o m*/ * @param entries The entries to cite. * @param database The database the entry belongs to. * @param style The bibliography style we are using. * @param inParenthesis Indicates whether it is an in-text citation or a citation in parenthesis. * This is not relevant if numbered citations are used. * @param withText Indicates whether this should be a normal citation (true) or an empty * (invisible) citation (false). * @param sync Indicates whether the reference list should be refreshed. * @throws Exception */ public void insertEntry(List<BibEntry> entries, BibDatabase database, List<BibDatabase> allBases, OOBibStyle style, boolean inParenthesis, boolean withText, String pageInfo, boolean sync) throws Exception { try { XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor(); if (entries.size() > 1) { if (style.getBooleanCitProperty(OOBibStyle.MULTI_CITE_CHRONOLOGICAL)) { entries.sort(yearAuthorTitleComparator); } else { entries.sort(entryComparator); } } String keyString = String.join(",", entries.stream().map(BibEntry::getCiteKey).collect(Collectors.toList())); // Insert bookmark: String bName = getUniqueReferenceMarkName(keyString, withText ? inParenthesis ? OOBibBase.AUTHORYEAR_PAR : OOBibBase.AUTHORYEAR_INTEXT : OOBibBase.INVISIBLE_CIT); // If we should store metadata for page info, do that now: if (pageInfo != null) { LOGGER.info("Storing page info: " + pageInfo); setCustomProperty(bName, pageInfo); } xViewCursor.getText().insertString(xViewCursor, " ", false); if (style.isFormatCitations()) { XPropertySet xCursorProps = UnoRuntime.queryInterface(XPropertySet.class, xViewCursor); String charStyle = style.getCitationCharacterFormat(); try { xCursorProps.setPropertyValue(CHAR_STYLE_NAME, charStyle); } catch (UnknownPropertyException | PropertyVetoException | IllegalArgumentException | WrappedTargetException ex) { // Setting the character format failed, so we throw an exception that // will result in an error message for the user. Before that, // delete the space we inserted: xViewCursor.goLeft((short) 1, true); xViewCursor.setString(""); throw new UndefinedCharacterFormatException(charStyle); } } xViewCursor.goLeft((short) 1, false); Map<BibEntry, BibDatabase> databaseMap = new HashMap<>(); for (BibEntry entry : entries) { databaseMap.put(entry, database); } String citeText = style.isNumberEntries() ? "-" : style.getCitationMarker(entries, databaseMap, inParenthesis, null, null); insertReferenceMark(bName, citeText, xViewCursor, withText, style); xViewCursor.collapseToEnd(); xViewCursor.goRight((short) 1, false); XTextRange position = xViewCursor.getEnd(); if (sync) { // To account for numbering and for uniqiefiers, we must refresh the cite markers: updateSortedReferenceMarks(); refreshCiteMarkers(allBases, style); // Insert it at the current position: rebuildBibTextSection(allBases, style); } // Go back to the relevant position: xViewCursor.gotoRange(position, false); } catch (DisposedException ex) { // We need to catch this one here because the OpenOfficePanel class is // loaded before connection, and therefore cannot directly reference // or catch a DisposedException (which is in a OO jar file). throw new ConnectionLostException(ex.getMessage()); } }
From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.google.GoogleDistributedService.java
default List<Metadata.Items> getMetadata(AccountDeploymentDetails<GoogleAccount> details, SpinnakerRuntimeSettings runtimeSettings, List<ConfigSource> configSources, Integer version) { List<Metadata.Items> metadataItems = new ArrayList<>(); String deploymentName = details.getDeploymentName(); Metadata.Items items = new Metadata.Items().setKey("startup-script").setValue(getStartupScript()); metadataItems.add(items);/* ww w. j av a 2 s. c o m*/ items = new Metadata.Items().setKey("ssh-keys").setValue(GoogleProviderUtils.getSshPublicKey()); metadataItems.add(items); if (!configSources.isEmpty()) { DaemonTaskHandler.message("Mounting config in vault server"); GoogleVaultServerService vaultService = getVaultServerService(); VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings); String secretName = secretName("config-mounts", version); VaultConfigMountSet mountSet = VaultConfigMountSet.fromConfigSources(configSources); secretName = vaultService.writeVaultConfigMountSet(deploymentName, vault, secretName, mountSet); VaultConnectionDetails connectionDetails = buildConnectionDetails(details, runtimeSettings, secretName); DaemonTaskHandler.message("Placing vault connection details into instance metadata"); items = new Metadata.Items().setKey("vault_address").setValue(connectionDetails.getAddress()); metadataItems.add(items); items = new Metadata.Items().setKey("vault_token").setValue(connectionDetails.getToken()); metadataItems.add(items); items = new Metadata.Items().setKey("vault_secret").setValue(connectionDetails.getSecret()); metadataItems.add(items); } GoogleConsulServerService consulServerService = getConsulServerService(); RunningServiceDetails consulServerDetails = consulServerService.getRunningServiceDetails(details, runtimeSettings); Integer latestConsulVersion = consulServerDetails.getLatestEnabledVersion(); if (latestConsulVersion != null) { List<RunningServiceDetails.Instance> instances = consulServerDetails.getInstances() .get(latestConsulVersion); String instancesValue = String.join(" ", instances.stream().map(RunningServiceDetails.Instance::getId).collect(Collectors.toList())); items = new Metadata.Items().setKey("consul-members") // TODO(lwander) change to consul_members for consistency w/ vault .setValue(instancesValue); DaemonTaskHandler.message("Placing consul connection details into instance metadata"); metadataItems.add(items); } return metadataItems; }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testIndicesExist() { String[] indices = randomIndicesNames(1, 10); GetIndexRequest getIndexRequest = new GetIndexRequest().indices(indices); Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(getIndexRequest::indicesOptions, getIndexRequest::indicesOptions, expectedParams); setRandomLocal(getIndexRequest, expectedParams); setRandomHumanReadable(getIndexRequest, expectedParams); setRandomIncludeDefaults(getIndexRequest, expectedParams); final Request request = RequestConverters.indicesExist(getIndexRequest); assertEquals(HttpHead.METHOD_NAME, request.getMethod()); assertEquals("/" + String.join(",", indices), request.getEndpoint()); assertThat(expectedParams, equalTo(request.getParameters())); assertNull(request.getEntity());/*from ww w .j av a 2 s. c o m*/ }
From source file:it.uniud.ailab.dcore.launchers.Launcher.java
/** * Load the document trying different charsets. The charset tried, are, in * order://from w w w . j av a 2 s . c om * <ul> * <li>UTF-16;</li> * <li>UTF-8;</li> * <li>US-ASCII.</li> * </ul> * * @param filePath the path of the document * @return the text of the document * @throws IOException if the charset is not supported */ private static String loadDocument(File filePath) throws IOException { String document = ""; IOException exception = null; // try different charsets. if none is recognized, throw the // exception detected when reading. try { document = String.join(" ", Files.readAllLines(filePath.toPath(), StandardCharsets.UTF_8)); } catch (java.nio.charset.MalformedInputException e) { exception = e; } if (exception != null) { try { exception = null; document = String.join(" ", Files.readAllLines(filePath.toPath(), StandardCharsets.UTF_16)); } catch (java.nio.charset.MalformedInputException e) { exception = e; } } if (exception != null) { try { exception = null; document = String.join(" ", Files.readAllLines(filePath.toPath(), StandardCharsets.US_ASCII)); } catch (java.nio.charset.MalformedInputException e) { exception = e; } } // no charset has been recognized if (exception != null) { throw exception; } return document; }
From source file:com.formkiq.core.service.workflow.WorkflowEditorServiceImplTest.java
/** * testEventIdremoveprintstep01()// ww w.j a va2s .c om * remove print step. */ @Test public void testEventIdremoveprintstep01() { // given String[] fieldids = new String[] { "1" }; this.workflow.setPrintsteps(new ArrayList<>(Arrays.asList("1", "2", "3"))); // when expect(this.flow.getData()).andReturn(this.mockarchive); expect(this.mockarchive.getWorkflow()).andReturn(this.workflow); replayAll(); this.ws.eventIdremoveprintstep(this.flow, fieldids); // then verifyAll(); assertEquals("1,3", String.join(",", this.workflow.getPrintsteps())); }