code: @InterfaceAudience.Private
      private void replaceDatabase(String databaseName,
                                   InputStream databaseStream,
                                   Iterator<Map.Entry<String, InputStream>> attachmentStreams)
              throws CouchbaseLiteException {
          try {
              Database db = getDatabase(databaseName, false);
  
              String dstDbPath = FileDirUtils.getPathWithoutExt(db.getPath()) + kV1DBExtension;
              String dstAttsPath = FileDirUtils.getPathWithoutExt(dstDbPath) + " attachments";
  
              OutputStream destStream = new FileOutputStream(new File(dstDbPath));
              StreamUtils.copyStream(databaseStream, destStream);
              File attachmentsFile = new File(dstAttsPath);
              FileDirUtils.deleteRecursive(attachmentsFile);
              if (!attachmentsFile.exists()) {
                  attachmentsFile.mkdirs();
              }
              if (attachmentStreams != null) {
                  StreamUtils.copyStreamsToFolder(attachmentStreams, attachmentsFile);
              }
              if (!upgradeV1Database(databaseName, dstDbPath)) {
                  throw new CouchbaseLiteException(Status.INTERNAL_SERVER_ERROR);
              }
              db.open();
              db.replaceUUIDs();
          } catch (FileNotFoundException e) {
              Log.e(Database.TAG, "Error replacing the database: %s", e, databaseName);
              throw new CouchbaseLiteException(Status.INTERNAL_SERVER_ERROR);
          } catch (IOException e) {
              Log.e(Database.TAG, "Error replacing the database: %s", e, databaseName);
              throw new CouchbaseLiteException(Status.INTERNAL_SERVER_ERROR);
          }
      }
docs: /////////////////////////////////////////////////////////////////////////