private static class ProfilesConfigFileWriter.ProfilesConfigFileWriterHelper extends AbstractProfilesConfigFileScanner
Modifier and Type | Field and Description |
---|---|
private java.lang.StringBuilder |
buffer |
private java.util.Set<java.lang.String> |
deletedProfiles
Map of the names of all the profiles to be deleted
|
private java.util.Map<java.lang.String,java.util.Set<java.lang.String>> |
existingProfileProperties |
private java.util.Map<java.lang.String,Profile> |
newProfiles
Map of all the profiles to be modified, keyed by profile names
|
private java.io.Writer |
writer
The writer where the modified profiles will be output to
|
Constructor and Description |
---|
ProfilesConfigFileWriterHelper(java.io.Writer writer,
java.util.Map<java.lang.String,Profile> modifications)
Creates ProfilesConfigFileWriterHelper with the specified new
profiles.
|
Modifier and Type | Method and Description |
---|---|
private void |
append(java.lang.String str)
This method handles IOException that occurs when calling the append
method on the writer.
|
private void |
buffer(java.lang.String line) |
private void |
flush() |
protected void |
onEmptyOrCommentLine(java.lang.String profileName,
java.lang.String line)
Action to be performed when an empty or comment line is detected
|
protected void |
onEndOfFile()
Action to be performed when the scanner reaches the end of the
credentials file.
|
protected void |
onProfileEndingLine(java.lang.String prevProfileName)
Action to be performed when the scanner reaches the end of a profile
section.
|
protected void |
onProfileProperty(java.lang.String profileName,
java.lang.String propertyKey,
java.lang.String propertyValue,
boolean isSupportedProperty,
java.lang.String line)
Action to be performed when a property declaration is detected inside a
profile section.
|
protected void |
onProfileStartingLine(java.lang.String profileName,
java.lang.String line)
Action to be performed when the starting line of a new profile is detected
|
private void |
writeLine(java.lang.String line) |
private void |
writeProfile(Profile profile) |
private void |
writeProfileName(java.lang.String profileName) |
private void |
writeProperty(java.lang.String propertyKey,
java.lang.String propertyValue) |
void |
writeWithExistingContent(java.util.Scanner existingContent)
Read the existing content of a credentials file, and then make
in-place modification according to the new profiles specified in this
class.
|
void |
writeWithoutExistingContent()
Append the new profiles to the writer, by reading from empty content.
|
run
private final java.io.Writer writer
private final java.util.Map<java.lang.String,Profile> newProfiles
private final java.util.Set<java.lang.String> deletedProfiles
private final java.lang.StringBuilder buffer
private final java.util.Map<java.lang.String,java.util.Set<java.lang.String>> existingProfileProperties
public ProfilesConfigFileWriterHelper(java.io.Writer writer, java.util.Map<java.lang.String,Profile> modifications)
writer
- The writer where the modified content is output to.modifications
- A map of all the new profiles, keyed by the profile name.
If a profile name is associated with a null value, it's
profile content will be removed.public void writeWithoutExistingContent()
public void writeWithExistingContent(java.util.Scanner existingContent)
protected void onEmptyOrCommentLine(java.lang.String profileName, java.lang.String line)
AbstractProfilesConfigFileScanner
onEmptyOrCommentLine
in class AbstractProfilesConfigFileScanner
protected void onProfileStartingLine(java.lang.String profileName, java.lang.String line)
AbstractProfilesConfigFileScanner
onProfileStartingLine
in class AbstractProfilesConfigFileScanner
protected void onProfileEndingLine(java.lang.String prevProfileName)
AbstractProfilesConfigFileScanner
onProfileEndingLine
in class AbstractProfilesConfigFileScanner
protected void onProfileProperty(java.lang.String profileName, java.lang.String propertyKey, java.lang.String propertyValue, boolean isSupportedProperty, java.lang.String line)
AbstractProfilesConfigFileScanner
onProfileProperty
in class AbstractProfilesConfigFileScanner
profileName
- The name of the profile where this property is declared.propertyKey
- The name of the property.propertyValue
- The value of the property.isSupportedProperty
- Whether this is a supported property according to the
specification of credential profiles file.line
- The original line of text where the property is declared.protected void onEndOfFile()
AbstractProfilesConfigFileScanner
onEndOfFile
in class AbstractProfilesConfigFileScanner
private void writeProfile(Profile profile)
private void writeProfileName(java.lang.String profileName)
private void writeProperty(java.lang.String propertyKey, java.lang.String propertyValue)
private void writeLine(java.lang.String line)
private void append(java.lang.String str)
private void flush()
private void buffer(java.lang.String line)