code: public synchronized void compact() throws ClosedJournalException, IOException {
          if (opened) {
              for (DataFile file : dataFiles.values()) {
                  // Can't compact the data file (or subsequent files) that is currently being written to:
                  if (file.getDataFileId() >= lastAppendLocation.getDataFileId()) {
                      continue;
                  } else {
                      Location firstUserLocation = goToFirstLocation(file, Location.USER_RECORD_TYPE, false);
                      if (firstUserLocation == null) {
                          removeDataFile(file);
                      } else {
                          Location firstDeletedLocation = goToFirstLocation(file, Location.DELETED_RECORD_TYPE, false);
                          if (firstDeletedLocation != null) {
                              compactDataFile(file);
                          }
                      }
                  }
              }
          } else {
              throw new ClosedJournalException("The journal is closed!");
          }
      }
docs: Compact the journal, reducing size of logs containing deleted entries and
  completely removing empty (with only deleted entries) logs.
  
  @throws IOException
  @throws ClosedJournalException