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

Ludovic Poitou
21.27.2013 df439c5fb79fae7b439fd03cbac13c3a2b3dec3b
Fix for issue OPENDJ-1207 - Import-ldif corrupts some photo files during process.
The root cause was an threading issue and the fact that a single buffer was used when processing a URL and loading the content to the attribute value. Now using ByteStringBuilder.append(InputStream, int) which has its own internal buffer.
2 files modified
30 ■■■■ changed files
opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/LDIFReader.java 26 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
@@ -903,9 +903,7 @@
    this.rootContainer = rootContainer;
    try
    {
      reader =
          new LDIFReader(importConfiguration, rootContainer,
              READER_WRITER_BUFFER_SIZE);
      reader = new LDIFReader(importConfiguration, rootContainer);
    }
    catch (IOException ioe)
    {
opends/src/server/org/opends/server/util/LDIFReader.java
@@ -73,9 +73,6 @@
  /** The reader that will be used to read the data. */
  private BufferedReader reader;
  /** The buffer to use to read data from a URL. */
  private byte[] buffer;
  /** The import configuration that specifies what should be imported. */
  private LDIFImportConfig importConfig;
@@ -139,7 +136,6 @@
    this.importConfig = importConfig;
    reader               = importConfig.getReader();
    buffer               = new byte[4096];
    lineNumber           = 0;
    lastEntryLineNumber  = -1;
    lastEntryBodyLines   = new LinkedList<StringBuilder>();
@@ -162,14 +158,12 @@
   *          The import configuration for this LDIF reader. It must not
   *          be <CODE>null</CODE>.
   * @param rootContainer The root container needed to get the next entry ID.
   * @param size The size of the buffer to read the LDIF bytes into.
   *
   * @throws IOException
   *           If a problem occurs while opening the LDIF file for
   *           reading.
   */
  public LDIFReader(LDIFImportConfig importConfig, RootContainer rootContainer,
                     int size)
  public LDIFReader(LDIFImportConfig importConfig, RootContainer rootContainer)
         throws IOException
  {
    ensureNotNull(importConfig);
@@ -180,7 +174,6 @@
    this.lastEntryBodyLines   = new LinkedList<StringBuilder>();
    this.lastEntryHeaderLines = new LinkedList<StringBuilder>();
    this.pluginConfigManager  = DirectoryServer.getPluginConfigManager();
    this.buffer        = new byte[size];
    this.rootContainer = rootContainer;
    // If we should invoke import plugins, then do so.
    if (importConfig.invokeImportPlugins())
@@ -1972,17 +1965,12 @@
        InputStream inputStream = null;
        ByteStringBuilder builder;
        try
        {
          builder = new ByteStringBuilder();
          ByteStringBuilder builder = new ByteStringBuilder(4096);
          inputStream  = contentURL.openConnection().getInputStream();
          int bytesRead;
          while ((bytesRead = inputStream.read(buffer)) > 0)
          {
            builder.append(buffer, 0, bytesRead);
          }
          while (builder.append(inputStream, 4096) != -1) { /* Do nothing */ }
          value = builder.toByteString();
        }
@@ -2005,13 +1993,7 @@
        }
        finally
        {
          if (inputStream != null)
          {
            try
            {
              inputStream.close();
            } catch (Exception e) {}
          }
          StaticUtils.close(inputStream);
        }
      }
      else