@Test public void readSingleEntity() throws Exception { String ldif = "dn: dc=example,dc=com\n" + "objectClass: domain\n" + "objectClass: top\n" + "dc: example\n"; Map<String, Attributes> entities = LDIFUtils.read(new ByteArrayInputStream(ldif.getBytes())); assertThat(entities.size(), is(1)); String dn = "dc=example,dc=com"; Attributes entity = entities.get(dn); assertThat(entity, notNullValue()); assertThat(entity.get("dn"), nullValue()); assertThat(entity.get("dc").get(), is("example")); assertThat(entity.get("objectClass").contains("domain"), is(true)); assertThat(entity.get("objectClass").contains("top"), 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);  }