Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Th2 3202 #189

Open
wants to merge 5 commits into
base: version-3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# th2 common library (Java) (3.33.0)
# th2 common library (Java) (3.33.1)

## Usage

Expand Down Expand Up @@ -288,6 +288,11 @@ dependencies {

## Release notes

### 3.33.1

+ Added ability to read dictionary by alias as file
+ Corrected logging for configuration files

### 3.33.0

+ Added ability to read dictionaries by aliases and as group of all available aliases
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
#

release_version=3.33.0
release_version=3.33.1

description = 'th2 common library (Java)'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,21 @@ public <T> T getCustomConfiguration(Class<T> confClass) {
*/
public abstract InputStream loadSingleDictionary();

/**
* @param alias name of dictionary
* @return Dictionary as {@link File}
* @throws IllegalStateException if can not read dictionary
*/
public abstract File loadDictionaryFile(String alias);
Topru333 marked this conversation as resolved.
Show resolved Hide resolved


/**
* @return list of available dictionary aliases or an empty list
* @throws IllegalStateException if can not read dictionary
*/
public abstract Set<String> getDictionaryAliases();


/**
* @param alias name of dictionary
* @return Dictionary as {@link InputStream}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,22 @@ public Set<String> getDictionaryAliases() {
}
}

@Override
public File loadDictionaryFile(String alias) {
Topru333 marked this conversation as resolved.
Show resolved Hide resolved
return getDictionaryPath(alias).toFile();
}

@Override
public InputStream loadDictionary(String alias) {
Path dictionaryPath = getDictionaryPath(alias);
try {
return new ByteArrayInputStream(getGzipBase64StringDecoder().decode(Files.readString(dictionaryPath)));
} catch (IOException e) {
throw new IllegalStateException("Can not read dictionary '" + alias + "' from path: " + dictionaryPath, e);
}
}

private Path getDictionaryPath(String alias) {
Path dictionaryFolder = getPathToDictionaryAliasesDir();
try {
LOGGER.debug("Loading dictionary by alias ({}) from folder: {}", alias, dictionaryFolder);
Expand All @@ -567,7 +581,7 @@ public InputStream loadDictionary(String alias) {
throw new IllegalStateException("Found several dictionaries by alias '" + alias + "' at path: " + dictionaryFolder.toAbsolutePath());
}

return new ByteArrayInputStream(getGzipBase64StringDecoder().decode(Files.readString(dictionaries.get(0))));
return dictionaries.get(0);
} catch (IOException e) {
throw new IllegalStateException("Can not read dictionary '" + alias + "' from path: " + dictionaryFolder.toAbsolutePath(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ConfigurationManager(private val configurationPath: Map<Class<*>, Path>) {
}

val sourceContent = String(Files.readAllBytes(configPath))
LOGGER.info("Configuration path {} source content {}", configPath, sourceContent)
LOGGER.info { "Configuration path $configClass source content $sourceContent" }
val content: String = stringSubstitutor.replace(sourceContent)
return objectMapper.readerFor(configClass).readValue(content)
} catch (e: IOException) {
Expand Down