Truncating the file to zero restores it to a clean state.
482329
public void truncate(long size) throws IOException {
        super.truncate(size);
        if (size == 0) {
            synchronized (this) {
                mTranCount = 0;
                // Clear the bit to indicate clean.
                mBitlist.clear(mBitlistPos);
            }
        }
    }
790269
def clean(self):
        
        logger.info('Cleaning up archive')
        shutil.move(
            os.path.join(
                self.data_dir,
                'var/IRS/data/scripts/pofd/download/FullDataFile.txt'
            ),
            self.final_path
        )

        shutil.rmtree(os.path.join(self.data_dir, 'var'))
        os.remove(self.zip_path)
1364451
def cleanup(self):
        

        self.log.debug("Cleaning up %s temporary directory" % self.tmp_dir)
        shutil.rmtree(self.tmp_dir, ignore_errors=True)
768451
def copy_truncate
      return unless ::File.exist?(@fn)
      FileUtils.concat @fn, @fn_copy
      @io.truncate 0

      # touch the age file if needed
      if @age
        FileUtils.touch @age_fn
        @age_fn_mtime = nil
      end

      @roller.roll = true
    end
1205110
public function clear() {
		$fileEngine = $this->getFileEngine();
		$fileEngine->removeAll();
		if (!$this->tm->hasOpenTransaction()) {
			$fileEngine->flush();
		}
	}
738687
@Override
  public void truncate(Zxid zxid) throws IOException {
    int lastKeepIdx = getFileIdx(zxid);
    for (int i = lastKeepIdx + 1; i < logFiles.size(); ++i) {
      // Deletes all the log files after the file which contains the
      // transaction with zxid.
      File file = logFiles.get(i);
      boolean result = file.delete();
      if (!result) {
        LOG.warn("The file {} might not be deleted successfully.",
                  file.getName());
      }
    }
    if (lastKeepIdx != -1) {
      File file = this.logFiles.get(lastKeepIdx);
      try (SimpleLog log = new SimpleLog(file)) {
        log.truncate(zxid);
      }
    }
    logFiles.subList(lastKeepIdx+ 1, logFiles.size()).clear();
    this.currentLog = getLastLog();
    this.lastSeenZxid = getLatestZxid();
  }
1029833
def _truncateend(self, bits):
        """"""
        assert 0 <= bits <= self.len
        if not bits:
            return
        if bits == self.len:
            self._clear()
            return
        newlength_in_bytes = (self._offset + self.len - bits + 7) // 8
        self._setbytes_unsafe(self._datastore.getbyteslice(0, newlength_in_bytes), self.len - bits,
                              self._offset)
        assert self._assertsanity()
231940
public void clear() throws IOException
   {
      if (out != null)
      {
         out.truncate(0);
         out.close();
         out = PrivilegedFileHelper.fileOutputStream(logFile).getChannel();
         out.position(1024 * fileSize - 1);
         out.write(ByteBuffer.wrap(new byte[]{0}));
         out.position(0);
         out.force(false);
      }
   }
960516
def flush(self):
        """"""
        if self.mode != 'r':
            with self.mutex:
                self.zf.close()
                # N.B., re-open with mode 'a' regardless of initial mode so we don't wipe
                # what's been written
                self.zf = zipfile.ZipFile(self.path, mode='a',
                                          compression=self.compression,
                                          allowZip64=self.allowZip64)
572347
def _clean_data(self, str_value, file_data, obj_value):
        """"""
        str_value = str_value or None
        obj_value = obj_value or None
        return (str_value, None, obj_value)
47114
private void cleanUp(File f) {
        if (f != null && f.getParentFile() != null) {
            if (m_absoluteTempPath.equalsIgnoreCase(f
                    .getParentFile().getAbsolutePath())) {
                f.delete();
            }
        }
    }
124213
def cleanup_all_temporary_files(self):
        # type: (Descriptor) -> None
        
        # delete local file
        try:
            self.final_path.unlink()
        except OSError:
            pass
        # iterate unchecked chunks and delete
        for key in self._unchecked_chunks:
            ucc = self._unchecked_chunks[key]['ucc']
            if ucc.temp:
                try:
                    ucc.file_path.unlink()
                except OSError:
                    pass
455025
public function truncate()
    {
        $this->file->flock(LOCK_EX);
        $result = $this->file->ftruncate(0);
        $this->file->flock(LOCK_UN);

        return $result;
    }
1011227
public boolean truncate(long zxid) throws IOException {
        FileTxnIterator itr = new FileTxnIterator(this.logDir, zxid);
        PositionInputStream input = itr.inputStream;
        long pos = input.getPosition();
        // now, truncate at the current position
        RandomAccessFile raf=new RandomAccessFile(itr.logFile,"rw");
        raf.setLength(pos);
        raf.close();
        while(itr.goToNextLog()) {
            if (!itr.logFile.delete()) {
                LOG.warn("Unable to truncate " + itr.logFile);
            }
        }
        return true;
    }
308663
def _truncate_wrapper(self):
        
        io_attr = getattr(self._io, 'truncate')

        def truncate_wrapper(*args, **kwargs):
            """Wrap truncate call to call flush after truncate."""
            if self._append:
                self._io.seek(self._read_seek, self._read_whence)
            size = io_attr(*args, **kwargs)
            self.flush()
            if not self.is_stream:
                self.file_object.size = size
                buffer_size = len(self._io.getvalue())
                if buffer_size < size:
                    self._io.seek(buffer_size)
                    self._io.write('\0' * (size - buffer_size))
                    self.file_object.set_contents(
                        self._io.getvalue(), self._encoding)
                    self._flush_pos = size
                    if self._filesystem.is_macos or sys.version_info[0] > 2:
                        self._adapt_size_for_related_files(size - buffer_size)

            self.flush()
            if not IS_PY2:
                return size

        return truncate_wrapper
113025
function truncate(arr, len) {
    if (arr.length > len) {
      arr.length = len;
      return true;
    }
  }
6928
public void truncateFileCount(long count) throws IOException {
        if (count < 0) {
            throw new IllegalArgumentException("count < 0: " + count);
        }
        try {
            mFileTableLock.acquireUpgradableLock();
            long oldCount = getFileCount();
            if (count >= oldCount) {
                return;
            }
            
            mFileTableLock.acquireWriteLock();
            try {
                for (long id = oldCount; --id >= count; ) {
                    deleteFile(id);
                }
                mFileTable.truncate(count * mFileTableEntrySize);
            }
            finally {
                mFileTableLock.releaseLock();
            }
        }
        catch (InterruptedException e) {
            throw new InterruptedIOException();
        }
        finally {
            mFileTableLock.releaseLock();
        }
    }