@Override public String toString() { return Strings.duration(currentTimeInMillis); } }
protected static String toString(List<ServerAddress> addresses) { return Strings.join(ADDRESS_DELIMITER, addresses); }
private void parse(String value, Function<String, Path> pathCreator, List<Path> result) { if (!Strings.isNullOrEmpty(value)) { Arrays.stream(value.split(",")).forEach(name -> result.add(pathCreator.apply(name))); } }
numThreads, collections.size(), Strings.join(", ", collections)); for (int i = 0; i != numThreads; ++i) { copyThreads.submit(() -> { numDocumentsCopied.addAndGet(numDocs); long duration = clock.currentTimeInMillis() - start; logger.info("Completing initial sync of {} documents from '{}' in {}", numDocs, id, Strings.duration(duration)); int remaining = collections.size() - numCollectionsCopied.get(); logger.info("Initial sync aborted after {} with {} of {} collections incomplete", Strings.duration(syncDuration), remaining, collections.size()); return false; collections.size(), numDocumentsCopied.get(), Strings.duration(syncDuration)); return true;
private List<ReplicationMessage.Column> transform(List<PgProto.DatumMessage> messageList, List<PgProto.TypeInfo> typeInfoList) { return IntStream.range(0, messageList.size()) .mapToObj(index -> { final PgProto.DatumMessage datum = messageList.get(index); final Optional<PgProto.TypeInfo> typeInfo = Optional.ofNullable(hasTypeMetadata() && typeInfoList != null ? typeInfoList.get(index) : null); final String columnName = Strings.unquoteIdentifierPart(datum.getColumnName()); final PostgresType type = typeRegistry.get((int)datum.getColumnType()); return new AbstractReplicationMessageColumn(columnName, type, typeInfo.map(PgProto.TypeInfo::getModifier).orElse(null), typeInfo.map(PgProto.TypeInfo::getValueOptional).orElse(Boolean.FALSE), hasTypeMetadata()) { @Override public Object getValue(PgConnectionSupplier connection, boolean includeUnknownDatatypes) { return PgProtoReplicationMessage.this.getValue(datum, connection, includeUnknownDatatypes); } @Override public String toString() { return datum.toString(); } }; }) .collect(Collectors.toList()); }
/** * Obtain a function that will replace variables in the supplied value with values from the supplied lookup function. * <p> * Variables may appear anywhere within a string value, and multiple variables can be used within the same value. Variables * take the form: * * <pre> * variable := '${' variableNames [ ':' defaultValue ] '}' * variableNames := variableName [ ',' variableNames ] * variableName := // any characters except ',' and ':' and '}' * defaultValue := // any characters except '}' * </pre> * * Note that <i>variableName</i> is the name used to look up a the property. * </p> * Notice that the syntax supports multiple <i>variables</i>. The logic will process the <i>variables</i> from let to right, * until an existing property is found. And at that point, it will stop and will not attempt to find values for the other * <i>variables</i>. * <p> * * @param replacementsByVariableName the function used to find the replacements for variable names; may not be null * @return the function that will replace variables in supplied strings; never null */ public static Function<String, String> replaceVariablesWith(Function<String, String> replacementsByVariableName) { return (value) -> { return replaceVariables(value, replacementsByVariableName); }; }
/** * @param lsnString - textual representation of Lsn * @return LSN converted from its textual representation */ public static Lsn valueOf(String lsnString) { return (lsnString == null || NULL_STRING.equals(lsnString)) ? NULL : new Lsn(Strings.hexStringToByteArray(lsnString.replace(":", ""))); }
private String rename(String[] nameNodes) { StringJoiner newName = new StringJoiner("."); int replaceIndex = fieldNodes.length - 1; int i = 0; for (String nameNode : nameNodes) { if (Strings.isNumeric(nameNode)) { newName.add(nameNode); } else { newName.add((i == replaceIndex) ? newFieldNode : nameNode); i++; } } return newName.toString(); } }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Table) { Table that = (Table) obj; return this.id().equals(that.id()) && this.columns().equals(that.columns()) && this.primaryKeyColumnNames().equals(that.primaryKeyColumnNames()) && Strings.equalsIgnoreCase(this.defaultCharsetName(), that.defaultCharsetName()); } return false; }
private String delimiter(int columnCount, int[] columnSizes) { StringBuilder sb = new StringBuilder(); for (int i = 1; i <= columnCount; i++) { if (i > 1) sb.append("---"); sb.append(Strings.createString('-', columnSizes[i])); } return sb.toString(); }
public void unquoteIdentifierPartShouldReturnNullForNull() { assertThat(Strings.unquoteIdentifierPart(null)).isNull(); }
return Strings.replaceVariables(value, valuesByVariableName); });
@Test public void hexStringToByteArrayShouldReturnCorrectByteArray() { assertThat(Strings.hexStringToByteArray(null)).isNull(); assertThat(Strings.hexStringToByteArray("00")).isEqualTo(new byte[] { 0 }); assertThat(Strings.hexStringToByteArray("010203")).isEqualTo(new byte[] { 1, 2, 3 }); assertThat(Strings.hexStringToByteArray("CAFEBABE")).isEqualTo(new byte[] { -54, -2, -70, -66 }); }
int offset = 0; for (int i = 0; i < items.length; i++) { if (Strings.isNumeric(items[i])) { if (previousNumerical) { return items;
/** * Load the database schema information using the previously-recorded history, and stop reading the history when the * the history reaches the supplied starting point. * * @param startingPoint the source information with the current {@link SourceInfo#partition()} and {@link SourceInfo#offset() * offset} at which the database schemas are to reflect; may not be null */ public void loadHistory(SourceInfo startingPoint) { // Read the system variables from the MySQL instance and load them into the DDL parser as defaults ... Map<String, String> variables = connectionContext.readMySqlCharsetSystemVariables(); dbSchema.setSystemVariables(variables); // And then load the history ... dbSchema.loadHistory(startingPoint); // The server's default character set may have changed since we last recorded it in the history, // so we need to see if the history's state does not match ... String systemCharsetName = variables.get(MySqlSystemVariables.CHARSET_NAME_SERVER); String systemCharsetNameFromHistory = dbSchema.systemVariables().getVariable(MySqlSystemVariables.CHARSET_NAME_SERVER); if (!Strings.equalsIgnoreCase(systemCharsetName, systemCharsetNameFromHistory)) { // The history's server character set is NOT the same as the server's current default, // so record the change in the history ... String ddlStatement = connectionContext.setStatementFor(variables); dbSchema.applyDdl(source, "", ddlStatement, null); } recordProcessor.regenerate(); }
/** * Use a string of the specified number of characters to mask the string values for each of the columns with * fully-qualified names that match the given comma-separated list of regular expression patterns. * * @param fullyQualifiedColumnNames the comma-separated list of fully-qualified column names; may not be null * @param numberOfChars the number of mask characters to be used in the mask value * @param maskChar the character to be used; may not be null * @return this object so that methods can be chained together; never null */ public Builder maskStrings(String fullyQualifiedColumnNames, int numberOfChars, char maskChar) { return maskStrings(fullyQualifiedColumnNames, Strings.createString(maskChar, numberOfChars)); }
/** * Returns a new String composed of the supplied values joined together with a copy of the specified {@code delimiter}. * All {@code null} values are simply ignored. * * @param delimiter the delimiter that separates each element * @param values the values to join together. * @return a new {@code String} that is composed of the {@code elements} separated by the {@code delimiter} * * @throws NullPointerException If {@code delimiter} or {@code elements} is {@code null} * @see java.lang.String#join */ public static <T> String join(CharSequence delimiter, Iterable<T> values) { return join(delimiter, values, v -> { return v != null ? v.toString() : null; }); }
@Override protected void pollComplete(List<SourceRecord> batch) { // Record a bit about this batch ... int batchSize = batch.size(); recordCounter += batchSize; totalRecordCounter.addAndGet(batchSize); if (batchSize > 0) { SourceRecord lastRecord = batch.get(batchSize - 1); lastOffset = lastRecord.sourceOffset(); if (pollOutputDelay.hasElapsed()) { // We want to record the status ... long millisSinceLastOutput = clock.currentTimeInMillis() - previousOutputMillis; try { context.temporaryLoggingContext("binlog", () -> { logger.info("{} records sent during previous {}, last recorded offset: {}", recordCounter, Strings.duration(millisSinceLastOutput), lastOffset); }); } finally { recordCounter = 0; previousOutputMillis += millisSinceLastOutput; } } } }
/** * Check if the string contains only digits. * * @param str the string to check * @return {@code true} if only contains digits */ public static boolean isNumeric(String str) { if (isNullOrEmpty(str)) { return false; } final int sz = str.length(); for (int i = 0; i < sz; i++) { if (!Character.isDigit(str.charAt(i))) { return false; } } return true; }
private void assertSchemaContent(String[] fields, Schema[] types, Schema keySchema) { IntStream.range(0, fields.length).forEach(i -> { String fieldName = fields[i].trim(); Field field = keySchema.field(Strings.unquoteIdentifierPart(fieldName)); assertNotNull(fieldName + " not found in schema", field); VerifyRecord.assertConnectSchemasAreEqual(fieldName, types[i], field.schema()); }); }