org.apache.commons.io.FilenameUtils.failIfNullBytePresent()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(15.1k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.apache.commons.io.FilenameUtils.failIfNullBytePresent()方法的一些代码示例,展示了FilenameUtils.failIfNullBytePresent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilenameUtils.failIfNullBytePresent()方法的具体详情如下:
包路径:org.apache.commons.io.FilenameUtils
类名称:FilenameUtils
方法名:failIfNullBytePresent

FilenameUtils.failIfNullBytePresent介绍

[英]Check the input for null bytes, a sign of unsanitized data being passed to to file level functions. This may be used for poison byte attacks.
[中]检查输入是否为空字节,这是传递给文件级函数的未初始化数据的标志。这可能用于有毒字节攻击。

代码示例

代码示例来源:origin: commons-io/commons-io

/**
 * Checks whether the extension of the filename is that specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extension  the extension to check for, null or empty checks for no extension
 * @return true if the filename has the specified extension
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final String extension) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extension == null || extension.isEmpty()) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  return fileExt.equals(extension);
}

代码示例来源:origin: commons-io/commons-io

failIfNullBytePresent(filename + UNIX_SEPARATOR);
  return filename + UNIX_SEPARATOR;
failIfNullBytePresent(path);
return path;

代码示例来源:origin: commons-io/commons-io

/**
 * Removes the extension from a filename.
 * <p>
 * This method returns the textual part of the filename before the last dot.
 * There must be no directory separator after the dot.
 * <pre>
 * foo.txt    --&gt; foo
 * a\b\c.jpg  --&gt; a\b\c
 * a\b\c      --&gt; a\b\c
 * a.b\c      --&gt; a.b\c
 * </pre>
 * <p>
 * The output will be the same irrespective of the machine that the code is running on.
 *
 * @param filename  the filename to query, null returns null
 * @return the filename minus the extension
 */
public static String removeExtension(final String filename) {
  if (filename == null) {
    return null;
  }
  failIfNullBytePresent(filename);
  final int index = indexOfExtension(filename);
  if (index == NOT_FOUND) {
    return filename;
  } else {
    return filename.substring(0, index);
  }
}

代码示例来源:origin: commons-io/commons-io

/**
 * Gets the name minus the path from a full filename.
 * <p>
 * This method will handle a file in either Unix or Windows format.
 * The text after the last forward or backslash is returned.
 * <pre>
 * a/b/c.txt --&gt; c.txt
 * a.txt     --&gt; a.txt
 * a/b/c     --&gt; c
 * a/b/c/    --&gt; ""
 * </pre>
 * <p>
 * The output will be the same irrespective of the machine that the code is running on.
 *
 * @param filename  the filename to query, null returns null
 * @return the name of the file without the path, or an empty string if none exists.
 * Null bytes inside string will be removed
 */
public static String getName(final String filename) {
  if (filename == null) {
    return null;
  }
  failIfNullBytePresent(filename);
  final int index = indexOfLastSeparator(filename);
  return filename.substring(index + 1);
}

代码示例来源:origin: commons-io/commons-io

/**
 * Checks whether the extension of the filename is one of those specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extensions  the extensions to check for, null checks for no extension
 * @return true if the filename is one of the extensions
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final String[] extensions) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extensions == null || extensions.length == 0) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  for (final String extension : extensions) {
    if (fileExt.equals(extension)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: commons-io/commons-io

/**
 * Checks whether the extension of the filename is one of those specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extensions  the extensions to check for, null checks for no extension
 * @return true if the filename is one of the extensions
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final Collection<String> extensions) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extensions == null || extensions.isEmpty()) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  for (final String extension : extensions) {
    if (fileExt.equals(extension)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: commons-io/commons-io

/**
 * Does the work of getting the path.
 *
 * @param filename  the filename
 * @param separatorAdd  0 to omit the end separator, 1 to return it
 * @return the path. Null bytes inside string will be removed
 */
private static String doGetPath(final String filename, final int separatorAdd) {
  if (filename == null) {
    return null;
  }
  final int prefix = getPrefixLength(filename);
  if (prefix < 0) {
    return null;
  }
  final int index = indexOfLastSeparator(filename);
  final int endIndex = index+separatorAdd;
  if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
    return "";
  }
  final String path = filename.substring(prefix, endIndex);
  failIfNullBytePresent(path);
  return path;
}

代码示例来源:origin: commons-io/commons-io

