{"id":28574190,"url":"https://github.com/felixsfd/enhancedproperties","last_synced_at":"2025-06-10T21:20:39.634Z","repository":{"id":41981609,"uuid":"284474637","full_name":"FelixSFD/EnhancedProperties","owner":"FelixSFD","description":"Powerful wrapper for the Java Properties-class","archived":false,"fork":false,"pushed_at":"2023-01-11T20:01:11.000Z","size":110,"stargazers_count":0,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-01T13:19:44.131Z","etag":null,"topics":["java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FelixSFD.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"FelixSFD","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-08-02T14:11:32.000Z","updated_at":"2024-05-01T13:19:44.133Z","dependencies_parsed_at":"2023-02-09T06:17:17.622Z","dependency_job_id":null,"html_url":"https://github.com/FelixSFD/EnhancedProperties","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FelixSFD%2FEnhancedProperties","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FelixSFD%2FEnhancedProperties/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FelixSFD%2FEnhancedProperties/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FelixSFD%2FEnhancedProperties/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FelixSFD","download_url":"https://codeload.github.com/FelixSFD/EnhancedProperties/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FelixSFD%2FEnhancedProperties/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259152958,"owners_count":22813250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java"],"created_at":"2025-06-10T21:20:34.758Z","updated_at":"2025-06-10T21:20:39.543Z","avatar_url":"https://github.com/FelixSFD.png","language":"Java","funding_links":["https://github.com/sponsors/FelixSFD"],"categories":[],"sub_categories":[],"readme":"[![Tests](https://github.com/FelixSFD/EnhancedProperties/workflows/Tests/badge.svg)](https://github.com/FelixSFD/EnhancedProperties/actions?query=workflow%3ATests)\n[![javadoc](https://javadoc.io/badge2/de.felixsfd/EnhancedProperties/javadoc.svg)](https://javadoc.io/doc/de.felixsfd/EnhancedProperties)\n[![Maven Central](https://img.shields.io/maven-central/v/de.felixsfd/EnhancedProperties)](https://search.maven.org/artifact/de.felixsfd/EnhancedProperties)\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n# EnhancedProperties\n_EnhancedProperties_ is an improved way to read `*.properties`-files in Java. It handles reading (and soon writing) files for you, so you don't need to worry about your Input/Output-Streams, closing files etc. There are even methods to parse the data into the most common datatypes.\nThis library is especially useful, if you have a large amount of properties.\n\n## Use with Maven\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ede.felixsfd\u003c/groupId\u003e\n  \u003cartifactId\u003eenhancedproperties\u003c/artifactId\u003e\n  \u003cversion\u003e1.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n# Basic example\n## The old way\n\nFor reading a double value from a local properties file, you'd do something like this:\n\n```java\nProperties properties = new Properties();\ntry (FileInputStream fis = new FileInputStream(new File(\"my.properties\"))) {\n  properties.load(fis);\n}\n\nString strValue = properties.getProperty(\"someNumber\", \"0.0\");\ndouble doubleValue;\ntry {\n  doubleValue = Double.parseDouble(strValue);\n} catch (NumberFormatException e) {\n  doubleValue = 0.0;\n}\n```\n\nThis might be nice an quick in some cases, but if you have lots of properties and read them very often, this can be quite annoying.\n\n## Quick and dirty\n\nIf you don't have many different keys in you file, you can create an anonymous class of `EnhancedPropertiesInFile`, `EnhancedPropertiesInResources` or `EnhancedPropertiesInFileOrResources`.\n**This is not the recommended way, but it should work, too.**\n\n```java\nEnhancedPropertiesInFile propertiesInFile = new EnhancedPropertiesInFile(\"my.properties\") {};\ndouble doubleValue = propertiesInFile.getDouble(\"someNumber\", 0.0);\n```\n\n## The beautiful way\n\n**This is the recommended way of using _EnhancedProperties_.**\n\n### Create your Properties-Class\n\nTo read the properties for your application, you'll need to create a subclass of `EnhancedPropertiesInFile`, `EnhancedPropertiesInResources` or `EnhancedPropertiesInFileOrResources`.\nIn this example, we need `EnhancedPropertiesInFile`.\n\n```java\npublic class MyProperties extends EnhancedPropertiesInFile {\n  protected MyProperties() throws IOException {\n    super(\"my.properties\");\n  }\n\n  public double getDoubleValue(double defaultValue) {\n    return super.getDouble(\"doubleValue\", defaultValue);\n  }\n}\n```\n\n### Access the property\n\nSince the `MyProperties`-class contains the file-path and handles parsing the double as well, we can now access the value like this:\n\n```java\nMyProperties myProperties = new MyProperties();\ndouble doubleValue = myProperties.getDoubleValue(0.0);\n```\n\n# Example: Read file from resources\n\nTo read a file from your application's resources, you can follow the instructions of the \"basic example\". Just change the superclass for `MyProperties` from `EnhancedPropertiesInFile` to `EnhancedPropertiesInResources`.\n\n```java\npublic class MyProperties extends EnhancedPropertiesInResources {\n  protected MyProperties() throws IOException {\n    super(\"my.properties\");\n  }\n\n  public double getDoubleValue(double defaultValue) {\n    return super.getDouble(\"doubleValue\", defaultValue);\n  }\n}\n```\n\n# Example: Use two properties file overwriting each other\n\nFor complex use-cases, you can read files from file-system and the application's resources at the same time. If a key is present in both files, the value from the preferred file will be used.\nThis is useful, if you ship default properties within the resources of the application but you wan't to override some of the values.\n\nIn this example, we assume, that the default properties are stored in the resources-root directory and the custom properties in `/home/user/application/my.properties`.\nThe values of the file in the file-system should be preferred over the values in the resources.\n\n```java\n@ReadRule(preferredLocation = ReadRule.Location.FILE)\npublic class MyProperties extends EnhancedPropertiesInResources {\n  protected MyProperties() throws IOException {\n    super(\"/home/user/application/my.properties\", \"my_default.properties\");\n  }\n\n  public double getDoubleValue(double defaultValue) {\n    return super.getDouble(\"doubleValue\", defaultValue);\n  }\n}\n```\n\nIf you want the properties in the resources to be the preferred file, just change the annotation to `@ReadRule(preferredLocation = ReadRule.Location.RESOURCES)`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixsfd%2Fenhancedproperties","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffelixsfd%2Fenhancedproperties","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffelixsfd%2Fenhancedproperties/lists"}