Truncate the file and return the filename.
505449
def prepare_file(filename):
    """"""
    directory = os.path.join(utils.get_project_root(), "analyzation/")
    if not os.path.exists(directory):
        os.makedirs(directory)
    workfilename = os.path.join(directory, filename)
    open(workfilename, 'w').close()  # Truncate the file
    return workfilename
978963
function truncate(input, length, suffix, preserve) {

  length = isUndefined(length) ? input.length : length;
  preserve = preserve || false;
  suffix = suffix || '';

  if(!isString(input) || (input.length <= length)) return input;

  return input.substring(0, (preserve) ?
    ((input.indexOf(' ', length) === -1) ? input.length : input.indexOf(' ', length)) :
    length) + suffix;
}
901243
def truncate_to_string(num, precision=0):
        """"""
        if precision > 0:
            parts = ('{0:.%df}' % precision).format(Decimal(num)).split('.')
            decimal_digits = parts[1][:precision].rstrip('0')
            decimal_digits = decimal_digits if len(decimal_digits) else '0'
            return parts[0] + '.' + decimal_digits
        return ('%d' % num)
987570
def truncate(string, length, ellipsis="…"):
    
    if len(string) > length:
        return string[: length - len(ellipsis)] + ellipsis
    return string
1171317
public synchronized void truncate() throws OpenJournalException, IOException {
        if (!opened) {
            for (DataFile file : dataFiles.values()) {
                removeDataFile(file);
            }
        } else {
            throw new OpenJournalException("The journal is open! The journal must be closed to be truncated.");
        }
    }
1360714
private Method reflectTruncate(FileSystem fs) {
		// completely disable the check for truncate() because the check can be problematic
		// on some filesystem implementations
		if (!useTruncate) {
			return null;
		}

		Method m = null;
		if (fs != null) {
			Class<?> fsClass = fs.getClass();
			try {
				m = fsClass.getMethod("truncate", Path.class, long.class);
			} catch (NoSuchMethodException ex) {
				LOG.debug("Truncate not found. Will write a file with suffix '{}' " +
					" and prefix '{}' to specify how many bytes in a bucket are valid.", validLengthSuffix, validLengthPrefix);
				return null;
			}

			// verify that truncate actually works
			Path testPath = new Path(basePath, UUID.randomUUID().toString());
			try {
				try (FSDataOutputStream outputStream = fs.create(testPath)) {
					outputStream.writeUTF("hello");
				} catch (IOException e) {
					LOG.error("Could not create file for checking if truncate works.", e);
					throw new RuntimeException(
							"Could not create file for checking if truncate works. " +
									"You can disable support for truncate() completely via " +
									"BucketingSink.setUseTruncate(false).", e);
				}

				try {
					m.invoke(fs, testPath, 2);
				} catch (IllegalAccessException | InvocationTargetException e) {
					LOG.debug("Truncate is not supported.", e);
					m = null;
				}
			} finally {
				try {
					fs.delete(testPath, false);
				} catch (IOException e) {
					LOG.error("Could not delete truncate test file.", e);
					throw new RuntimeException("Could not delete truncate test file. " +
							"You can disable support for truncate() completely via " +
							"BucketingSink.setUseTruncate(false).", e);
				}
			}
		}
		return m;
	}
633682
def truncate(string, index):
    """"""
    if len(string) > index and index > 0:
        string = string[:index - 1] + u('…')
    return string
934402
def getFilename(name):
    """"""
    # first replace all illegal chars
    name = re.sub(r"[^0-9a-zA-Z_\-\.]", "_", name)
    # then remove double dots and underscores
    while ".." in name:
        name = name.replace('..', '.')
    while "__" in name:
        name = name.replace('__', '_')
    # remove a leading dot or minus
    if name.startswith((".", "-")):
        name = name[1:]
    return name
44153
public String fileName()
    {
        if (tc.isEntryEnabled())
            Tr.entry(tc, "fileName", this);
        if (tc.isEntryEnabled())
            Tr.exit(tc, "fileName", _fileName);
        return _fileName;
    }
356418
def truncate_str(str_, maxlen=110, truncmsg=' ~~~TRUNCATED~~~ '):
    
    if NO_TRUNCATE:
        return str_
    if maxlen is None or maxlen == -1 or len(str_) < maxlen:
        return str_
    else:
        maxlen_ = maxlen - len(truncmsg)
        lowerb  = int(maxlen_ * .8)
        upperb  = maxlen_ - lowerb
        tup = (str_[:lowerb], truncmsg, str_[-upperb:])
        return ''.join(tup)
1095629
def _remove_compression_suffix_if_present(self, filename):
        
        for ext in [".gz", ".gzip", ".zip"]:
            if filename.endswith(ext):
                return filename[:-len(ext)]
        return filename
85128
function truncate($filename, $new_size)
    {
        $attr = pack('N3', NET_SFTP_ATTR_SIZE, $new_size / 4294967296, $new_size); // 4294967296 == 0x100000000 == 1<<32

        return $this->_setstat($filename, $attr, false);
    }
216536
public static String truncate(String string, int maxBytesLength,
            String appendString) {
        return string.getBytes().length > maxBytesLength ? truncate(string,
                maxBytesLength - appendString.getBytes().length) + appendString
                : string;
    }
865163
public static String truncate(String string, int maxLength) {
        if (string.length() > maxLength) {
            return string.substring(0, maxLength);
        }
        return string;
    }
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();
        }
    }
426670
function truncate(string) {
  if (string.length > SEG_LENGTH * 2 + 3) {
    return string.slice(0, SEG_LENGTH) + '...' + string.slice(-SEG_LENGTH);
  }

  return string;
}
1362305
protected static String trimFileExtension(String fileName) {
		if (fileName.lastIndexOf('.') == -1) {
			return fileName;
		}
		return fileName.substring(0, fileName.lastIndexOf('.'));
	}