Android File Name Create makeFileName(String prefix, String filename)

Here you can find the source of makeFileName(String prefix, String filename)

Description

Makes a 'standard' helper file name.

License

Apache License

Parameter

Parameter Description
prefix a parameter
filename a parameter

Return

non-null string.

Declaration

public static String makeFileName(String prefix, String filename) 

Method Source Code

/*/*  w  w w.ja v a2  s . c o  m*/
    Copyright 1996-2008 Ariba, Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    $Id: //ariba/platform/util/core/ariba/util/core/FileUtil.java#24 $
 */

import ariba.util.log.Log;
import java.io.File;
import java.io.IOException;
import java.io.FileFilter;
import java.io.FilenameFilter;
import java.util.Random;
import java.util.List;

public class Main{
    /**
     * Makes a 'standard' helper file name.  by prepending the prefix, and then stripping off the
     * directory name of the filename (if any).
     *
     * @param prefix
     * @param filename
     * @return non-null string.
     */
    public static String makeFileName(String prefix, String filename) {
        FastStringBuffer sb = null;

        if (filename != null) {
            String[] parts = filename.split("[/|\\\\]");
            sb = new FastStringBuffer(prefix);
            for (int i = 0; i < parts.length; i++) {
                // skip over the first part of the path if there is more than 1 part
                if ((i == 0 && parts.length == 1) || i > 0) {
                    sb.append(parts[i]);
                }
            }
        }
        return sb == null ? null : sb.toString();
    }
}

Related

  1. createImageName()
  2. getLocalDateTimeForFileName(Date date)
  3. getJpegFileName(long fileNumber)
  4. getMetadataFileName(long fileNumber)