Use to_s
to get the content of this asset.
app :: TextAsset :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
app :: Asset :: defaultinit
core :: Object :: defaultinit
app :: TextAsset :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# Text file from the assets folder
#
# Use `to_s` to get the content of this asset.
class TextAsset
super Asset
# Text content of this asset
redef var to_s = load is lazy
# Load this asset
fun load: String do return ""
# Error on the last call to `load`, if any
var error: nullable Error = null
end
lib/app/assets.nit:30,1--44,3
redef class TextAsset
redef fun load
do
# Find file
var ns_path = ("assets"/path).to_nsstring
var path_in_bundle = asset_path(ns_path)
if path_in_bundle.address_is_null then
self.error = new Error("TextAsset at '{path}' not found")
self.to_s = ""
return ""
end
# Load content
var text = asset_content(path_in_bundle)
if text.address_is_null then
self.error = new Error("Failed to read content of TextAsset at '{path}'")
self.to_s = ""
return ""
end
return text.to_s
end
end
lib/ios/assets.nit:21,1--43,3
redef class TextAsset
redef fun load
do
jni_env.push_local_frame 8
var manager = app.asset_manager
var stream = manager.open(path)
if stream.is_java_null then
self.error = new Error("Failed to open asset at '{path}'")
jni_env.pop_local_frame
self.to_s = ""
return ""
end
var text = stream.read_all
stream.close
if text.is_java_null then
self.error = new Error("Failed to read content of asset file at '{path}'")
jni_env.pop_local_frame
self.to_s = ""
return ""
end
var content = text.to_s
jni_env.pop_local_frame
self.to_s = content
return content
end
end
lib/android/assets.nit:23,1--51,3