获取文件名

@param type          0-原图 1水印图 2缩略图
@param tokenFilename 文件名
@return
433994
private String getFileName(int type, String tokenFilename) {
        StringBuilder sb = new StringBuilder();
        String filename = tokenFilename.substring(0, tokenFilename.indexOf(EXT_SEPERATOR));
        String ext = tokenFilename.substring(tokenFilename.indexOf(EXT_SEPERATOR));
        sb.append(filename);
        switch (type) {
            case 1:
                sb.append(IMAGE_WATERMARK_SUFFIX);
                break;
            case 2:
                sb.append(IMAGE_THUMB_SUFFIX);
                break;
        }
        sb.append(ext);
        return sb.toString();
    }
912832
public Response put(File file, String key, String token) throws QiniuException {
        return put(file, key, token, null, null, false);
    }
1214755
@VisibleForTesting
  synchronized void writeDelegationTokenToFile() throws IOException {
    if (this.fs.exists(this.tokenFilePath)) {
      LOGGER.info("Deleting existing token file " + this.tokenFilePath);
      this.fs.delete(this.tokenFilePath, false);
    }

    LOGGER.info("Writing new or renewed token to token file " + this.tokenFilePath);
    YarnHelixUtils.writeTokenToFile(this.token, this.tokenFilePath, this.fs.getConf());
    // Only grand access to the token file to the login user
    this.fs.setPermission(this.tokenFilePath, new FsPermission(FsAction.READ_WRITE, FsAction.NONE, FsAction.NONE));
  }
896441
public static String putFileType(String fileStreamHexHead, String extName) {
		return fileTypeMap.put(fileStreamHexHead.toLowerCase(), extName);
	}
324233
private static Optional<Token<?>> getTokenFromSeqFile(String authPath, String proxyUserName) throws IOException {
    try (Closer closer = Closer.create()) {
      FileSystem localFs = FileSystem.getLocal(new Configuration());
      SequenceFile.Reader tokenReader =
          closer.register(new SequenceFile.Reader(localFs, new Path(authPath), localFs.getConf()));
      Text key = new Text();
      Token<?> value = new Token<>();
      while (tokenReader.next(key, value)) {
        LOG.info("Found token for " + key);
        if (key.toString().equals(proxyUserName)) {
          return Optional.<Token<?>> of(value);
        }
      }
    }
    return Optional.absent();
  }
765943
@Override
    public Path getFileName() {
        // Root and empty String has no file name
        if (path.length() == 0 || path.equals(ArchivePaths.root().get())) {
            return null;
        } else {
            final List<String> tokens = tokenize(this);
            // Furthest out
            final Path fileName = new ShrinkWrapPath(tokens.get(tokens.size() - 1), this.fileSystem);
            return fileName;
        }
    }
263476
@VisibleForTesting
  Collection<Token<? extends TokenIdentifier>> readDelegationTokens(Path tokenFilePath) throws IOException {
    LOGGER.info("Reading updated token from token file: " + tokenFilePath);
    return YarnHelixUtils.readTokensFromFile(tokenFilePath, this.fs.getConf());
  }
1281067
private int getFileType(String typeInfo) {
        switch (typeInfo) {
            case "ASCII":
                return FTP.ASCII_FILE_TYPE;
            case "BINARY":
                return FTP.BINARY_FILE_TYPE;
            case "EBCDIC":
                return FTP.EBCDIC_FILE_TYPE;
            case "LOCAL":
                return FTP.LOCAL_FILE_TYPE;
            default:
                return FTP.BINARY_FILE_TYPE;
        }
    }
676821
protected String processFileName(String name) {

        int pos = name.lastIndexOf("/");
        if (pos >= 0) {
            name = name.substring(pos + 1);
        }
        pos = name.lastIndexOf("\\");
        if (pos >= 0) {
            name = name.substring(pos + 1);
        }
        return name;
    }
