|
1 | | -//! This is all based on https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html. |
| 1 | +//! Utilities for reading and writing Java properties files |
| 2 | +//! |
| 3 | +//! The specification is taken from https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html. |
| 4 | +//! Where the documentation is ambiguous or incomplete, behavior is based on the behavior of java.util.Properties. |
| 5 | +//! |
| 6 | +//! # Examples |
| 7 | +//! |
| 8 | +//! ``` |
| 9 | +//! use java_properties::PropertiesIter; |
| 10 | +//! use java_properties::PropertiesWriter; |
| 11 | +//! use std::collections::HashMap; |
| 12 | +//! use std::env::temp_dir; |
| 13 | +//! use std::fs::File; |
| 14 | +//! use std::io::prelude::*; |
| 15 | +//! |
| 16 | +//! # fn main() { |
| 17 | +//! # fn foo() -> std::result::Result<(), java_properties::PropertiesError> { |
| 18 | +//! let mut file_name = temp_dir(); |
| 19 | +//! file_name.push("java-properties-test.properties"); |
| 20 | +//! |
| 21 | +//! // Writing |
| 22 | +//! let mut map1 = HashMap::new(); |
| 23 | +//! map1.insert("a".to_string(), "b".to_string()); |
| 24 | +//! let mut f = try!(File::create(&file_name)); |
| 25 | +//! let mut writer = PropertiesWriter::new(f); |
| 26 | +//! for (k, v) in map1.iter() { |
| 27 | +//! try!(writer.write(&k, &v)); |
| 28 | +//! } |
| 29 | +//! |
| 30 | +//! // Reading |
| 31 | +//! let mut f = try!(File::open(&file_name)); |
| 32 | +//! let mut map2 = HashMap::new(); |
| 33 | +//! try!(PropertiesIter::new(f).read_into(|k, v| { |
| 34 | +//! map2.insert(k, v); |
| 35 | +//! })); |
| 36 | +//! assert_eq!(map1, map2); |
| 37 | +//! # Ok(()) |
| 38 | +//! # } |
| 39 | +//! # foo().unwrap(); |
| 40 | +//! # } |
| 41 | +//! ``` |
2 | 42 |
|
3 | 43 | extern crate encoding; |
4 | 44 | extern crate regex; |
|
0 commit comments