failIfNullBytePresent(filename);

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Checks whether the extension of the filename is one of those specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extensions  the extensions to check for, null checks for no extension
 * @return true if the filename is one of the extensions
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final Collection<String> extensions) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extensions == null || extensions.isEmpty()) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  for (final String extension : extensions) {
    if (fileExt.equals(extension)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Checks whether the extension of the filename is one of those specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extensions  the extensions to check for, null checks for no extension
 * @return true if the filename is one of the extensions
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final String[] extensions) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extensions == null || extensions.length == 0) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  for (final String extension : extensions) {
    if (fileExt.equals(extension)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Removes the extension from a filename.
 * <p>
 * This method returns the textual part of the filename before the last dot.
 * There must be no directory separator after the dot.
 * <pre>
 * foo.txt    --&gt; foo
 * a\b\c.jpg  --&gt; a\b\c
 * a\b\c      --&gt; a\b\c
 * a.b\c      --&gt; a.b\c
 * </pre>
 * <p>
 * The output will be the same irrespective of the machine that the code is running on.
 *
 * @param filename  the filename to query, null returns null
 * @return the filename minus the extension
 */
public static String removeExtension(final String filename) {
  if (filename == null) {
    return null;
  }
  failIfNullBytePresent(filename);
  final int index = indexOfExtension(filename);
  if (index == NOT_FOUND) {
    return filename;
  } else {
    return filename.substring(0, index);
  }
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Checks whether the extension of the filename is that specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extension  the extension to check for, null or empty checks for no extension
 * @return true if the filename has the specified extension
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final String extension) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extension == null || extension.isEmpty()) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  return fileExt.equals(extension);
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Checks whether the extension of the filename is that specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extension  the extension to check for, null or empty checks for no extension
 * @return true if the filename has the specified extension
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final String extension) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extension == null || extension.isEmpty()) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  return fileExt.equals(extension);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Gets the name minus the path from a full filename.
 * <p>
 * This method will handle a file in either Unix or Windows format.
 * The text after the last forward or backslash is returned.
 * <pre>
 * a/b/c.txt --&gt; c.txt
 * a.txt     --&gt; a.txt
 * a/b/c     --&gt; c
 * a/b/c/    --&gt; ""
 * </pre>
 * <p>
 * The output will be the same irrespective of the machine that the code is running on.
 *
 * @param filename  the filename to query, null returns null
 * @return the name of the file without the path, or an empty string if none exists.
 * Null bytes inside string will be removed
 */
public static String getName(final String filename) {
  if (filename == null) {
    return null;
  }
  failIfNullBytePresent(filename);
  final int index = indexOfLastSeparator(filename);
  return filename.substring(index + 1);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Removes the extension from a filename.
 * <p>
 * This method returns the textual part of the filename before the last dot.
 * There must be no directory separator after the dot.
 * <pre>
 * foo.txt    --&gt; foo
 * a\b\c.jpg  --&gt; a\b\c
 * a\b\c      --&gt; a\b\c
 * a.b\c      --&gt; a.b\c
 * </pre>
 * <p>
 * The output will be the same irrespective of the machine that the code is running on.
 *
 * @param filename  the filename to query, null returns null
 * @return the filename minus the extension
 */
public static String removeExtension(final String filename) {
  if (filename == null) {
    return null;
  }
  failIfNullBytePresent(filename);
  final int index = indexOfExtension(filename);
  if (index == NOT_FOUND) {
    return filename;
  } else {
    return filename.substring(0, index);
  }
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Gets the name minus the path from a full filename.
 * <p>
 * This method will handle a file in either Unix or Windows format.
 * The text after the last forward or backslash is returned.
 * <pre>
 * a/b/c.txt --&gt; c.txt
 * a.txt     --&gt; a.txt
 * a/b/c     --&gt; c
 * a/b/c/    --&gt; ""
 * </pre>
 * <p>
 * The output will be the same irrespective of the machine that the code is running on.
 *
 * @param filename  the filename to query, null returns null
 * @return the name of the file without the path, or an empty string if none exists.
 * Null bytes inside string will be removed
 */
public static String getName(final String filename) {
  if (filename == null) {
    return null;
  }
  failIfNullBytePresent(filename);
  final int index = indexOfLastSeparator(filename);
  return filename.substring(index + 1);
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Checks whether the extension of the filename is one of those specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extensions  the extensions to check for, null checks for no extension
 * @return true if the filename is one of the extensions
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final String[] extensions) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extensions == null || extensions.length == 0) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  for (final String extension : extensions) {
    if (fileExt.equals(extension)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Checks whether the extension of the filename is one of those specified.
 * <p>
 * This method obtains the extension as the textual part of the filename
 * after the last dot. There must be no directory separator after the dot.
 * The extension check is case-sensitive on all platforms.
 *
 * @param filename  the filename to query, null returns false
 * @param extensions  the extensions to check for, null checks for no extension
 * @return true if the filename is one of the extensions
 * @throws java.lang.IllegalArgumentException if the supplied filename contains null bytes
 */
public static boolean isExtension(final String filename, final Collection<String> extensions) {
  if (filename == null) {
    return false;
  }
  failIfNullBytePresent(filename);
  if (extensions == null || extensions.isEmpty()) {
    return indexOfExtension(filename) == NOT_FOUND;
  }
  final String fileExt = getExtension(filename);
  for (final String extension : extensions) {
    if (fileExt.equals(extension)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Does the work of getting the path.
 *
 * @param filename  the filename
 * @param separatorAdd  0 to omit the end separator, 1 to return it
 * @return the path. Null bytes inside string will be removed
 */
private static String doGetPath(final String filename, final int separatorAdd) {
  if (filename == null) {
    return null;
  }
  final int prefix = getPrefixLength(filename);
  if (prefix < 0) {
    return null;
  }
  final int index = indexOfLastSeparator(filename);
  final int endIndex = index+separatorAdd;
  if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
    return "";
  }
  final String path = filename.substring(prefix, endIndex);
  failIfNullBytePresent(path);
  return path;
}

代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded

/**
 * Does the work of getting the path.
 *
 * @param filename  the filename
 * @param separatorAdd  0 to omit the end separator, 1 to return it
 * @return the path. Null bytes inside string will be removed
 */
private static String doGetPath(final String filename, final int separatorAdd) {
  if (filename == null) {
    return null;
  }
  final int prefix = getPrefixLength(filename);
  if (prefix < 0) {
    return null;
  }
  final int index = indexOfLastSeparator(filename);
  final int endIndex = index+separatorAdd;
  if (prefix >= filename.length() || index < 0 || prefix >= endIndex) {
    return "";
  }
  String path = filename.substring(prefix, endIndex);
  failIfNullBytePresent(path);
  return path;
}

相关文章