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

allow escape sequences (like tab delimiters) #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions src/main/java/com/evolveum/polygon/connector/csv/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ public static Character toCharacter(String value) {
return null;
}

if (value.length() == 2 && value.startsWith("\\")) {
// This is likely to be an escape sequence, like \t
// We'll take advantage of Properties to convert this to a character
Properties props = new Properties();
try {
props.load(new StringReader("key=" + value));
} catch (IOException ex) {
throw new ConfigurationException("Can't cast to character, reason: " + ex.getMessage(), ex);
}

value = props.getProperty("key");
}

if (value.length() != 1) {
throw new ConfigurationException("Can't cast to character, illegal string size: "
+ value.length() + ", should be 1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ public void testMissingMultivalueDelimiter() throws Exception {
ConnectorFacade connector = setupConnector("/create.csv", config);
connector.test();
}

@Test
public void testTabDelimiter() throws Exception {
CsvConfiguration config = new CsvConfiguration();
config.setUniqueAttribute("uid");
config.setFieldDelimiter("\\t");
config.setReadOnly(true);

ConnectorFacade connector = setupConnector("/create-tabs.tsv", config);
connector.test();

}
}
2 changes: 2 additions & 0 deletions src/test/resources/create-tabs.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
firstName uid lastName password
john 123 doe qwe123