Last active
          September 30, 2022 12:22 
        
      - 
      
- 
        Save cp-hardik-p/eed89959fc7a2bfded4636de1abc01ec to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @Throws(IOException::class) | |
| private fun ensureLogSize(logFile: File) { | |
| if (logFile.length() < maxLogSize) return | |
| // We remove first 25% part of logs | |
| val startIndex = logFile.length() / 4 | |
| val randomAccessFile = RandomAccessFile(logFile, "r") | |
| randomAccessFile.seek(startIndex) | |
| val into = ByteArrayOutputStream() | |
| val buf = ByteArray(4096) | |
| var n: Int | |
| while (true) { | |
| n = randomAccessFile.read(buf) | |
| if (n < 0) break | |
| into.write(buf, 0, n) | |
| } | |
| randomAccessFile.close() | |
| val outputStream = FileOutputStream(logFile) | |
| into.writeTo(outputStream) | |
| outputStream.close() | |
| into.close() | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment