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

Yannick Lecaillez
01.42.2015 18789fb93b3441c9646af72f32335c7eed8f551a
opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/LogFile.java
@@ -204,11 +204,9 @@
   */
  private void ensureLogFileIsValid(final RecordParser<K, V> parser) throws ChangelogException
  {
    BlockLogReader<K, V> reader = null;
    try
    try(final RandomAccessFile readerWriter = new RandomAccessFile(logfile, "rws");
        final BlockLogReader<K, V> reader = BlockLogReader.newReader(logfile, readerWriter, parser))
    {
      final RandomAccessFile readerWriter = new RandomAccessFile(logfile, "rws");
      reader = BlockLogReader.newReader(logfile, readerWriter, parser) ;
      final long lastValidPosition = reader.checkLogIsValid();
      if (lastValidPosition != -1)
      {
@@ -223,10 +221,6 @@
          logfile.getPath(),
          StaticUtils.stackTraceToSingleLineString(e)));
    }
    finally
    {
      StaticUtils.close(reader);
    }
  }
  /**
@@ -258,11 +252,9 @@
   */
  void dumpAsTextFile(File dumpFile) throws ChangelogException
  {
    DBCursor<Record<K, V>> cursor = getCursor();
    BufferedWriter textWriter = null;
    try
    try(final BufferedWriter textWriter = new BufferedWriter(new FileWriter(dumpFile));
        final DBCursor<Record<K, V>> cursor = getCursor())
    {
      textWriter = new BufferedWriter(new FileWriter(dumpFile));
      while (cursor.getRecord() != null)
      {
        Record<K, V> record = cursor.getRecord();
@@ -280,10 +272,6 @@
          LocalizableMessage.raw("Error when dumping content of log '%s' in target file : '%s'", getPath(), dumpFile),
          e);
    }
    finally
    {
      StaticUtils.close(textWriter);
    }
  }
  /**
@@ -348,16 +336,10 @@
   */
  Record<K, V> getOldestRecord() throws ChangelogException
  {
    DBCursor<Record<K, V>> cursor = null;
    try
    try (final DBCursor<Record<K, V>> cursor = getCursor())
    {
      cursor = getCursor();
      return cursor.next() ? cursor.getRecord() : null;
    }
    finally
    {
      StaticUtils.close(cursor);
    }
  }
  /**
@@ -393,10 +375,8 @@
  long getNumberOfRecords() throws ChangelogException
  {
    // TODO  : need a more efficient way to retrieve it
    DBCursor<Record<K, V>> cursor = null;
    try
    try(final DBCursor<Record<K, V>> cursor = getCursor())
    {
      cursor = getCursor();
      long counter = 0L;
      while (cursor.next())
      {
@@ -404,10 +384,6 @@
      }
      return counter;
    }
    finally
    {
      StaticUtils.close(cursor);
    }
  }
  /** {@inheritDoc} */
@@ -438,8 +414,7 @@
   */
  void delete() throws ChangelogException
  {
    final boolean isDeleted = logfile.delete();
    if (!isDeleted)
    if (!logfile.delete())
    {
      throw new ChangelogException(ERR_CHANGELOG_UNABLE_TO_DELETE_LOG_FILE.get(getPath()));
    }