Subversion Repositories AndroidProjects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1671 chris 1
package com.gebauz.bauzoid.file;
2
 
3
/** File utilities and convenience functions. */
4
public class FileUtil
5
{
6
        private FileUtil() {}
7
 
8
        /** Extract the filename's path. */
9
        public static String extractPath(String filename)
10
        {
11
                for (int n = filename.length()-1; n >= 0; n--)
12
                {
13
                        if ((filename.charAt(n) == '\\') ||
14
                                (filename.charAt(n) == '/'))
15
                        {
16
                                return filename.substring(0, n);
17
                        }
18
                }
19
 
20
                return filename;
21
        }
22
 
23
        /** Extract the path's filename including its extension. */
24
        public static String extractFilename(String filePath)
25
        {
26
                for (int n = filePath.length()-1; n >= 0; n--)
27
                {
28
                        if ((filePath.charAt(n) == '\\') ||
29
                                (filePath.charAt(n) == '/'))
30
                        {
31
                                return filePath.substring(n+1, filePath.length());
32
                        }
33
                }
34
                return filePath;
35
        }
36
 
37
        /** Extract the path's filename without its extension. */
38
        public static String extractFilenameNoExt(String filePath)
39
        {
40
                for (int n = filePath.length()-1; n >= 0; n--)
41
                {
42
                        if (filePath.charAt(n) == '.')
43
                        {
44
                                return extractFilename(filePath.substring(0, n));
45
                        }
46
                }
47
                return filePath;
48
        }
49
 
50
        public static String replaceExt(String filePath, String newExt)
51
        {
52
                int i = filePath.lastIndexOf('.');
53
 
54
                if (i == -1)
55
                        return filePath;
56
 
57
                return filePath.substring(0, i) + "." + newExt;
58
        }
59
 
60
/*      public static String loadString(FileHandle handle)
61
        {
62
                return handle.readString();
63
        }*/
64
 
65
        /** Load a file into a string from assets. */
66
/*      public static String loadStringFromAsset(Resources resources, String asset) throws IOException
67
        {
68
                InputStream is = resources.getAssets().open(asset);
69
 
70
                return loadString(is);
71
        }*/
72
 
73
        /** Load a file into a string from resources. */
74
/*      public static String loadStringFromResource(Resources resources, int id) throws IOException
75
        {
76
                InputStream is = resources.openRawResource(id);
77
 
78
                return loadString(is);
79
        }*/
80
 
81
/*      public static String loadString(InputStream is) throws IOException
82
        {
83
                byte[] buffer = new byte[is.available()];
84
                is.read(buffer);
85
 
86
                ByteArrayOutputStream os = new ByteArrayOutputStream();
87
                os.write(buffer);
88
                os.close();
89
 
90
                is.close();
91
 
92
                return os.toString();
93
        }*/
94
 
95
        /** Load a file from assets. */
96
/*      public static File loadFileFromAsset(Resources resources, String asset) throws IOException
97
        {
98
                InputStream is = resources.getAssets().open(asset);
99
                return new File(is);
100
        }*/
101
 
102
        /** Load a file from resources. */
103
/*      public static File loadFileFromResource(Resources resources, int id) throws IOException
104
        {
105
                InputStream is = resources.openRawResource(id);
106
                return new File(is);
107
        }*/
108
}
109