@Override public boolean truncate(String fileName,long validDataEndOffset){
  DataOutputStream dataOutputStream=null;
  DataInputStream dataInputStream=null;
  boolean fileTruncatedSuccessfully=false;
  int bufferSize=validDataEndOffset > CarbonCommonConstants.BYTE_TO_KB_CONVERSION_FACTOR ? CarbonCommonConstants.BYTE_TO_KB_CONVERSION_FACTOR : (int)validDataEndOffset;
  String tempWriteFilePath=fileName + CarbonCommonConstants.TEMPWRITEFILEEXTENSION;
  FileFactory.FileType fileType=FileFactory.getFileType(fileName);
  try {
    CarbonFile tempFile=null;
    if (FileFactory.isFileExist(tempWriteFilePath,fileType)) {
      tempFile=FileFactory.getCarbonFile(tempWriteFilePath,fileType);
      tempFile.delete();
    }
    FileFactory.createNewFile(tempWriteFilePath,fileType);
    tempFile=FileFactory.getCarbonFile(tempWriteFilePath,fileType);
    byte[] buff=new byte[bufferSize];
    dataInputStream=FileFactory.getDataInputStream(fileName,fileType);
    int read=dataInputStream.read(buff,0,buff.length);
    dataOutputStream=FileFactory.getDataOutputStream(tempWriteFilePath,fileType);
    dataOutputStream.write(buff,0,read);
    long remaining=validDataEndOffset - read;
    while (remaining > 0) {
      if (remaining > bufferSize) {
        buff=new byte[bufferSize];
      }
 else {
        buff=new byte[(int)remaining];
      }
      read=dataInputStream.read(buff,0,buff.length);
      dataOutputStream.write(buff,0,read);
      remaining=remaining - read;
    }
    CarbonUtil.closeStreams(dataInputStream,dataOutputStream);
    tempFile.renameForce(fileName);
    fileTruncatedSuccessfully=true;
  }
 catch (  IOException e) {
    LOGGER.error("Exception occured while truncating the file " + e.getMessage());
  }
 finally {
    CarbonUtil.closeStreams(dataOutputStream,dataInputStream);
  }
  return fileTruncatedSuccessfully;
}

@ Override public boolean truncate ( String fileName , long validDataEndOffset ) { DataOutputStream dataOutputStream = null ; DataInputStream dataInputStream = null ; boolean fileTruncatedSuccessfully = false ; int bufferSize = validDataEndOffset > CarbonCommonConstants . BYTE_TO_KB_CONVERSION_FACTOR ? CarbonCommonConstants . BYTE_TO_KB_CONVERSION_FACTOR : ( int ) validDataEndOffset ; String tempWriteFilePath = fileName + CarbonCommonConstants . TEMPWRITEFILEEXTENSION ; FileFactory . FileType fileType = FileFactory . getFileType ( fileName ) ; try { CarbonFile tempFile = null ; if ( FileFactory . isFileExist ( tempWriteFilePath , fileType ) ) { tempFile = FileFactory . getCarbonFile ( tempWriteFilePath , fileType ) ; tempFile . delete ( ) ; } FileFactory . createNewFile ( tempWriteFilePath , fileType ) ; tempFile = FileFactory . getCarbonFile ( tempWriteFilePath , fileType ) ; byte [ ] buff = new byte [ bufferSize ] ; dataInputStream = FileFactory . getDataInputStream ( fileName , fileType ) ; int read = dataInputStream . read ( buff , 0 , buff . length ) ; dataOutputStream = FileFactory . getDataOutputStream ( tempWriteFilePath , fileType ) ; dataOutputStream . write ( buff , 0 , read ) ; long remaining = validDataEndOffset - read ; while ( remaining > 0 ) { if ( remaining > bufferSize ) { buff = new byte [ bufferSize ] ; } else { buff = new byte [ ( int ) remaining ] ; } read = dataInputStream . read ( buff , 0 , buff . length ) ; dataOutputStream . write ( buff , 0 , read ) ; remaining = remaining - read ; } CarbonUtil . closeStreams ( dataInputStream , dataOutputStream ) ; tempFile . renameForce ( fileName ) ; fileTruncatedSuccessfully = true ; } catch ( IOException e ) { LOGGER . error ( "Exception occured while truncating the file " + e . getMessage ( ) ) ; } finally { CarbonUtil . closeStreams ( dataOutputStream , dataInputStream ) ; } return fileTruncatedSuccessfully ; }
this method will delete the data in file data from a given offset
