@Test public void readMultipleEntities() throws Exception { String ldif = "dn: dc=example,dc=com\n" + "objectClass: domain\n" + "objectClass: top\n" + "dc: example\n" + "\n" + "dn: ou=Users,dc=example,dc=com\n" + "objectClass: organizationalUnit\n" + "objectClass: top\n" + "ou: Users\n"; Map<String, Attributes> entities = LDIFUtils.read(new ByteArrayInputStream(ldif.getBytes())); assertThat(entities.size(), is(2)); assertThat(entities.containsKey("dc=example,dc=com"), is(true)); assertThat(entities.containsKey("ou=Users,dc=example,dc=com"), is(true)); }
public static Map<String, Attributes> read(InputStream in) throws IOException { Map<String, Attributes> result = new LinkedHashMap<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line; Attributes currentEntity = null; String currentLine = null; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { continue; } if (line.isEmpty()) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentEntity = null; currentLine = null; continue; } if (currentEntity == null) { currentEntity = new BasicAttributes(); } if (!line.startsWith(" ")) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentLine = line; } else { currentLine = currentLine + line; } } if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } } return result; }
LDIFUtils { public static Map<String, Attributes> read(InputStream in) throws IOException { Map<String, Attributes> result = new LinkedHashMap<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line; Attributes currentEntity = null; String currentLine = null; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { continue; } if (line.isEmpty()) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentEntity = null; currentLine = null; continue; } if (currentEntity == null) { currentEntity = new BasicAttributes(); } if (!line.startsWith(" ")) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentLine = line; } else { currentLine = currentLine + line; } } if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } } return result; } }
LDIFUtils { public static Map<String, Attributes> read(InputStream in) throws IOException { Map<String, Attributes> result = new LinkedHashMap<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line; Attributes currentEntity = null; String currentLine = null; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { continue; } if (line.isEmpty()) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentEntity = null; currentLine = null; continue; } if (currentEntity == null) { currentEntity = new BasicAttributes(); } if (!line.startsWith(" ")) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentLine = line; } else { currentLine = currentLine + line; } } if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } } return result; }  }
LDIFUtils { public static Map<String, Attributes> read(InputStream in) throws IOException { Map<String, Attributes> result = new LinkedHashMap<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line; Attributes currentEntity = null; String currentLine = null; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { continue; } if (line.isEmpty()) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentEntity = null; currentLine = null; continue; } if (currentEntity == null) { currentEntity = new BasicAttributes(); } if (!line.startsWith(" ")) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentLine = line; } else { currentLine = currentLine + line; } } if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } } return result; }  static Map<String, Attributes> read(InputStream in); }
LDIFUtils { public static Map<String, Attributes> read(InputStream in) throws IOException { Map<String, Attributes> result = new LinkedHashMap<>(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line; Attributes currentEntity = null; String currentLine = null; while ((line = reader.readLine()) != null) { if (line.startsWith("#")) { continue; } if (line.isEmpty()) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentEntity = null; currentLine = null; continue; } if (currentEntity == null) { currentEntity = new BasicAttributes(); } if (!line.startsWith(" ")) { if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } currentLine = line; } else { currentLine = currentLine + line; } } if (currentLine != null) { storeAttribute(result, currentEntity, currentLine); } } return result; }  static Map<String, Attributes> read(InputStream in);  }