1316681
private static Token createToken(char symbol, StringBuilder nameBuf, StringBuilder valueBuf) {
        String value = null;
        if (valueBuf.length() > 0) {
            value = valueBuf.toString();
            valueBuf.setLength(0); // empty the value buffer
        }

        if (nameBuf.length() > 0) {
            TokenType type = Token.resolveTypeAsSymbol(symbol);
            String name = nameBuf.toString();
            nameBuf.setLength(0); // empty the name buffer

            int offset = name.indexOf(Token.GETTER_SEPARATOR);
            if (offset > -1) {
                String name2 = name.substring(0, offset);
                String getter = name.substring(offset + 1);
                Token token = new Token(type, name2);
                if (!getter.isEmpty()) {
                    token.setGetterName(getter);
                }
                token.setDefaultValue(value);
                return token;
            } else if (value != null) {
                TokenDirectiveType directiveType = TokenDirectiveType.resolve(name);
                if (directiveType != null) {
                    String getter = null;
                    String defaultValue = null;
                    offset = value.indexOf(Token.GETTER_SEPARATOR);
                    if (offset > -1) {
                        String value2 = value.substring(0, offset);
                        String getter2 = value.substring(offset + 1);
                        value = value2;
                        offset = getter2.indexOf(Token.VALUE_SEPARATOR);
                        if (offset > -1) {
                            String getter3 = getter2.substring(0, offset);
                            String value3 = getter2.substring(offset + 1);
                            if (!getter3.isEmpty()) {
                                getter = getter3;
                            }
                            if (!value3.isEmpty()) {
                                defaultValue = value3;
                            }
                        } else {
                            if (!getter2.isEmpty()) {
                                getter = getter2;
                            }
                        }
                    }
                    Token token = new Token(type, directiveType, value);
                    token.setGetterName(getter);
                    token.setDefaultValue(defaultValue);
                    return token;
                } else {
                    Token token = new Token(type, name);
                    token.setDefaultValue(value);
                    return token;
                }
            } else {
                return new Token(type, name);
            }
        } else {
            // when not exists tokenName then tokenType must be TEXT type
            return new Token(value);
        }
    }
1321662
public static File  withDefaultType( File file, Type defaultType)
    {
    return
      file != null && FilenameUtils.getExtension( file.getName()).isEmpty()
      ? new File( String.format( "%s.%s", file.getPath(), String.valueOf( defaultType).toLowerCase()))
      : file;
    }
650472
protected static boolean isValidFilename(String filename) {
		if (filename == null || filename.length() == 0) {
			throw new NullPointerException("文件名不能为空.");
		}
		if (filename.indexOf("..") != -1) {
			throw new IllegalArgumentException("文件名称不能包含'..'");
		}
		Matcher m = FILENAME_PATTERN.matcher(filename);
		return m.matches();
	}
824046
public static String getByFilename(String fileName, String defaultType) {
        String extn = getExtension(fileName);
        if (extn != null) {
            return get(extn, defaultType);
        } else {
            // no extension, no content type
            return null;
        }
    }
1295113
def _tokenize(self, source, name, filename=None, state=None):
        
        source = self.preprocess(source, name, filename)
        stream = self.lexer.tokenize(source, name, filename, state)
        for ext in self.iter_extensions():
            stream = ext.filter_stream(stream)
            if not isinstance(stream, TokenStream):
                stream = TokenStream(stream, name, filename)
        return stream
645630
public static String getUserNameFromToken(String authToken) {
        if (null == authToken) {
            return null;
        }

        return authToken.split(TOKEN_SEPARATOR)[0];
    }
283069
public static String createUniqueFileName(String fileName) {

        int    index  = fileName.lastIndexOf(".");
        String suffix = fileName.substring(index);
        String uqName = UUIDUtils.getUUID16() + suffix;
        return uqName;
    }
1159171
public Token getMatchedToken(final int tokenType) throws RecognitionException {
        Token result = parser.getCurrentToken();
        boolean isIdentifierCompatible = false;
        if (identifierTokenIndex == tokenType && identifierTokenIndex > result.getType()) {
            isIdentifierCompatible = true;
        }
        if (result.getType() == tokenType || isIdentifierCompatible) {
            if (Token.EOF != tokenType && isIdentifierCompatible && result instanceof CommonToken) {
                ((CommonToken) result).setType(identifierTokenIndex);
            }
            parser.getErrorHandler().reportMatch(parser);
            parser.consume();
        } else {
            result = parser.getErrorHandler().recoverInline(parser);
            if (parser.getBuildParseTree() && -1 == result.getTokenIndex()) {
                parser.getContext().addErrorNode(parser.createErrorNode(parser.getContext(), result));
            }
        }
        return result;
    }