mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
20.17.2016 9e168295f1c1ab30c211f07cea5934a74ad760cb
LDIFReader.java: code cleanup
2 files modified
49 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/types/LDIFImportConfig.java 3 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java 46 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/LDIFImportConfig.java
@@ -190,9 +190,8 @@
  private BufferedReader getBufferedReader(Reader reader) {
    if (reader instanceof BufferedReader) {
      return (BufferedReader)reader;
    } else {
      return new BufferedReader(reader);
    }
    return new BufferedReader(reader);
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
@@ -476,8 +476,7 @@
        }
        else
        {
          LocalizableMessage message =
                  ERR_LDIF_INVALID_LEADING_SPACE.get(lineNumber, line);
          LocalizableMessage message = ERR_LDIF_INVALID_LEADING_SPACE.get(lineNumber, line);
          logToRejectWriter(lines, message);
          throw new LDIFException(message, lineNumber, false);
        }
@@ -535,9 +534,7 @@
    int colonPos = line.indexOf(":");
    if (colonPos <= 0)
    {
      LocalizableMessage message =
              ERR_LDIF_NO_ATTR_NAME.get(lastEntryLineNumber, line);
      LocalizableMessage message = ERR_LDIF_NO_ATTR_NAME.get(lastEntryLineNumber, line);
      logToRejectWriter(lines, message);
      throw new LDIFException(message, lastEntryLineNumber, true);
    }
@@ -550,9 +547,7 @@
    }
    else if (! attrName.equals("dn"))
    {
      LocalizableMessage message =
              ERR_LDIF_NO_DN.get(lastEntryLineNumber, line);
      LocalizableMessage message = ERR_LDIF_NO_DN.get(lastEntryLineNumber, line);
      logToRejectWriter(lines, message);
      throw new LDIFException(message, lastEntryLineNumber, true);
    }
@@ -566,20 +561,25 @@
      return DN.rootDN();
    }
    String dn = readValue(line, colonPos, lines);
    return decodeDN(dn, lines, line);
  }
  private String readValue(StringBuilder line, int colonPos, List<StringBuilder> lines) throws LDIFException
  {
    if (line.charAt(colonPos+1) == ':')
    {
      // The DN is base64-encoded.  Find the first non-blank character and
      // take the rest of the line, base64-decode it, and parse it as a DN.
      // The value is base64-encoded. Find the first non-blank character
      // and take the rest of the line, and base64-decode it.
      int pos = findFirstNonSpaceCharPosition(line, colonPos + 2);
      String dnStr = base64Decode(line.substring(pos), lines, line);
      return decodeDN(dnStr, lines, line);
      return base64Decode(line.substring(pos), lines, line);
    }
    else
    {
      // The rest of the value should be the DN.  Skip over any spaces and
      // attempt to decode the rest of the line as the DN.
      // The rest of the value should be the value. Skip over any spaces
      // and attempt to decode the rest of the line as a string.
      int pos = findFirstNonSpaceCharPosition(line, colonPos + 1);
      return decodeDN(line.substring(pos), lines, line);
      return line.substring(pos);
    }
  }
@@ -686,22 +686,8 @@
      throw new LDIFException(message, lastEntryLineNumber, false );
    }
    if (line.charAt(colonPos+1) == ':')
    {
      // The change type is base64-encoded.  Find the first non-blank character
      // and take the rest of the line, and base64-decode it.
      int pos = findFirstNonSpaceCharPosition(line, colonPos + 2);
      return base64Decode(line.substring(pos), lines, line);
    return readValue(line, colonPos, lines);
    }
    else
    {
      // The rest of the value should be the changetype. Skip over any spaces
      // and attempt to decode the rest of the line as the changetype string.
      int pos = findFirstNonSpaceCharPosition(line, colonPos + 1);
      return line.substring(pos);
    }
  }
  /**
   * Decodes the provided line as an LDIF attribute and adds it to the