22
22
23
23
package xyz.quaver.io
24
24
25
+ import android.annotation.SuppressLint
25
26
import androidx.annotation.RequiresApi
26
27
import xyz.quaver.io.util.*
28
+ import java.io.File
29
+ import java.net.URI
30
+ import java.nio.file.Path
27
31
28
32
@RequiresApi(19 )
29
33
abstract class SAFileX : FileX {
34
+ @SuppressWarnings(" unused" )
30
35
private constructor () : super (" " ) {
31
36
throw UnsupportedOperationException (" STOP! You violated the law." )
32
37
}
@@ -35,12 +40,12 @@ abstract class SAFileX : FileX {
35
40
36
41
override fun canExecute () = false
37
42
38
- override fun canRead () = when {
43
+ override fun canRead (): Boolean = when {
39
44
cached -> cache.canRead
40
45
else -> uri.canRead(context)
41
46
}
42
47
43
- override fun canWrite () = when {
48
+ override fun canWrite (): Boolean = when {
44
49
cached -> cache.canWrite
45
50
else -> uri.canWrite(context)
46
51
}
@@ -57,40 +62,40 @@ abstract class SAFileX : FileX {
57
62
return true
58
63
}
59
64
60
- override fun deleteOnExit () {
65
+ override fun deleteOnExit (): Unit =
61
66
DeleteOnExitHook .add(uri)
62
- }
63
67
64
- override fun exists () = when {
68
+ override fun exists (): Boolean = when {
65
69
cached -> cache.exists
66
70
else -> uri.exists(context)
67
71
}
68
72
69
73
override fun getAbsoluteFile () = canonicalFile
70
74
override fun getAbsolutePath () = canonicalPath
71
75
72
- override fun getCanonicalFile () = uri.toFile(context)
73
- override fun getCanonicalPath () = canonicalFile?.canonicalPath
76
+ override fun getCanonicalFile (): File ? = uri.toFile(context)
77
+ override fun getCanonicalPath (): String? = canonicalFile?.canonicalPath
74
78
75
- override fun getName () = uri.name
76
- override fun getPath () = uri.path
79
+ override fun getName (): String? = uri.name
80
+ override fun getPath (): String? = uri.path
77
81
78
- override fun getFreeSpace () = kotlin.runCatching {
82
+ override fun getFreeSpace (): Long = kotlin.runCatching {
79
83
canonicalFile?.freeSpace
80
84
}.getOrNull() ? : throw UnsupportedOperationException ()
81
85
82
- override fun getTotalSpace () = kotlin.runCatching {
86
+ override fun getTotalSpace (): Long = kotlin.runCatching {
83
87
canonicalFile?.totalSpace
84
88
}.getOrNull() ? : throw UnsupportedOperationException ()
85
89
86
- override fun getUsableSpace () = kotlin.runCatching {
90
+ @SuppressLint(" UsableSpace" )
91
+ override fun getUsableSpace (): Long = kotlin.runCatching {
87
92
canonicalFile?.usableSpace
88
93
}.getOrNull() ? : throw UnsupportedOperationException ()
89
94
90
- override fun hashCode () =
95
+ override fun hashCode (): Int =
91
96
uri.hashCode()
92
97
93
- override fun equals (other : Any? ) =
98
+ override fun equals (other : Any? ): Boolean =
94
99
this .hashCode() == other.hashCode()
95
100
96
101
override fun isAbsolute () = true
@@ -100,18 +105,36 @@ abstract class SAFileX : FileX {
100
105
else -> uri.isDirectory(context)
101
106
}
102
107
103
- override fun isFile () = ! isDirectory
108
+ override fun isFile (): Boolean = ! isDirectory
104
109
105
- override fun isHidden () = name?.startsWith(' .' ) ? : false
110
+ override fun isHidden (): Boolean = name?.startsWith(' .' ) ? : false
106
111
107
- override fun lastModified () = when {
112
+ override fun lastModified (): Long = when {
108
113
cached -> cache.lastModified
109
114
else -> uri.lastModified(context)
110
115
} ? : 0L
111
116
112
- override fun length () = when {
117
+ override fun length (): Long = when {
113
118
cached -> cache.length
114
119
else -> uri.length(context)
115
120
} ? : 0L
116
121
122
+ override fun setExecutable (executable : Boolean ) = throw UnsupportedOperationException ()
123
+ override fun setExecutable (executable : Boolean , ownerOnly : Boolean ) = throw UnsupportedOperationException ()
124
+ override fun setLastModified (time : Long ) = throw UnsupportedOperationException ()
125
+ override fun setReadOnly () = throw UnsupportedOperationException ()
126
+ override fun setReadable (readable : Boolean ) = throw UnsupportedOperationException ()
127
+ override fun setReadable (readable : Boolean , ownerOnly : Boolean ) = throw UnsupportedOperationException ()
128
+ override fun setWritable (writable : Boolean ) = throw UnsupportedOperationException ()
129
+ override fun setWritable (writable : Boolean , ownerOnly : Boolean ) = throw UnsupportedOperationException ()
130
+
131
+ @RequiresApi(26 )
132
+ override fun toPath (): Path ? =
133
+ canonicalFile?.toPath()
134
+
135
+ override fun toString (): String =
136
+ uri.toString()
137
+
138
+ override fun toURI (): URI = URI (uri.toString())
139
+
117
140
}
0 commit comments